mindspore.mint.nn.LogSoftmax
- class mindspore.mint.nn.LogSoftmax(dim=None)[source]
Applies the Log Softmax function to the input tensor on the specified axis. For a slice along the given axis, denoted as \(x\) with each element \(x_i\), the LogSoftmax function is defined as follows:
\[\text{output}(x_i) = \log \left(\frac{\exp(x_i)} {\sum_{j = 0}^{N-1}\exp(x_j)}\right),\]where \(N\) is the length of the input tensor along the specified axis.
- Parameters
dim (int, optional) – Specify the calculation dimension for LogSoftmax. Default:
None.- Returns
Tensor.
- Supported Platforms:
Ascend
Examples
>>> 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]]