torch normalize
torch.nn.functional.normalize
范数
0范数,1范数,2范数
见范数blog:
https://blog.youkuaiyun.com/cursethegod/article/details/80372718
见示例:
input_ = torch.randn((3, 4))
a = torch.nn.Softmax()(input_)
b = torch.nn.functional.normalize(a)
a的结果为:
tensor([[0.2074, 0.2850, 0.1973, 0.3103],
[0.2773, 0.1442, 0.3652, 0.2132],
[0.3244, 0.3206, 0.0216, 0.3334]])
b的结果为:
tensor([[0.4071, 0.5595, 0.3874, 0.6092],
[0.5274, 0.2743, 0.6945, 0.4054],
[0.5738, 0.5671, 0.0381, 0.5896]])
b中的0.4071其实就是a中的 0.2074/根号下(0.20740.2074+0.2850.285+0.19730.1973+0.31030.3103) = 0.407: