From 82a9850ffc24afda75cba0fa19357d44114b4d74 Mon Sep 17 00:00:00 2001 From: WangXi Date: Sat, 22 Aug 2020 16:04:13 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90doc=E3=80=91sign=20&=20tanh=20(#2402)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refine sign tanh api, test=develop * Add Tanh, test=develop * fix en, test=develop --- doc/fluid/api/nn/activation.rst | 3 +- doc/fluid/api/nn/activation/Tanh.rst | 13 +++++++ doc/fluid/api/tensor/math.rst | 1 + doc/fluid/api/tensor/math/sign.rst | 10 +++++ doc/fluid/api_cn/layers_cn/sign_cn.rst | 6 --- doc/fluid/api_cn/nn_cn/activation_cn.rst | 3 +- .../api_cn/nn_cn/activation_cn/Tanh_cn.rst | 35 +++++++++++++++++ doc/fluid/api_cn/tensor_cn/sign_cn.rst | 27 ++++++++++++- doc/fluid/api_cn/tensor_cn/tanh_cn.rst | 39 +++++++------------ 9 files changed, 103 insertions(+), 34 deletions(-) create mode 100644 doc/fluid/api/nn/activation/Tanh.rst create mode 100644 doc/fluid/api/tensor/math/sign.rst create mode 100644 doc/fluid/api_cn/nn_cn/activation_cn/Tanh_cn.rst diff --git a/doc/fluid/api/nn/activation.rst b/doc/fluid/api/nn/activation.rst index d073a6f71c4..387e2f66dac 100644 --- a/doc/fluid/api/nn/activation.rst +++ b/doc/fluid/api/nn/activation.rst @@ -8,8 +8,9 @@ activation activation/ELU.rst activation/GELU.rst activation/Hardshrink.rst + activation/Tanh.rst activation/Hardtanh.rst activation/PReLU.rst activation/ReLU.rst activation/LogSigmoid.rst - activation/Softmax.rst + activation/Softmax.rst \ No newline at end of file diff --git a/doc/fluid/api/nn/activation/Tanh.rst b/doc/fluid/api/nn/activation/Tanh.rst new file mode 100644 index 00000000000..80cb491331f --- /dev/null +++ b/doc/fluid/api/nn/activation/Tanh.rst @@ -0,0 +1,13 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_nn_activation_Tanh: + +Tanh +--------- + +.. autoclass:: paddle.nn.layer.activation.Tanh + :members: + :inherited-members: + :noindex: + diff --git a/doc/fluid/api/tensor/math.rst b/doc/fluid/api/tensor/math.rst index 22f645a0fbe..50d66eac8b8 100644 --- a/doc/fluid/api/tensor/math.rst +++ b/doc/fluid/api/tensor/math.rst @@ -23,6 +23,7 @@ math math/mm.rst math/mul.rst math/pow.rst + math/sign.rst math/sin.rst math/sqrt.rst math/sum.rst diff --git a/doc/fluid/api/tensor/math/sign.rst b/doc/fluid/api/tensor/math/sign.rst new file mode 100644 index 00000000000..5ee442aec63 --- /dev/null +++ b/doc/fluid/api/tensor/math/sign.rst @@ -0,0 +1,10 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! +.. _api_tensor_math_sign: + +sign +------ + +.. autofunction:: paddle.tensor.math.sign + :noindex: + diff --git a/doc/fluid/api_cn/layers_cn/sign_cn.rst b/doc/fluid/api_cn/layers_cn/sign_cn.rst index 5559e7a7bef..7b5e84aa970 100644 --- a/doc/fluid/api_cn/layers_cn/sign_cn.rst +++ b/doc/fluid/api_cn/layers_cn/sign_cn.rst @@ -5,12 +5,6 @@ sign .. py:function:: paddle.fluid.layers.sign(x) -:alias_main: paddle.sign -:alias: paddle.sign,paddle.tensor.sign,paddle.tensor.math.sign -:old_api: paddle.fluid.layers.sign - - - 此OP对输入x中每个元素进行正负判断,并且输出正负判断值:1代表正,-1代表负,0代表零。 参数: diff --git a/doc/fluid/api_cn/nn_cn/activation_cn.rst b/doc/fluid/api_cn/nn_cn/activation_cn.rst index 14caa161565..0b776c0078e 100644 --- a/doc/fluid/api_cn/nn_cn/activation_cn.rst +++ b/doc/fluid/api_cn/nn_cn/activation_cn.rst @@ -11,6 +11,7 @@ activation activation_cn/ELU_cn.rst activation_cn/GELU_cn.rst activation_cn/Hardshrink_cn.rst + activation_cn/Tanh_cn.rst activation_cn/Hardtanh_cn.rst activation_cn/PRelu_cn.rst activation_cn/ReLU_cn.rst @@ -18,4 +19,4 @@ activation activation_cn/Softmax_cn.rst activation_cn/LogSoftmax_cn.rst activation_cn/Sigmoid_cn.rst - activation_cn/LogSigmoid_cn.rst + activation_cn/LogSigmoid_cn.rst \ No newline at end of file diff --git a/doc/fluid/api_cn/nn_cn/activation_cn/Tanh_cn.rst b/doc/fluid/api_cn/nn_cn/activation_cn/Tanh_cn.rst new file mode 100644 index 00000000000..4f97cdb57f0 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/activation_cn/Tanh_cn.rst @@ -0,0 +1,35 @@ +.. _cn_api_nn_Tanh: + +Tanh +------------------------------- +.. py:class:: paddle.nn.Tanh(name=None) + +Tanh激活层 + +.. math:: + Tanh(x) = \frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} + + +参数 +:::::::::: + - 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_tensor(np.array([-0.4, -0.2, 0.1, 0.3])) + m = paddle.nn.Tanh() + out = m(x) + print(out.numpy()) + # [-0.37994896 -0.19737532 0.09966799 0.29131261] \ No newline at end of file diff --git a/doc/fluid/api_cn/tensor_cn/sign_cn.rst b/doc/fluid/api_cn/tensor_cn/sign_cn.rst index becd204197a..e1443fc2dfa 100644 --- a/doc/fluid/api_cn/tensor_cn/sign_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/sign_cn.rst @@ -1,7 +1,30 @@ -.. _cn_api_tensor_cn_sign: +.. _cn_api_tensor_sign: sign ------------------------------- -:doc_source: paddle.fluid.layers.sign +.. py:function:: paddle.sign(x, name=None) + +此OP对输入x中每个元素进行正负判断,并且输出正负判断值:1代表正,-1代表负,0代表零。 + +参数: + - **x** (Tensor) – 进行正负值判断的多维Tensor,数据类型为 float16, float32或float64。 + - **name** (str,可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 + +返回:输出正负号Tensor,数据的shape大小及数据类型和输入 ``x`` 一致。 + +返回类型:Tensor + +**代码示例** + +.. code-block:: python + + import numpy as np + import paddle + + data = np.array([3.0, 0.0, -2.0, 1.7], dtype='float32') + paddle.disable_static() + x = paddle.to_tensor(data) + out = paddle.sign(x=x) + print(out) # [1.0, 0.0, -1.0, 1.0] diff --git a/doc/fluid/api_cn/tensor_cn/tanh_cn.rst b/doc/fluid/api_cn/tensor_cn/tanh_cn.rst index 84e295cb73c..ee81756c3cf 100644 --- a/doc/fluid/api_cn/tensor_cn/tanh_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/tanh_cn.rst @@ -3,44 +3,35 @@ tanh ------------------------------- -.. py:function:: paddle.tanh(x, name=None, out=None) - -:alias_main: paddle.tanh -:alias: paddle.tanh,paddle.tensor.tanh,paddle.tensor.math.tanh -:update_api: paddle.fluid.layers.tanh - +.. py:function:: paddle.tanh(x, name=None) tanh 激活函数 .. math:: - out = \frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} - + out = \frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} 参数: - - **x** (Variable) - 支持任意维度的Tensor。数据类型为float32,float64或float16。 - - **name** (str,可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 - - **out** (Variable, 可选) – 指定存储运算结果的Tensor。如果设置为None或者不设置,将创建新的Tensor存储运算结果,默认值为None。 + - **x** (Tensor) - Tanh算子的输入, 多维Tensor,数据类型为 float16,float32或float64。 + - **name** (str, 可选) - 该层名称(可选,默认为None)。具体用法请参见 :ref:`api_guide_Name`。 -返回:返回类型为Variable(Tensor|LoDTensor), 数据类型同输入一致。 +返回: tanh的输出Tensor,和输入有着相同类型和shape。 + +返回类型: Tensor **代码示例**: .. code-block:: python - import numpy as np - import paddle - import paddle.fluid as fluid - - inputs = fluid.layers.data(name="x", shape = [3], dtype='float32') - output = paddle.tanh(inputs) + import paddle + import numpy as np - exe = fluid.Executor(fluid.CPUPlace()) - exe.run(fluid.default_startup_program()) + paddle.disable_static() - img = np.array([0, 0.5, 0.3]).astype(np.float32) + x_data = np.array([-0.4, -0.2, 0.1, 0.3]) + x = paddle.to_tensor(x_data) + out = paddle.tanh(x) + print(out.numpy()) + # [-0.37994896 -0.19737532 0.09966799 0.29131261] - res = exe.run(fluid.default_main_program(), feed={'x':img}, fetch_list=[output]) - print(res) - # [array([0., 0.46211717, 0.2913126], dtype=float32)]