Well, you could use regression loss functions like nn.MSELoss, but they might perform poorly on a classification task. Another approach would be to soften your target and use soft labels in nn.CrossEntropyLoss. There are some shortcomings to this approach also, as explained here 8.