未验证 提交 164b47af 编写于 作者: T Tao Luo 提交者: GitHub

remove tree_conv, match_matrix, var_conv2d to contrib (#1229)

上级 c1362a6c
......@@ -158,7 +158,6 @@ fluid.layers
layers_cn/lstm_cn.rst
layers_cn/lstm_unit_cn.rst
layers_cn/margin_rank_loss_cn.rst
layers_cn/match_matrix_tensor_cn.rst
layers_cn/matmul_cn.rst
layers_cn/maxout_cn.rst
layers_cn/mean_cn.rst
......@@ -286,7 +285,6 @@ fluid.layers
layers_cn/thresholded_relu_cn.rst
layers_cn/topk_cn.rst
layers_cn/transpose_cn.rst
layers_cn/tree_conv_cn.rst
layers_cn/unfold_cn.rst
layers_cn/Uniform_cn.rst
layers_cn/uniform_random_cn.rst
......@@ -295,7 +293,6 @@ fluid.layers
layers_cn/unique_with_counts_cn.rst
layers_cn/unsqueeze_cn.rst
layers_cn/unstack_cn.rst
layers_cn/var_conv_2d_cn.rst
layers_cn/warpctc_cn.rst
layers_cn/where_cn.rst
layers_cn/While_cn.rst
......
.. _cn_api_fluid_layers_match_matrix_tensor:
match_matrix_tensor
-------------------------------
.. py:function:: paddle.fluid.layers.match_matrix_tensor(x, y, channel_num, act=None, param_attr=None, dtype='float32', name=None)
计算两个长度可变词序列的语义匹配矩阵,给一个长度为n的问题A,和一个长度为m的标题B,输入形状为[n, h]和[m, h],h为hidden_size。如果channel_num设置为3,将会生成一个形为[h, 3, h]的参数可学习的矩阵W。接着语义匹配矩阵将会通过A * W * B.T = [n, h]*[h, 3, h]*[h, m] = [n, 3, m]来计算A和B。可学习参数矩阵W在这个过程中相当于一个全链接层。如果提供了激活函数,相关激活函数将会被用到输出中。x和y应当为LodTensor并且仅支持一个level LoD。
给一个1-level LoDTensor x:
x.lod = [[2, 3, ]]
x.data = [[0.3, 0.1], [0.2, 0.3], [0.5, 0.6], [0.7, 0.1], [0.3, 0.4]]
x.dims = [5, 2]
y是一个Tensor:
y.lod = [[3, 1, ]]
y.data = [[0.1, 0.2], [0.3, 0.7], [0.9, 0.2], [0.4, 0.1]]
y.dims = [4, 2]
channel_num设为2,我们就可以得到一个 1-level LoDTensor:
out.lod = [[12, 6]] # where 12 = channel_num * x.lod[0][0] * y.lod[0][0]
out.dims = [18, 1] # where 18 = 12 + 6
参数:
- **x** (Variable) - 1-level的输入LoDTensor。
- **y** (Variable) - 1-level的输入LoDTensor。
- **channel_num** (int) - 可学习参数W的通道数。
- **act** (str,默认为None) - 激活函数。
- **param_attr** (ParamAttr|ParamAttr的列表,默认为None) - 此层可学习参数的属性。
- **dtype** ('float32') - w数据的数据类型。
- **name** (str|None) - 层名,若为None,则自动设置。
返回:由此层指定LoD的输出
返回类型:变量(Variable)
**代码示例**:
.. code-block:: python
import numpy as np
from paddle.fluid import layers
x_lod_tensor = layers.data(name='x', shape=[10], lod_level=1)
y_lod_tensor = layers.data(name='y', shape=[10], lod_level=1)
out, out_tmp = layers.match_matrix_tensor(x=x_lod_tensor, y=y_lod_tensor, channel_num=3)
.. _cn_api_fluid_layers_tree_conv:
tree_conv
-------------------------------
.. py:function:: paddle.fluid.layers.tree_conv(nodes_vector, edge_set, output_size, num_filters=1, max_depth=2, act='tanh', param_attr=None, bias_attr=None, name=None)
基于树结构的卷积Tree-Based Convolution运算。
基于树的卷积是基于树的卷积神经网络(TBCNN,Tree-Based Convolution Neural Network)的一部分,它用于对树结构进行分类,例如抽象语法树。 Tree-Based Convolution提出了一种称为连续二叉树的数据结构,它将多路(multiway)树视为二叉树。 提出基于树的卷积论文: https://arxiv.org/abs/1409.5718v1
参数:
- **nodes_vector** (Variable) – (Tensor) 树上每个节点的特征向量(vector)。特征向量的形状必须为[max_tree_node_size,feature_size]
- **edge_set** (Variable) – (Tensor) 树的边。边必须带方向。边集的形状必须是[max_tree_node_size,2]
- **output_size** (int) – 输出特征宽度
- **num_filters** (int) – filter数量,默认值1
- **max_depth** (int) – filter的最大深度,默认值2
- **act** (str) – 激活函数,默认 tanh
- **param_attr** (ParamAttr) – filter的参数属性,默认None
- **bias_attr** (ParamAttr) – 此层bias的参数属性,默认None
- **name** (str) – 此层的名称(可选)。如果设置为None,则将自动命名层,默认为None
返回: (Tensor)子树的特征向量。输出张量的形状是[max_tree_node_size,output_size,num_filters]。输出张量可以是下一个树卷积层的新特征向量
返回类型:out(Variable)
**代码示例**:
.. code-block:: python
import paddle.fluid as fluid
# 10 代表数据集的最大节点大小max_node_size,5 代表向量宽度
nodes_vector = fluid.layers.data(name='vectors', shape=[10, 5], dtype='float32')
# 10 代表数据集的最大节点大小max_node_size, 2 代表每条边连接两个节点
# 边必须为有向边
edge_set = fluid.layers.data(name='edge_set', shape=[10, 2], dtype='float32')
# 输出的形状会是[None, 10, 6, 1],
# 10 代表数据集的最大节点大小max_node_size, 6 代表输出大小output size, 1 代表 1 个filter
out_vector = fluid.layers.tree_conv(nodes_vector, edge_set, 6, 1, 2)
# reshape之后, 输出张量output tensor为下一个树卷积的nodes_vector
out_vector = fluid.layers.reshape(out_vector, shape=[-1, 10, 6])
out_vector_2 = fluid.layers.tree_conv(out_vector, edge_set, 3, 4, 2)
# 输出tensor也可以用来池化(论文中称为global pooling)
pooled = fluid.layers.reduce_max(out_vector, dims=2) # 全局池化
.. _cn_api_fluid_layers_var_conv_2d:
var_conv_2d
-------------------------------
.. py:function:: paddle.fluid.layers.var_conv_2d(input, row, col, input_channel, output_channel, filter_size, stride=1, param_attr=None, act=None, dtype='float32', name=None)
var_conv_2d层依据给定的参数来计算输出, ``input`` 、 ``row`` 和 ``col`` 都是1-level的 ``LodTensor`` 卷积操作与普通的conv2d卷积层一样,值得注意的是,输入数据的第二个维度即input.dim[1]应该为1。
如果 ``input_channel`` 是2,并且给了如下的row lodTensor 和 col lodTensor:
.. code-block:: text
row.lod = [[5, 4]]
col.lod = [[6, 7]]
输入是一个lodTensor:
input.lod = [[60, 56]] # where 60 = input_channel * 5 * 6
input.dims = [116, 1] # where 116 = 60 + 56
如果设置 output_channel 为3, filter_size 为 [3, 3], stride 为 [1, 1]:
output.lod = [[90, 84]] # where 90 = output_channel * [(5-1)/stride + 1] * [(6-1)/stride + 1]
output.dims = [174, 1] # where 174 = 90 + 84
参数:
- **input** (Variable) – dims[1]等于1的1-level的LodTensor。
- **row** (Variable) – 1-level的LodTensor提供height。
- **col** (Variable) – 1-level的LodTensor提供width。
- **input_channel** (int) – 输入通道的数目。
- **output_channel** (int) – 输出通道的数目。
- **filter_size** (int|tuple|None) – 过滤器尺寸。 如果是元组,则应当为两个整型数字(filter_size_H, filter_size_W)。否则,过滤器会变为正方形。
- **stride** (int|tuple) – 步长。 如果是元组,则应当为两个整型数字(stride_H, stride_W)。否则,stride_H = stride_W = stride。默认: stride = 1.
- **param_attr** (ParamAttr|None) – 为var_conv2d可学习的权重分配参数属性如果设置为None,或者ParamAttr的一个属性, var_conv2d将会创建ParamAttr做为param_attr。如果param_attr的初始化没有设定,参数将会以 \(Normal(0.0, std)\),进行初始化,\(std\) 为 \((\frac{2.0 }{filter\_elem\_num})^{0.5}\). 默认: None。
- **act** (str) – 激活类型,如果设置为None,则不会激活。默认:None
- **dtype** ('float32') – 输出与参数的数据类型
- **name** (str|None) – 层名。如果没有设置,将会被自动命名。默认: None。
返回: 由该层指定LoD的输出变量
返回类型: 变量(Variable)
**代码示例**:
.. code-block:: python
import numpy as np
from paddle.fluid import layers
x_lod_tensor = layers.data(name='x', shape=[1], lod_level=1)
row_lod_tensor = layers.data(name='row', shape=[6], lod_level=1)
col_lod_tensor = layers.data(name='col', shape=[6], lod_level=1)
out = layers.var_conv_2d(input=x_lod_tensor,
row=row_lod_tensor,
col=col_lod_tensor,
input_channel=3,
output_channel=5,
filter_size=[3, 3],
stride=1)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册