tdm_child

paddle.fluid.contrib.layers.nn. tdm_child ( x, node_nums, child_nums, param_attr=None, dtype='int32' ) [source]
Tdm Child
According to the input node_id on the given tree, return the corresponding child node_id and

whether child is a leaf node by leaf_mask value.

System Message: WARNING/2 (/usr/local/lib/python3.8/site-packages/paddle/fluid/contrib/layers/nn.py:docstring of paddle.fluid.contrib.layers.nn.tdm_child, line 4)

Definition list ends without a blank line; unexpected unindent.

Given:
    tree[[0], [1, 2], [3, 4], [5, 6]] # A binary tree with seven nodes
    x = [[2], [3]]
    node_nums = 7
    child_nums = 2

  we get:
    child = [[5, 6],
             [0, 0]]
    leaf_mask = [[1, 1],
                 [0, 0]]

System Message: WARNING/2 (/usr/local/lib/python3.8/site-packages/paddle/fluid/contrib/layers/nn.py:docstring of paddle.fluid.contrib.layers.nn.tdm_child, line 17)

Explicit markup ends without a blank line; unexpected unindent.

Parameters
  • x (Variable) – Variable contained the node_id information, dtype support int32/int64.

  • node_nums (int) – Number of total nodes.

  • child_nums (int) – Maximum number of child nodes per node.

  • param_attr (ParamAttr) – To specify the tdm-tree-info parameter property. Default: None, which means the default weight parameter property is used. See usage for details in: ref: api_fluid_ParamAttr, should has shape(node_nums, 3 + child_nums), dtype support int32/int64. The dimension[1] of tdm-tree-info contains the following: 1. Item_id(int, shape(1)), if node is a leaf node, give its item_id corresponding to node_id, else give 0. 2. Layer_id(int, shape(1)), indicates which layer the node is on. 3. Parent_id(int, shape(1)), node’s parent node. 4. Child_id(int, shape(child_nums)), all child node’s node_id of this node should be given. If the number of child nodes is insufficient, padding 0 until child nums equal to child_nums

  • dtype (str) – The data type of output child and leaf_mask, support int32/int64.

Returns

A tuple including input node’s child(Variable) and leaf_mask(Variable).

If child is a leaf node, leaf_mask equal ot 1, otherwise equal to 0.

Return type

tuple

Examples


System Message: WARNING/2 (/usr/local/lib/python3.8/site-packages/paddle/fluid/contrib/layers/nn.py:docstring of paddle.fluid.contrib.layers.nn.tdm_child, line 45)

Explicit markup ends without a blank line; unexpected unindent.

import paddle.fluid as fluid import numpy as np x = fluid.data(name=”x”, shape=[None, 1], dtype=”int32”, lod_level=1) tree_info = [[0,0,0,1,2],

System Message: ERROR/3 (/usr/local/lib/python3.8/site-packages/paddle/fluid/contrib/layers/nn.py:docstring of paddle.fluid.contrib.layers.nn.tdm_child, line 49)

Unexpected indentation.

[0,1,0,3,4],[0,1,0,5,6], [0,2,1,0,0],[1,2,1,0,0],[2,2,2,0,0],[3,2,2,0,0]]

System Message: WARNING/2 (/usr/local/lib/python3.8/site-packages/paddle/fluid/contrib/layers/nn.py:docstring of paddle.fluid.contrib.layers.nn.tdm_child, line 51)

Block quote ends without a blank line; unexpected unindent.

tree_info_np = np.array(tree_info) tree_info_np = np.reshape(tree_info_np, (7,5)) node_nums = 7 child_nums = 2 child, leaf_mask = fluid.contrib.layers.tdm_child(x, node_nums, child_nums,

System Message: ERROR/3 (/usr/local/lib/python3.8/site-packages/paddle/fluid/contrib/layers/nn.py:docstring of paddle.fluid.contrib.layers.nn.tdm_child, line 56)

Unexpected indentation.

param_attr=fluid.ParamAttr(
initializer=fluid.initializer.NumpyArrayInitializer(

tree_info_np)))

System Message: WARNING/2 (/usr/local/lib/python3.8/site-packages/paddle/fluid/contrib/layers/nn.py:docstring of paddle.fluid.contrib.layers.nn.tdm_child, line 59)

Block quote ends without a blank line; unexpected unindent.

place = fluid.CPUPlace() exe = fluid.Executor(place) exe.run(fluid.default_startup_program()) xx = np.array([[2],[3]]).reshape((2,1)).astype(“int32”) child_res, leaf_mask_res = exe.run(feed={“x”:xx}, fetch_list=[child, leaf_mask])