软 plus 函数

classtorch.nn.Softplus(beta=1.0, threshold=20.0)[源代码]

对每个元素应用Softplus函数。

$\text{Softplus}(x) = \frac{1}{\beta} * \log(1 + \exp(\beta * x))$

SoftPlus 是 ReLU 函数的一种平滑近似,可用于确保机器的输出始终为正。

为了保证数值稳定性,当$input \times \beta > threshold$时,实现会退回到线性函数。

参数
  • beta (float) – Softplus 公式中的 $\beta$ 值。默认值:1

  • threshold (float) – 阈值以上的情况将恢复为线性函数。默认值:20

形状:
  • 输入: $(*)$,其中$*$表示任意维度的数量。

  • 输出: $(*)$,形状与输入相同。

{BASE_RAW_UPLOAD_URL}/pytorch-doc-2.5/eeaae7ea7b1fdbe29ec22c49189a71a3.png

示例:

>>> m = nn.Softplus()
>>> input = torch.randn(2)
>>> output = m(input)
本页目录