Hardshrink¶ 類 torch.nn.Hardshrink(lambd=0.5)[source][source]¶ 逐元素應用 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)