未验证 提交 ae185c9a 编写于 作者: Z zhongpu 提交者: GitHub

update NCE_cn.rst, PRelu_cn.rst, to_variable_cn.rst, test=develop (#1318)

* update NCE_cn.rst, PRelu_cn.rst, to_variable_cn.rst, test=develop

* fix NCE, PRelu, to_variable, test=develop

* add comment for class Layer, test=develop

* add comment for dygraph layer, test=develop

* add comment for dygraph layer, test=develop

* add comment for name, test=develop

* update to_variable_cn.rst, test=develop
上级 2d5c194e
......@@ -5,29 +5,21 @@ NCE
.. py:class:: paddle.fluid.dygraph.NCE(name_scope, num_total_classes, param_attr=None, bias_attr=None, num_neg_samples=None, sampler='uniform', custom_dist=None, seed=0, is_sparse=False)
计算并返回噪音对比估计( noise-contrastive estimation training loss)。
`请参考Noise-contrastive estimation: A new estimation principle for unnormalized statistical models
<http://www.jmlr.org/proceedings/papers/v9/gutmann10a/gutmann10a.pdf>`_
该接口用于构建 ``NCE`` 类的一个可调用对象,具体用法参照 ``代码示例`` 。其中实现了 ``NCE`` 损失函数的功能,其默认使用均匀分布进行抽样,计算并返回噪音对比估计( noise-contrastive estimation training loss)。更多详情请参考:`Noise-contrastive estimation: A new estimation principle for unnormalized statistical models <http://www.jmlr.org/proceedings/papers/v9/gutmann10a/gutmann10a.pdf>`_
该operator默认使用均匀分布进行抽样。
参数:
参数:
- **name_scope** (str) – 该类的名称。
- **num_total_classes** (int) - 所有样本中的类别的总数。
- **sample_weight** (Variable|None) - 存储每个样本权重,shape为[batch_size, 1]存储每个样本的权重。每个样本的默认权重为1.0。
- **param_attr** (ParamAttr|None) - :math:`可学习参数/nce权重` 的参数属性。如果它没有被设置为ParamAttr的一个属性,nce将创建ParamAttr为param_attr。如没有设置param_attr的初始化器,那么参数将用Xavier初始化。默认值:None。
- **bias_attr** (ParamAttr|bool|None) - nce偏置的参数属性。如果设置为False,则不会向输出添加偏置(bias)。如果值为None或ParamAttr的一个属性,则bias_attr=ParamAtt。如果没有设置bias_attr的初始化器,偏置将被初始化为零。默认值:None。
- **num_neg_samples** (int) - 负样例的数量。默认值是10。
- **name** (str|None) - 该layer的名称(可选)。如果设置为None,该层将被自动命名。
- **sampler** (str) – 取样器,用于从负类别中进行取样。可以是 ‘uniform’, ‘log_uniform’ 或 ‘custom_dist’。 默认 ‘uniform’。
- **custom_dist** (float[]) – 一个 float[] 并且它的长度为 ``num_total_classes`` 。 如果取样器类别为‘custom_dist’,则使用此参数。 custom_dist[i] 是第i个类别被取样的概率。默认为 None
- **seed** (int) – 取样器使用的seed。默认为0。
- **is_sparse** (bool) – 标志位,指明是否使用稀疏更新, :math:`weight@GRAD` 和 :math:`bias@GRAD` 会变为 SelectedRows。默认为False。
返回: nce loss
返回类型: 变量(Variable)
- **sample_weight** (Variable, 可选) - 维度为\[batch_size, 1\],存储每个样本的权重。每个样本的默认权重为1.0。默认值:None。
- **param_attr** (ParamAttr, 可选) - 指定权重参数属性的对象。默认值为None,表示使用默认的权重参数属性。具体用法请参见 :ref:`cn_api_fluid_ParamAttr` 。
- **bias_attr** (ParamAttr, 可选) - 指定偏置参数属性的对象。默认值为None,表示使用默认的偏置参数属性。具体用法请参见 :ref:`cn_api_fluid_ParamAttr` 。
- **num_neg_samples** (int, 可选) - 负样本的数量。默认值:10。
- **sampler** (str, 可选) – 指明采样器的类型,用于从负类别中进行采样。可以是 ``uniform`` 、 ``log_uniform`` 或 ``custom_dist`` 。 默认值: ``uniform`` 。
- **custom_dist** (float[], 可选) – float[] 类型的数据,并且它的长度为 ``num_total_classes`` 。如果采样器类别为 ``custom_dist`` ,则使用此参数。custom_dist\[i\]是第i个类别被取样的概率。默认值:None
- **seed** (int, 可选) – 采样器使用的随机种子。默认值:0。
- **is_sparse** (bool, 可选) – 指明是否使用稀疏更新,如果为True, :math:`weight@GRAD` 和 :math:`bias@GRAD` 会变为 SelectedRows。默认值:False。
返回:无
**代码示例**
......@@ -74,6 +66,12 @@ NCE
nce_loss3 = nce(embs3, words[label_word])
属性
::::::::::::
.. py:attribute:: weight
本层的可学习参数,类型为 ``Parameter``
.. py:attribute:: bias
本层的可学习偏置,类型为 ``Parameter``
......@@ -5,46 +5,46 @@ PRelu
.. py:class:: paddle.fluid.dygraph.PRelu(name_scope, mode, param_attr=None)
等式:
该接口用于构建 ``PRelu`` 类的一个可调用对象,具体用法参照 ``代码示例`` 。其中实现了 ``PRelu`` 激活函数的三种激活方式。
计算公式如下:
.. math::
y = max(0, x) + \alpha min(0, x)
参数:
- **name_scope** (str)- 该类的名称。
- **mode** (str) - 权重共享模式。共提供三种激活方式:
.. code-block:: text
all: 所有元素使用同一个权值
channel: 在同一个通道中的元素使用同一个权值
element: 每一个元素有一个独立的权值
- **param_attr** (ParamAttr|None) - 可学习权重 :math:`[\alpha]` 的参数属性。
- **name_scope** (str) - 该类的名称。
- **mode** (str) - 权重共享模式。共提供三种激活方式:
.. code-block:: text
all:所有元素使用同一个 :math:`[\alpha]` 值
channel:在同一个通道中的元素使用同一个 :math:`[\alpha]` 值
element:每一个元素有一个独立的 :math:`[\alpha]` 值
返回: 输出Tensor与输入tensor的shape相同
- **param_attr** (ParamAttr, 可选) - 指定权重参数属性的对象。默认值为None,表示使用默认的权重参数属性。具体用法请参见 :ref:`cn_api_fluid_ParamAttr`
返回类型: 变量(Variable)
返回:无
**代码示例:**
.. code-block:: python
import paddle.fluid as fluid
import numpy as np
inp_np = np.ones([5, 200, 100, 100]).astype('float32')
with fluid.dygraph.guard():
mode = 'channel'
prelu = fluid.PRelu(
'prelu',
mode=mode,
param_attr=fluid.ParamAttr(initializer=fluid.initializer.Constant(1.0)))
dy_rlt = prelu(fluid.dygraph.base.to_variable(inp_np))
import paddle.fluid as fluid
from paddle.fluid.dygraph.base import to_variable
import numpy as np
inp_np = np.ones([5, 200, 100, 100]).astype('float32')
with fluid.dygraph.guard():
inp_np = to_variable(inp_np)
mode = 'channel'
prelu = fluid.PRelu('prelu', mode=mode, param_attr=fluid.ParamAttr(initializer=fluid.initializer.Constant(1.0)))
dy_rlt = prelu(inp_np)
属性
::::::::::::
.. py:attribute:: weight
本层的可学习参数,类型为 ``Parameter``
......@@ -5,15 +5,15 @@ to_variable
.. py:function:: paddle.fluid.dygraph_to_variable(value, block=None, name=None)
该函数会从ndarray创建一个variable
该函数实现从numpy\.ndarray对象或者Variable对象创建一个 ``Variable`` 类型的对象
参数:
- **value** (ndarray) – 需要转换的numpy值
- **block** (fluid.Block) – variable所在的block,默认为None
- **name** (str) – variable的名称,默认为None
- **value** (ndarray) – 需要转换的numpy\.ndarray对象,维度可以为多维,数据类型为numpy\.{float16, float32, float64, int16, int32, int64, uint8, uint16}中的一种。
- **block** (fluid.Block, 可选) – Variable所在的Block,默认值为None。
- **name** (str, 可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。
返回: 从指定numpy创建的variable
返回:从指定numpy\.ndarray对象创建的 ``Tensor`` ,数据类型和 ``value`` 一致,返回值维度和 ``value`` 一致
返回类型:Variable
......@@ -28,8 +28,3 @@ to_variable
x = np.ones([2, 2], np.float32)
y = fluid.dygraph.to_variable(x)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册