softshrink

paddle.nn.functional. softshrink ( x, threshold=0.5, name=None ) [源代码]

softshrink 激活层

softshrink(x)={xthreshold,if x>thresholdx+threshold,if x<threshold0,otherwise

其中,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])