nn.NLLLoss is used for a multi-class classification use case.
While the model output should contain the log probabilities for all classes, the target should be a LongTensor containing the class indices.
Based on the shape it looks like your target might be a one-hot encoded tensor.
If that’s the case (and the number of classes is encoded in dim1), you could use
target = torch.argmax(target, 1)

to get the class indices in the right shape.