# Fine tuned multiclass model

**URL:** <https://discuss.huggingface.co/t/fine-tuned-multiclass-model/61640>\
**Category:** Beginners\
**Created:** [November 9, 2023, 10:59am UTC](https://discuss.huggingface.co/t/fine-tuned-multiclass-model/61640 "2023-11-09T10:59:16Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rajaa1](https://avatars.discourse-cdn.com/v4/letter/r/f9ae1b/32.png) [@Rajaa1](https://discuss.huggingface.co/u/Rajaa1)\
**Post date:** [November 9, 2023, 10:59am UTC](https://discuss.huggingface.co/t/fine-tuned-multiclass-model/61640/1 "2023-11-09T10:59:16Z")

</div>

Hello everyone,

I’m working on a project where I need to create a fine-tuned model that can take a sentence as input and output scores for a group of labels. I have a labeled dataset with 10,000 records, but I’m unsure how to handle the label columns. Specifically, I need guidance on how to convert these labels into numerical format and which type of model would be suitable for this task.

Any help or suggestions would be greatly appreciated. Thank you!

---

<div class="post-metadata">

**Author:** ![panigrah](https://avatars.discourse-cdn.com/v4/letter/p/bb73d2/32.png) [@panigrah](https://discuss.huggingface.co/u/panigrah)\
**Post date:** [November 9, 2023, 12:39pm UTC](https://discuss.huggingface.co/t/fine-tuned-multiclass-model/61640/2 "2023-11-09T12:39:03Z")

</div>

Here is one approach. This just allocates a sequential number to each category.

> **[Google Colaboratory](https://colab.research.google.com/github/abhimishra91/transformers-tutorials/blob/master/transformers_multiclass_classification.ipynb#scrollTo=qfOgYgtDEq4s)**

---

<div class="post-metadata">

**Author:** ![Rajaa1](https://avatars.discourse-cdn.com/v4/letter/r/f9ae1b/32.png) [@Rajaa1](https://discuss.huggingface.co/u/Rajaa1)\
**Post date:** [November 9, 2023, 6:49pm UTC](https://discuss.huggingface.co/t/fine-tuned-multiclass-model/61640/4 "2023-11-09T18:49:00Z")

</div>

Thank you, that was really helpful! However, my dataset contains around 255 unique labels. Converting all of them to numerical values isn’t practical. How can I address this issue?  
i think it is zero shot classification task I’m not sure

---

<div class="post-metadata">

**Author:** ![MattiLinnanvuori](https://avatars.discourse-cdn.com/v4/letter/m/ec9cab/32.png) [@MattiLinnanvuori](https://discuss.huggingface.co/u/MattiLinnanvuori)\
**Post date:** [November 11, 2023, 7:39am UTC](https://discuss.huggingface.co/t/fine-tuned-multiclass-model/61640/5 "2023-11-11T07:39:25Z")

</div>

Why isn’t it practical to convert all of them to numerical values? If you don’t want to, you can use zero-shot classification like in the following link but the result may not be as good. https://huggingface.co/docs/transformers/v4.35.0/en/main\_classes/pipelines#transformers.ZeroShotClassificationPipeline

---

<div class="post-metadata">

**Author:** ![Rajaa1](https://avatars.discourse-cdn.com/v4/letter/r/f9ae1b/32.png) [@Rajaa1](https://discuss.huggingface.co/u/Rajaa1)\
**Post date:** [November 11, 2023, 8:06am UTC](https://discuss.huggingface.co/t/fine-tuned-multiclass-model/61640/6 "2023-11-11T08:06:44Z")

</div>

Thanks, I’ve converted the labels to numerical values. Now, I’m wondering if it’s possible to fine-tune a zero-shot classification model. If so, could you please share a link or guide me on how to do it? or i must use the pipeline directly without fine tune

---

<div class="post-metadata">

**Author:** ![MattiLinnanvuori](https://avatars.discourse-cdn.com/v4/letter/m/ec9cab/32.png) [@MattiLinnanvuori](https://discuss.huggingface.co/u/MattiLinnanvuori)\
**Post date:** [November 11, 2023, 9:03am UTC](https://discuss.huggingface.co/t/fine-tuned-multiclass-model/61640/7 "2023-11-11T09:03:46Z")

</div>

[https://huggingface.co/docs/transformers/tasks/sequence\_classification](https://huggingface.co/docs/transformers/tasks/sequence_classification) Yes, it is possible to finetune a zero-shot classification model as explained in the link above. It is also possible to use a pretrained model.

---

<div class="post-metadata">

**Author:** ![MattiLinnanvuori](https://avatars.discourse-cdn.com/v4/letter/m/ec9cab/32.png) [@MattiLinnanvuori](https://discuss.huggingface.co/u/MattiLinnanvuori)\
**Post date:** [November 11, 2023, 9:05am UTC](https://discuss.huggingface.co/t/fine-tuned-multiclass-model/61640/8 "2023-11-11T09:05:44Z")

</div>

[https://discuss.huggingface.co/t/fine-tuning-zero-shot-models/15338](https://discuss.huggingface.co/t/fine-tuning-zero-shot-models/15338) The link above may be better.

---

<div class="post-metadata">

**Author:** ![Rajaa1](https://avatars.discourse-cdn.com/v4/letter/r/f9ae1b/32.png) [@Rajaa1](https://discuss.huggingface.co/u/Rajaa1)\
**Post date:** [November 11, 2023, 9:23am UTC](https://discuss.huggingface.co/t/fine-tuned-multiclass-model/61640/9 "2023-11-11T09:23:33Z")

</div>

Thank you for the information. I believe the first link is for text classification, not specifically designed for zero-shot classification. Can you clarify if there’s any difference in fine tuned between the two? I want a zero-shot  
Also, when fine-tuning a zero-shot classification model, what should the dataset format be? Should it be a labeled dataset with specific labels, or should it follow a specific structure, such as having two columns (premise and hypothesis) with labels like 1 (neutral), 0 (entailment), and 2 (contradiction)?

---

<div class="post-metadata">

**Author:** ![MattiLinnanvuori](https://avatars.discourse-cdn.com/v4/letter/m/ec9cab/32.png) [@MattiLinnanvuori](https://discuss.huggingface.co/u/MattiLinnanvuori)\
**Post date:** [November 11, 2023, 9:48am UTC](https://discuss.huggingface.co/t/fine-tuned-multiclass-model/61640/10 "2023-11-11T09:48:45Z")

</div>

[https://discuss.huggingface.co/t/new-pipeline-for-zero-shot-text-classification/681/14#:~:text=Thanks%20for%20the,add%20a%20bit%3A](https://discuss.huggingface.co/t/new-pipeline-for-zero-shot-text-classification/681/14#:~:text=Thanks%20for%20the,add%20a%20bit%3A) The link above describes the finetuning of zero-shot models. The difference between finetuning of sequences and NLI is that the former uses a custom number of labels and only the sequence to classify and the latter uses three labels in the specific order and the sequence to classify followed by the putative entailment as specified in the link above. That link also suggests to use zero-shot classification only if you don’t have enough labeled data.
