mindspore.ops.log_softmax
- mindspore.ops.log_softmax(logits, axis=- 1)[源代码]
- 在指定轴上对输入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长度。 - 参数:
- logits (Tensor) - 输入Tensor,上述公式中的 \(x\) ,shape为 \((N, *)\) ,其中 \(*\) 表示任意数量的附加维度,其数据类型为float16或float32。 
- axis (int) - 指定进行运算的轴。默认值: - -1。
 
- 返回:
- Tensor,数据类型和shape与 logits 相同。 
- 异常:
- TypeError - axis 不是int。 
- TypeError - logits 的数据类型既不是float16也不是float32。 
- ValueError - axis 不在[-len(logits.shape), len(logits.shape))范围中。 
- ValueError - logits 的维度小于1。 
 
- 支持平台:
- Ascend- GPU- CPU
 - 样例: - >>> import mindspore >>> import numpy as np >>> from mindspore import Tensor, ops >>> logits = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32) >>> output = ops.log_softmax(logits) >>> print(output) [-4.4519143 -3.4519143 -2.4519143 -1.4519144 -0.4519144]