nn.NLLLoss expects log probabilities as the model outputs, so use F.log_softmax on your output before passing it to the criterion or alternatively keep your current model architecture and use nn.CrossEntropyLoss instead, which will internally use F.log_softmax + nn.NLLLoss.