{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n\n# Tree-LSTM in DGL\n\n**Author**: Zihao Ye, Qipeng Guo, [Minjie Wang](https://jermainewang.github.io/), [Jake Zhao](https://cs.nyu.edu/~jakezhao/), Zheng Zhang\n\n
The tutorial aims at gaining insights into the paper, with code as a mean\n of explanation. The implementation thus is NOT optimized for running\n efficiency. For recommended implementation, please refer to the [official\n examples](https://github.com/dmlc/dgl/tree/master/examples).
**Definition**: :func:`~dgl.batch` unions a list of $B$\n :class:`~dgl.DGLGraph`\\ s and returns a :class:`~dgl.DGLGraph` of batch\n size $B$.\n\n - The union includes all the nodes,\n edges, and their features. The order of nodes, edges, and features are\n preserved.\n\n - Given that you have $V_i$ nodes for graph\n $\\mathcal{G}_i$, the node ID $j$ in graph\n $\\mathcal{G}_i$ correspond to node ID\n $j + \\sum_{k=1}^{i-1} V_k$ in the batched graph.\n\n - Therefore, performing feature transformation and message passing on\n the batched graph is equivalent to doing those\n on all ``DGLGraph`` constituents in parallel.\n\n - Duplicate references to the same graph are\n treated as deep copies; the nodes, edges, and features are duplicated,\n and mutation on one reference does not affect the other.\n - The batched graph keeps track of the meta\n information of the constituents so it can be\n :func:`~dgl.batched_graph.unbatch`\\ ed to list of ``DGLGraph``\\ s.
``apply_node_func`` is a new node UDF that has not been introduced before. In\n ``apply_node_func``, a user specifies what to do with node features,\n without considering edge features and messages. In a Tree-LSTM case,\n ``apply_node_func`` is a must, since there exists (leaf) nodes with\n $0$ incoming edges, which would not be updated with\n ``reduce_func``.
Before you call :meth:`~dgl.DGLGraph.prop_nodes`, specify a\n `message_func` and `reduce_func` in advance. In the example, you can see built-in\n copy-from-source and sum functions as message functions, and a reduce\n function for demonstration.