Hardshrink¶ class torch.nn.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} HardShrink(x)=⎩⎨⎧x,x,0, if x>λ if x<−λ otherwise 參數 lambd (float) – Hardshrink 公式中的 λ\lambdaλ 值。預設值:0.5 形狀 輸入:(∗)(*)(∗),其中 ∗*∗ 表示任意數量的維度。 輸出:(∗)(*)(∗),與輸入形狀相同。 範例 >>> m = nn.Hardshrink() >>> input = torch.randn(2) >>> output = m(input)