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)