nn.Softmax(dim=None)
- dim: 计算的维度 A dimension along which Softmax will be computed (so every slice along dim will sum to 1).
用softmax函数将N维输入进行归一化,归一化之后每个输出的Tensor范围在[0, 1],并且归一化的那一维和为1
Applies the Softmax function to an n-dimensional input Tensor rescaling them so that the elements of the n-dimensional output Tensor lie in the range [0,1] and sum to 1.
实例:从下面的例子可以看出,Softmax
维度为0时对最后一维即列进行归一化,因此,维度为1时对行进行归一化
1 | input = torch.Tensor([[1,2,3], [4,5,6], [7,8,9]]) |