How to interpret class weights when using CrossEntropyLoss

The loss for the current sample will be multiplied with the corresponding class weight and the final loss will be normalized by the sum of all used weightes (if reduction='mean' is used).
The docs give the formula, while this post gives you a manual example.

So the “prioritization” is relative to the used samples, not absolute.

1 Like