Softplus¶ class torch.nn.Softplus(beta=1.0, threshold=20.0)[來源][來源]¶ 逐元素套用 Softplus 函數。 Softplus(x)=1β∗log(1+exp(β∗x))\text{Softplus}(x) = \frac{1}{\beta} * \log(1 + \exp(\beta * x)) Softplus(x)=β1∗log(1+exp(β∗x))SoftPlus 是一個對 ReLU 函數的平滑近似,可用於約束機器輸出始終為正數。 為了數值穩定性,當 input×β>thresholdinput \times \beta > thresholdinput×β>threshold 時,實現會回復到線性函數。 參數 beta (float) – Softplus 公式中的 β\betaβ 值。預設值:1 threshold (float) – 高於此值會回復到線性函數。預設值:20 形狀 輸入:(∗)(*)(∗),其中 ∗*∗ 表示任何數量的維度。 輸出:(∗)(*)(∗),與輸入形狀相同。 範例 >>> m = nn.Softplus() >>> input = torch.randn(2) >>> output = m(input)