1. 程式人生 > 其它 >torch.nn.LogSoftmax用法

torch.nn.LogSoftmax用法

技術標籤:PytorchpytorchLogSoftmax

LOGSOFTMAX

CLASS torch.nn.LogSoftmax(dim: Optional[int] = None)

\large log(Softmax(x))函式應用於n維輸入張量。 LogSoftmax公式可以簡化為:

\large \text{LogSoftmax}(x_{i}) = \log\left(\frac{\exp(x_i) }{ \sum_j \exp(x_j)} \right)

Shape:

  • Input:(∗)where∗means, any number of additional dimensions

  • Output:(∗), same shape as the input

Parameters

dim(int) – A dimension along whichLogSoftmaxwill be computed.用來計算LogSoftmax的維度。

Returns

a Tensor of the same dimension and shape as the input with values in the range [-inf, 0)。與輸入具有相同維度和形狀的張量,其值在[-inf,0)範圍內。

Examples:

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