# How can I use class\_weights when training?

**URL:** <https://discuss.huggingface.co/t/how-can-i-use-class-weights-when-training/1067>\
**Category:** 🤗Transformers\
**Created:** [September 9, 2020, 2:29pm UTC](https://discuss.huggingface.co/t/how-can-i-use-class-weights-when-training/1067 "2020-09-09T14:29:03Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![PhilipMay](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/philipmay/32/2324_2.png) [@PhilipMay](https://discuss.huggingface.co/u/PhilipMay)\
**Post date:** [September 29, 2020, 10:40am UTC](https://discuss.huggingface.co/t/how-can-i-use-class-weights-when-training/1067/2 "2020-09-29T10:40:31Z")

</div>

Answering my own question:  
Subclass `Trainer` and override the `compute_loss` method (see example [here](https://huggingface.co/transformers/master/main_classes/trainer.html)).

---

_[View the full topic](https://discuss.huggingface.co/t/how-can-i-use-class-weights-when-training/1067)._
