Multi-Class Cross Entropy Loss function implementation in PyTorch 
  
  
    You could try the following code: 
batch_size = 4
-torch.mean(torch.sum(labels.view(batch_size, -1) * torch.log(preds.view(batch_size, -1)), dim=1))
  


In this topic ,ptrblck said that a  F.softmax function at dim=1 should be added before the nn.CrossEntropyLoss().
In the document(https://pytorch.org/docs/stable/nn.html?highlight=crossentropy#torch.nn.CrossEntropyLoss 636) , it return nll_loss(log_softmax(input, 1) which return negative log and softmax.
My question is that  should I calculated the softmax at dim=1 before the function nn.CrossEntropyLoss  which already have a softmax at dim=1 ?