Thank you for your reply

In a classifier, each class has its own loss, for example CrossEntropyLoss and the final loss is usually the value of them. I want to choose 5 classes with highest loss value and just backprop them.
Sorry, the code is illegal, what I want to express is the loss of the first class in a classifier.