Get loss for individual samples

I would like to get the individual loss for each sample, but the loss functions such as crossEntropyLoss output the average loss in a minibatch. Could I do it using minibatch?

I couldn’t find any python code defining these loss functions. Do I need to modify the C backend?


You are right, it’s in C backend. Or you can write your own cross entropy loss. You can use gather to extract the log probability of correct class label.

1 Like