快捷方式

LogSoftmax

class torch.nn.LogSoftmax(dim=None)[source][source]

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

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 的維度。

返回值

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

返回型別

None

示例

>>> m = nn.LogSoftmax(dim=1)
>>> input = torch.randn(2, 3)
>>> output = m(input)

文件

訪問 PyTorch 的全面開發者文件

檢視文件

教程

獲取針對初學者和高階開發者的深入教程

檢視教程

資源

查詢開發資源並解答疑問

檢視資源