softshrink¶
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
返回¶
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])