評價此頁

LogSoftmax#

class torch.nn.modules.activation.LogSoftmax(dim=None)[原始碼]#

對 n 維輸入 Tensor 應用 log(Softmax(x))\log(\text{Softmax}(x)) 函式。

LogSoftmax 的公式可以簡化為

LogSoftmax(xi)=log(exp(xi)jexp(xj))\text{LogSoftmax}(x_{i}) = \log\left(\frac{\exp(x_i) }{ \sum_j \exp(x_j)} \right)
形狀
  • 輸入: ()(*),其中 * 表示任意數量的附加維度

  • 輸出: ()(*),與輸入形狀相同

引數

dim (int) – 計算 LogSoftmax 的維度。

返回

一個與輸入具有相同維度和形狀的張量,其值在 [-inf, 0) 範圍內

返回型別

示例

>>> m = nn.LogSoftmax(dim=1)
>>> input = torch.randn(2, 3)
>>> output = m(input)
extra_repr()[原始碼]#

返回模組的額外表示。

返回型別

str

forward(input)[原始碼]#

執行前向傳播。

返回型別

張量