評價此頁

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)[原始碼]#

執行前向傳播。

返回型別

張量