How can I use class_weights when training?

I have an unbalanced dataset. When training I want to pass class_weights so the update for rare classes is highen than for large classes. How is this possible in HF with PyTorch?


1 Like

Answering my own question:
Subclass Trainer and override the compute_loss method (see example here).

1 Like

Sorry I missed your question and didn’t point you to this directly.

1 Like

No worries. You did on GitHub… :slight_smile: :+1:

Hi @PhilipMay !Do you mind pasting an example please, as I don’t really understand the documentation