評價此頁

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)[原始碼]#

執行前向傳播。

返回型別

張量