mindspore.mint.nn.LogSoftmax
- class mindspore.mint.nn.LogSoftmax(dim=None)[源代码]
在指定轴上对输入Tensor应用LogSoftmax函数。对于指定轴上的切片 \(x\),其中每个元素为 \(x_i\),LogSoftmax函数的定义如下:
\[\text{output}(x_i) = \log \left(\frac{\exp(x_i)} {\sum_{j = 0}^{N-1}\exp(x_j)}\right),\]其中, \(N\) 为输入tensor在指定轴上的长度。
- 参数:
dim (int, 可选) - 指定进行LogSoftmax的计算维度。默认
None。
- 返回:
Tensor。
- 支持平台:
Ascend
样例:
>>> import mindspore >>> x = mindspore.tensor([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]], mindspore.float32) >>> log_softmax = mindspore.mint.nn.LogSoftmax(dim=-1) >>> output = log_softmax(x) >>> print(output) [[-5.00672150e+00 -6.72150636e-03 -1.20067215e+01] [-7.00091219e+00 -1.40009127e+01 -9.12250078e-04]]