How to add weighted CrossEntropy loss in sequence classification task?
## ❓ Questions & Help

<!-- A clear and concise description of the question. -->
I am doing a sequence classification task base on run_ner.py. My dataset is an imbalenced dataset and apperantly 'O' label appears far more than other labels. I'm wondering if it is helpful to use weighted CrossEntropy loss.
If the answer is 'yes', how to add weight to the loss function? Currently I hard code the weight in BertForSequenceClassification class (in modeling_bert.py). I feel it is not a smart way to do it. Do you have some advice on how to add the weight infomation?
Many thanks.
Hi, no specific advice other than computing the loss your-self outside of the model's forward method.