megengine.functional.nn.logsoftmax¶
- logsoftmax(inp, axis)[源代码]¶
对一个n维的输入张量做
函数 的公式可以简化为:为了提高数值稳定性,实现根据以下的变换:
实际案例
import numpy as np from megengine import tensor import megengine.functional as F x = tensor(np.arange(-5, 5, dtype=np.float32)).reshape(2,5) y = F.logsoftmax(x, axis=1) print(y.numpy().round(decimals=4))
输出:
[[-4.4519 -3.4519 -2.4519 -1.4519 -0.4519] [-4.4519 -3.4519 -2.4519 -1.4519 -0.4519]]
- 返回类型