Softshrink

class paddle.nn. Softshrink ( threshold=0.5, name=None ) [源代码]

Softshrink 激活层

\[\begin{split}Softshrink(x)= \begin{cases} x - threshold, \text{if } x > threshold \\ x + threshold, \text{if } x < -threshold \\ 0, \text{otherwise} \end{cases}\end{split}\]

其中,\(x\) 为输入的 Tensor。

参数

  • threshold (float,可选) - Softshrink 激活计算公式中的 threshold 值,必须大于等于零。默认值为 0.5。

  • name (str,可选) - 具体用法请参见 Name,一般无需设置,默认值为 None。

形状

  • input:任意形状的 Tensor。

  • output:和 input 具有相同形状的 Tensor。

代码示例

>>> import paddle

>>> x = paddle.to_tensor([-0.9, -0.2, 0.1, 0.8])
>>> m = paddle.nn.Softshrink()
>>> out = m(x)
>>> print(out)
Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
[-0.39999998,  0.        ,  0.        ,  0.30000001])