评价此页

Softplus#

class torch.nn.Softplus(beta=1.0, threshold=20.0)[source]#

Element-wise 应用 Softplus 函数。

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

SoftPlus 是 ReLU 函数的光滑近似,可用于约束模型的输出始终为正。

为保证数值稳定性,当 input×β>thresholdinput \times \beta > threshold 时,实现将恢复为线性函数。

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

  • threshold (float) – 大于此值的输入将恢复为线性函数。默认值:20

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

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

../_images/Softplus.png

示例

>>> m = nn.Softplus()
>>> input = torch.randn(2)
>>> output = m(input)