softshrink

paddle.nn.functional. softshrink ( x, 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

参数

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

返回

Tensor,数据类型和形状同 x 一致。

代码示例

import paddle
import paddle.nn.functional as F

x = paddle.to_tensor([-0.9, -0.2, 0.1, 0.8])
out = F.softshrink(x)
print(out)
# Tensor(shape=[4], dtype=float32, place=Place(gpu:0), stop_gradient=True,
#        [-0.39999998,  0.        ,  0.        ,  0.30000001])