mindspore.nn.SoftShrink

查看源文件
class mindspore.nn.SoftShrink(lambd=0.5)[源代码]

逐元素计算SoftShrink激活函数。

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

SoftShrink函数图:

../../_images/Softshrink.png
参数:
  • lambd (number, 可选) - SoftShrink公式中的 \(\lambda\) ,必须不小于零。默认 0.5

输入:
  • input (Tensor) - 输入tensor。支持数据类型:

    • Ascend:mindspore.float16、mindspore.float32、mindspore.bfloat16。

    • CPU/GPU:mindspore.float16、mindspore.float32。

输出:

Tensor。

支持平台:

Ascend GPU CPU

样例:

>>> import mindspore
>>> input = mindspore.tensor([[ 0.5297,  0.7871,  1.1754], [ 0.7836,  0.6218, -1.1542]], mindspore.float16)
>>> softshrink = mindspore.nn.SoftShrink()
>>> output = softshrink(input)
>>> print(output)
[[ 0.02979  0.287    0.676  ]
 [ 0.2837   0.1216  -0.6543 ]]