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时,实现会回退到线性函数。 Parameters beta (float) – Softplus 公式的 β\betaβ 值。默认值:1 阈值 (float) – 高于此值的数值将恢复为线性函数。默认值:20 Shape: 输入:(∗)(*)(∗),其中 ∗*∗ 表示任意数量的维度。 输出: (∗)(*)(∗), 与输入形状相同。 示例: >>> m = nn.Softplus() >>> input = torch.randn(2) >>> output = m(input)