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} HardShrink(x)=⎩⎨⎧x,x,0, if x>λ if x<−λ otherwise Parameters lambd (float) – Hardshrink 公式的 λ\lambdaλ 值。默认值:0.5 Shape: 输入:(∗)(*)(∗),其中 ∗*∗ 表示任意数量的维度。 输出: (∗)(*)(∗), 与输入形状相同。 示例: >>> m = nn.Hardshrink() >>> input = torch.randn(2) >>> output = m(input)