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
import numpy as np
x = paddle.to_tensor(np.array([-0.9, -0.2, 0.1, 0.8]))
out = F.softshrink(x) # [-0.4, 0, 0, 0.3]