l = torch.tensor([2.0, 1.0, 0.1, -1.0]) p = torch.softmax(l, dim=0) print(p) # tensor([0.6381, 0.2347, 0.0954, 0.0318]) print(p.sum()) # tensor(1.0000) print(-torch.log(p[0])) # tensor(0.4493)