# SequenceClassification num\_labels\<2 doesn't work on trainer

**URL:** <https://discuss.huggingface.co/t/sequenceclassification-num-labels-2-doesnt-work-on-trainer/13181>\
**Category:** Beginners\
**Created:** [December 28, 2021, 2:25pm UTC](https://discuss.huggingface.co/t/sequenceclassification-num-labels-2-doesnt-work-on-trainer/13181 "2021-12-28T14:25:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bhavnicksm](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/bhavnicksm/32/3547_2.png) [@bhavnicksm](https://discuss.huggingface.co/u/bhavnicksm)\
**Post date:** [December 28, 2021, 2:25pm UTC](https://discuss.huggingface.co/t/sequenceclassification-num-labels-2-doesnt-work-on-trainer/13181/1 "2021-12-28T14:25:01Z")

</div>

I was trying out running AutoModelForSequenceClassification for num\_labels = 1 and for num\_labels =2 but no matter what changes I did, the Trainer module kept throwing some or the other unfixable error.

In num\_labels=1, it worked but the model learnt absolutely nothing with the regression loss. I think there should be a **BinaryCrossEntropyLoss** there instead of the **MSELoss** because it just doesn’t do a good job in training the model.

For num\_labels=2, unless you turn on the multi-label-problem=True, it doesn’t work because the trainer keeps asking for targets of size [\*, 2] without expanding the labels into one-hot.

Now, this could be a bug or there might be a specific way to make it work.BCEwithLogitsLoss is a much better option than MSELoss and I can’t think of the reason why someone would use MSELoss.

---

<div class="post-metadata">

**Author:** ![forwins](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/forwins/32/26880_2.png) [@forwins](https://discuss.huggingface.co/u/forwins)\
**Post date:** [May 14, 2024, 6:30am UTC](https://discuss.huggingface.co/t/sequenceclassification-num-labels-2-doesnt-work-on-trainer/13181/2 "2024-05-14T06:30:34Z")

</div>

Hi there. MSELoss is actually not bad for binary classification, because it used sigmoid function and sum up to 1, but if u gonna use model with multi-label-problem u have to choose BCEwithLogitsLoss because it uses the one hot encoding with softmax and logits therefore whatever how many categories u want to predict it will sum up to 1 and works well
