评价此页

Softplus#

class torch.nn.modules.activation.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 是 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)
extra_repr()[源码]#

返回模块的额外表示。

返回类型

str

forward(input)[源码]#

运行前向传播。

返回类型

张量