Softplus¶ class torch.nn.Softplus(beta=1.0, threshold=20.0)[source][source]¶ 逐元素地应用 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)