From f5bc56c70819738b7044b67209c5ec95918df74a Mon Sep 17 00:00:00 2001 From: zhupengyang Date: Mon, 17 Aug 2020 15:21:26 +0800 Subject: [PATCH] hardshrink and Hardshrink doc (#2371) --- doc/fluid/api/nn.rst | 3 +- doc/fluid/api/nn/activation.rst | 8 ++++ doc/fluid/api/nn/activation/Hardshrink.rst | 13 ++++++ doc/fluid/api/nn/hard_shrink.rst | 7 --- doc/fluid/api/nn/hardshrink.rst | 11 +++++ doc/fluid/api_cn/nn_cn.rst | 2 +- doc/fluid/api_cn/nn_cn/activation_cn.rst | 1 + .../nn_cn/activation_cn/Hardshrink_cn.rst | 43 +++++++++++++++++++ doc/fluid/api_cn/nn_cn/hard_shrink_cn.rst | 7 --- doc/fluid/api_cn/nn_cn/hardshrink_cn.rst | 42 ++++++++++++++++++ doc/fluid/api_cn/nn_cn/softmax_cn.rst | 18 ++++---- 11 files changed, 130 insertions(+), 25 deletions(-) create mode 100644 doc/fluid/api/nn/activation.rst create mode 100644 doc/fluid/api/nn/activation/Hardshrink.rst delete mode 100644 doc/fluid/api/nn/hard_shrink.rst create mode 100644 doc/fluid/api/nn/hardshrink.rst create mode 100644 doc/fluid/api_cn/nn_cn/activation_cn/Hardshrink_cn.rst delete mode 100644 doc/fluid/api_cn/nn_cn/hard_shrink_cn.rst create mode 100644 doc/fluid/api_cn/nn_cn/hardshrink_cn.rst diff --git a/doc/fluid/api/nn.rst b/doc/fluid/api/nn.rst index 3d8ad814d..60a4913ab 100644 --- a/doc/fluid/api/nn.rst +++ b/doc/fluid/api/nn.rst @@ -5,6 +5,7 @@ paddle.nn .. toctree:: :maxdepth: 1 + nn/activation.rst nn/adaptive_pool2d.rst nn/adaptive_pool3d.rst nn/add_position_encoding.rst @@ -60,7 +61,7 @@ paddle.nn nn/GradientClipByValue.rst nn/grid_sampler.rst nn/GroupNorm.rst - nn/hard_shrink.rst + nn/hardshrink.rst nn/hard_sigmoid.rst nn/hard_swish.rst nn/hash.rst diff --git a/doc/fluid/api/nn/activation.rst b/doc/fluid/api/nn/activation.rst new file mode 100644 index 000000000..76dfe5956 --- /dev/null +++ b/doc/fluid/api/nn/activation.rst @@ -0,0 +1,8 @@ +========== +activation +========== + +.. toctree:: + :maxdepth: 1 + + activation/Hardshrink.rst diff --git a/doc/fluid/api/nn/activation/Hardshrink.rst b/doc/fluid/api/nn/activation/Hardshrink.rst new file mode 100644 index 000000000..552e6a2a9 --- /dev/null +++ b/doc/fluid/api/nn/activation/Hardshrink.rst @@ -0,0 +1,13 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_nn_activation_Hardshrink: + +Hardshrink +--------- + +.. autoclass:: paddle.nn.activation.Hardshrink + :members: + :inherited-members: + :noindex: + diff --git a/doc/fluid/api/nn/hard_shrink.rst b/doc/fluid/api/nn/hard_shrink.rst deleted file mode 100644 index a6e2cef0c..000000000 --- a/doc/fluid/api/nn/hard_shrink.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. _api_nn_hard_shrink: - -hard_shrink -------------------------------- -:doc_source: paddle.fluid.layers.hard_shrink - - diff --git a/doc/fluid/api/nn/hardshrink.rst b/doc/fluid/api/nn/hardshrink.rst new file mode 100644 index 000000000..48b98f2a5 --- /dev/null +++ b/doc/fluid/api/nn/hardshrink.rst @@ -0,0 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_nn_hardshrink: + +hardshrink +---------- + +.. autofunction:: paddle.nn.functional.hardshrink + :noindex: + diff --git a/doc/fluid/api_cn/nn_cn.rst b/doc/fluid/api_cn/nn_cn.rst index b42ec565b..f377c90c7 100644 --- a/doc/fluid/api_cn/nn_cn.rst +++ b/doc/fluid/api_cn/nn_cn.rst @@ -73,7 +73,7 @@ paddle.nn nn_cn/GradientClipByValue_cn.rst nn_cn/grid_sampler_cn.rst nn_cn/GroupNorm_cn.rst - nn_cn/hard_shrink_cn.rst + nn_cn/hardshrink_cn.rst nn_cn/hard_sigmoid_cn.rst nn_cn/hard_swish_cn.rst nn_cn/hash_cn.rst diff --git a/doc/fluid/api_cn/nn_cn/activation_cn.rst b/doc/fluid/api_cn/nn_cn/activation_cn.rst index 79d125894..337a4a8d9 100644 --- a/doc/fluid/api_cn/nn_cn/activation_cn.rst +++ b/doc/fluid/api_cn/nn_cn/activation_cn.rst @@ -8,5 +8,6 @@ activation .. toctree:: :maxdepth: 1 + activation_cn/Hardshrink_cn.rst activation_cn/LeakyReLU_cn.rst activation_cn/Sigmoid_cn.rst diff --git a/doc/fluid/api_cn/nn_cn/activation_cn/Hardshrink_cn.rst b/doc/fluid/api_cn/nn_cn/activation_cn/Hardshrink_cn.rst new file mode 100644 index 000000000..61ba40a8f --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/activation_cn/Hardshrink_cn.rst @@ -0,0 +1,43 @@ +.. _cn_api_nn_Hardshrink: + +Hardshrink +------------------------------- +.. py:class:: paddle.nn.Hardshrink(threshold=0.5, name=None) + +Hardshrink激活层 + +.. math:: + + Hardshrink(x)= + \left\{ + \begin{aligned} + &x, & & if \ x > threshold \\ + &x, & & if \ x < -threshold \\ + &0, & & if \ others + \end{aligned} + \right. + +其中,:math:`x` 为输入的 Tensor + +参数 +:::::::::: + - threshold (float, 可选) - Hardshrink激活计算公式中的threshold值。默认值为0.5。 + - name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +形状: + - input: 任意形状的Tensor。 + - output: 和input具有相同形状的Tensor。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + + x = paddle.to_variable(np.array([-1, 0.3, 2.5])) + m = paddle.nn.Hardshrink() + out = m(x) # [-1., 0., 2.5] diff --git a/doc/fluid/api_cn/nn_cn/hard_shrink_cn.rst b/doc/fluid/api_cn/nn_cn/hard_shrink_cn.rst deleted file mode 100644 index 336fef4da..000000000 --- a/doc/fluid/api_cn/nn_cn/hard_shrink_cn.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. _cn_api_nn_cn_hard_shrink: - -hard_shrink -------------------------------- -:doc_source: paddle.fluid.layers.hard_shrink - - diff --git a/doc/fluid/api_cn/nn_cn/hardshrink_cn.rst b/doc/fluid/api_cn/nn_cn/hardshrink_cn.rst new file mode 100644 index 000000000..cb837884b --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/hardshrink_cn.rst @@ -0,0 +1,42 @@ +.. _cn_api_nn_cn_hard_shrink: + +hardshrink +------------------------------- +.. py:functional:: paddle.nn.functional.hardshrink(x, threshold=0.5, name=None) + +hardshrink激活层。计算公式如下: + +.. math:: + + hardshrink(x)= + \left\{ + \begin{aligned} + &x, & & if \ x > threshold \\ + &x, & & if \ x < -threshold \\ + &0, & & if \ others + \end{aligned} + \right. + +其中,:math:`x` 为输入的 Tensor + +参数 +:::::::::: + - x (Tensor) - 输入的 ``Tensor`` ,数据类型为:float32、float64。 + - threshold (float, 可选) - hard_shrink激活计算公式中的threshold值。默认值为0.5。 + - name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +返回 +:::::::::: + ``Tensor`` ,数据类型和形状同 ``x`` 一致。 + +代码示例 +:::::::::: + + import paddle + import paddle.nn.functional as F + import numpy as np + + paddle.disable_static() + + x = paddle.to_variable(np.array([-1, 0.3, 2.5])) + out = F.hardshrink(x) # [-1., 0., 2.5] diff --git a/doc/fluid/api_cn/nn_cn/softmax_cn.rst b/doc/fluid/api_cn/nn_cn/softmax_cn.rst index 5879cfa43..2e7b07ccf 100644 --- a/doc/fluid/api_cn/nn_cn/softmax_cn.rst +++ b/doc/fluid/api_cn/nn_cn/softmax_cn.rst @@ -2,7 +2,7 @@ softmax ------------------------------- -.. py:class:: paddle.nn.functional.softmax(x, axis=-1, name=None) +.. py:functional:: paddle.nn.functional.softmax(x, axis=-1, name=None) 该OP实现了softmax层。OP的计算过程如下: @@ -27,9 +27,9 @@ softmax - 示例1(矩阵一共有三维。axis = -1,表示沿着最后一维(即第三维)做softmax操作) -.. code-block:: python +.. code-block:: text - 输入 + # input x.shape = [2, 3, 4] @@ -42,7 +42,7 @@ softmax axis = -1 - 输出 + # output out.shape = [2, 3, 4] @@ -55,9 +55,9 @@ softmax - 示例2(矩阵一共有三维。axis = 1,表示沿着第二维做softmax操作) -.. code-block:: python +.. code-block:: text - 输入 + # input x.shape = [2, 3, 4] @@ -70,7 +70,7 @@ softmax axis = 1 - 输出 + # output out.shape = [2, 3, 4] @@ -101,7 +101,7 @@ softmax import paddle.nn.functional as F import numpy as np - paddle.enable_imperative() + paddle.disable_static() x = np.array([[[2.0, 3.0, 4.0, 5.0], [3.0, 4.0, 5.0, 6.0], @@ -109,7 +109,7 @@ softmax [[1.0, 2.0, 3.0, 4.0], [5.0, 6.0, 7.0, 8.0], [6.0, 7.0, 8.0, 9.0]]], 'float32') - x = paddle.imperative.to_variable(x) + x = paddle.to_variable(x) out = F.softmax(x) # [[[0.0320586 , 0.08714432, 0.23688282, 0.64391426], # [0.0320586 , 0.08714432, 0.23688282, 0.64391426], -- GitLab