评价此页

Softshrink#

class torch.nn.Softshrink(lambd=0.5)[source]#

逐元素应用 soft shrinkage 函数。

SoftShrinkage(x)={xλ, if x>λx+λ, if x<λ0, otherwise \text{SoftShrinkage}(x) = \begin{cases} x - \lambda, & \text{ if } x > \lambda \\ x + \lambda, & \text{ if } x < -\lambda \\ 0, & \text{ otherwise } \end{cases}
参数

lambd (float) – Softshrink 公式中的 λ\lambda 值(必须大于等于零)。默认值:0.5

形状
  • 输入: ()(*),其中 * 表示任意数量的维度。

  • 输出: ()(*),形状与输入相同。

../_images/Softshrink.png

示例

>>> m = nn.Softshrink()
>>> input = torch.randn(2)
>>> output = m(input)
extra_repr()[source]#

返回模块的额外表示。

返回类型

str

forward(input)[source]#

运行前向传播。

返回类型

张量