# Class weights in Trainer() instance

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fclass-weights-in-trainer-instance%2F9882%3E%5C
**Category:** Intermediate\
**Created:** [September 10, 2021, 11:51am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fclass-weights-in-trainer-instance%2F9882 "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](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmarlon89)%5C
**Post date:** [September 10, 2021, 11:51am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fclass-weights-in-trainer-instance%2F9882%2F1 "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](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fsgugger)%5C
**Post date:** [September 10, 2021, 1:41pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fclass-weights-in-trainer-instance%2F9882%2F2 "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).
