This code will most likely not work as intended, since you are passing the prediction indices after torch.max to the criterion, which will break the computation graph.
Also, don’t use the .data attribute.
Could you please give me an example, what the loss of a particular class would look like?
Do you want to get the predictions of your model for class 3 and compare it as a binary classification?