Shortcuts

Hardshrink

class torch.nn.Hardshrink(lambd=0.5)[源码]

逐元素应用硬收缩(Hardshrink)函数。

Hardshrink 定义为:

HardShrink(x)={x, if x>λx, if x<λ0, otherwise \text{HardShrink}(x) = \begin{cases} x, & \text{ if } x > \lambda \\ x, & \text{ if } x < -\lambda \\ 0, & \text{ otherwise } \end{cases}
Parameters

lambd (float) – Hardshrink 公式的 λ\lambda 值。默认值:0.5

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

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

../_images/Hardshrink.png

示例:

>>> m = nn.Hardshrink()
>>> input = torch.randn(2)
>>> output = m(input)
优云智算