评价此页

Hardshrink#

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

Element-wise applies the Hard Shrinkage (Hardshrink) function.

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}
参数

lambd (float) – The λ\lambda value for the Hardshrink formulation. Default: 0.5

形状
  • Input: ()(*), where * represents any number of dimensions.

  • Output: ()(*), same shape as the input.

../_images/Hardshrink.png

示例

>>> m = nn.Hardshrink()
>>> input = torch.randn(2)
>>> output = m(input)