LogSoftmax¶ class torch.nn.LogSoftmax(dim=None)[原始碼][原始碼]¶ 將 log(Softmax(x))\log(\text{Softmax}(x))log(Softmax(x)) 函數應用於 n 維輸入張量。 LogSoftmax 公式可以簡化為: LogSoftmax(xi)=log(exp(xi)∑jexp(xj))\text{LogSoftmax}(x_{i}) = \log\left(\frac{\exp(x_i) }{ \sum_j \exp(x_j)} \right) LogSoftmax(xi)=log(∑jexp(xj)exp(xi)) 形狀 輸入:(∗)(*)(∗),其中 * 表示任何數量的額外維度 輸出:(∗)(*)(∗),與輸入相同的形狀 參數 dim ( int ) – 將計算 LogSoftmax 的維度。 返回 一個與輸入具有相同維度和形狀的張量,其值範圍為 [-inf, 0) 返回類型 無 範例 >>> m = nn.LogSoftmax(dim=1) >>> input = torch.randn(2, 3) >>> output = m(input)