# Class weights in Trainer() instance

**URL:** <https://discuss.huggingface.co/t/class-weights-in-trainer-instance/9882>\
**Category:** Intermediate\
**Created:** [September 10, 2021, 11:51am UTC](https://discuss.huggingface.co/t/class-weights-in-trainer-instance/9882 "2021-09-10T11:51:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![marlon89](https://avatars.discourse-cdn.com/v4/letter/m/6de8d8/32.png) [@marlon89](https://discuss.huggingface.co/u/marlon89)\
**Post date:** [September 10, 2021, 11:51am UTC](https://discuss.huggingface.co/t/class-weights-in-trainer-instance/9882/1 "2021-09-10T11:51:08Z")

</div>

Hello everyone,

I know the question isn’t new but I wanted to see if there have been new features/developments to this: Is there a way to easily add class weights while fine tuning a bert model? I am doing the fine tuning with the Trainer() instance.

Cheers

---

<div class="post-metadata">

**Author:** ![sgugger](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/sgugger/32/2291_2.png) [@sgugger](https://discuss.huggingface.co/u/sgugger)\
**Post date:** [September 10, 2021, 1:41pm UTC](https://discuss.huggingface.co/t/class-weights-in-trainer-instance/9882/2 "2021-09-10T13:41:25Z")

</div>

You can override the loss computation anyway you like by subclassing the `Trainer`, as is documented [here](https://huggingface.co/transformers/main_classes/trainer.html).
