nn.CrossEntropyLoss细谈
nn.CrossEntropyLoss的官方定义
This criterion combines LogSoftmax and NLLLoss in one single class.
https://pytorch.org/docs/stable/nn.html
CrossEntropyLoss代码实例
import torch
y = torch.LongTensor([0])
z = torch.Tensor([[0.2,0.1,-0.1]])
criterion = torch.nn.CrossEntropyLoss()
loss = criterion(z,y)
print(loss)