Is it possible to add weights to every entry in the input for CrossEntropyLoss, using only python code while maintaining efficiency?
Alternatively, I looked at the underlying C code: ClassNLLCriterion.c and it seems that it may be modified to make use of the class weights to do entry weighting. Is this feasible for running some experiments?
I’d probably use reduce=False in the loss and do the weighting and summing myself. I don’t think you will notice the performance difference if you have any nontrivial computation in the model you waant to train.
Thanks so much for the reply. I’m worried that reduce=False will only give me access to mini batch level weights. Is there any way to get to the individual entries?
You’re totally right, I think. From the documentation I thought it would only give minibatch level access but the reduce=False flag uses the original input dimension for the output.