评价此页

Hardshrink#

class torch.nn.modules.activation.Hardshrink(lambd=0.5)[源代码]#

逐元素应用 Hard Shrinkage (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}
参数

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

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

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

../_images/Hardshrink.png

示例

>>> m = nn.Hardshrink()
>>> input = torch.randn(2)
>>> output = m(input)
extra_repr()[源代码]#

返回模块的额外表示。

返回类型

str

forward(input)[源代码]#

运行前向传播。

返回类型

张量