LogSoftmax

torch.nn.LogSoftmax(dim=None)[源代码]

$\log(\text{Softmax}(x))$函数应用于 n 维输入张量。

LogSoftmax 公式可以简化为:

$\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)
本页目录