# Multiclass vs Multilabel

**URL:** <https://discuss.huggingface.co/t/multiclass-vs-multilabel/672>\
**Category:** Beginners\
**Created:** [August 11, 2020, 8:29am UTC](https://discuss.huggingface.co/t/multiclass-vs-multilabel/672 "2020-08-11T08:29:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucaseo](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/lucaseo/32/250_2.png) [@lucaseo](https://discuss.huggingface.co/u/lucaseo)\
**Post date:** [August 11, 2020, 8:29am UTC](https://discuss.huggingface.co/t/multiclass-vs-multilabel/672/1 "2020-08-11T08:29:13Z")

</div>

Hello all,

I’m relatively new to transformer library and its models.

What I’m try-out is fine-tuning pretrained model for classification task.

I understood that BertForSequenceClassification is for classical **multi-class** classification.  
However, I’m confused on how to achieve “multi-label” classification task.

Can anyone guide me to multilabel classification?

ps.)

What I mean by Multiclass, it means labels are exclusive to each other  
ex)

- num\_labels = 5
- labels=[0, 1, 0, 0, 0]

Multilabel

- num\_labels = 5
- labels = [1, 0, 0, 1, 0]

---

<div class="post-metadata">

**Author:** ![marrrcin](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/marrrcin/32/12238_2.png) [@marrrcin](https://discuss.huggingface.co/u/marrrcin)\
**Post date:** [August 11, 2020, 9:26am UTC](https://discuss.huggingface.co/t/multiclass-vs-multilabel/672/2 "2020-08-11T09:26:17Z")

</div>

See how `transformers.modeling_bert.BertForSequenceClassification` is implemented - there is a `CrossEntropyLoss` built into this class internally. You can create custom class (PyTorch module) similar to `BertForSequenceClassification` and apply multi-label loss of your choice there. You can also look-up my blogpost [https://zablo.net/blog/post/custom-classifier-on-bert-model-guide-polemo2-sentiment-analysis/](https://zablo.net/blog/post/custom-classifier-on-bert-model-guide-polemo2-sentiment-analysis/) where I show how to build totally custom model on top of the pre-trained transformers models.
