# Fine tune Zero-shot classification on multi-label dataset

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffine-tune-zero-shot-classification-on-multi-label-dataset%2F63736%3E%5C
**Category:** Models\
**Created:** [November 27, 2023, 4:16pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffine-tune-zero-shot-classification-on-multi-label-dataset%2F63736 "2023-11-27T16:16:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ltrovato](https://avatars.discourse-cdn.com/v4/letter/l/f07891/32.png) [@ltrovato](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fltrovato)%5C
**Post date:** [November 27, 2023, 4:16pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffine-tune-zero-shot-classification-on-multi-label-dataset%2F63736%2F1 "2023-11-27T16:16:58Z")

</div>

Hi all,  
I started a small project where I am trying to fine-tune a zero-shot classification model on a proprietary dataset. I was thinking to use the NLI approach, building contradiction and entailment statements for each of my sentences/labels pairs.

I have a dataset with sentences and for each of them multiple true labels.

However, I am not sure on what is the best way to approach this, given that in literature I have only seen the case where there is only one label per sentence.

Making one example:

Sentence 1. Classes = [‘A’,‘B’,‘C’]

Should I build my dataset generating three different samples

Sentence 1. This is about ‘A’ + Entailment label  
Sentence 1. This is about ‘B’ + Entailment label  
Sentence 1. This is about ‘C’ + Entailment label

or generating only one as follows:

Sentence 1. This is about A, B, C. + Entailment label

I am happy to hear any other ideas on this.

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![panigrah](https://avatars.discourse-cdn.com/v4/letter/p/bb73d2/32.png) [@panigrah](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fpanigrah)%5C
**Post date:** [November 28, 2023, 9:53am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffine-tune-zero-shot-classification-on-multi-label-dataset%2F63736%2F2 "2023-11-28T09:53:51Z")

</div>

Here is one approach depending on the number of labels you have

> <https://github.com/NielsRogge/Transformers-Tutorials/blob/master/BERT/Fine_tuning_BERT_(and_friends)_for_multi_label_text_classification.ipynb>

---

<div class="post-metadata">

**Author:** ![ltrovato](https://avatars.discourse-cdn.com/v4/letter/l/f07891/32.png) [@ltrovato](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fltrovato)%5C
**Post date:** [November 28, 2023, 12:10pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffine-tune-zero-shot-classification-on-multi-label-dataset%2F63736%2F3 "2023-11-28T12:10:57Z")

</div>

Hi,  
thanks for pointing to this resource, but this is useful only for a classic multi-label classification problem.

I am looking into fine-tuning of a zero-shot classification model using the entailment-contradiction approach.

---

<div class="post-metadata">

**Author:** ![panigrah](https://avatars.discourse-cdn.com/v4/letter/p/bb73d2/32.png) [@panigrah](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fpanigrah)%5C
**Post date:** [November 28, 2023, 12:44pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffine-tune-zero-shot-classification-on-multi-label-dataset%2F63736%2F4 "2023-11-28T12:44:46Z")

</div>

Am curious why you wouldn’t treat it as a multi classification problem? Is there a reason it needs to be NLI. Will help me learn! Thanks

---

<div class="post-metadata">

**Author:** ![panigrah](https://avatars.discourse-cdn.com/v4/letter/p/bb73d2/32.png) [@panigrah](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fpanigrah)%5C
**Post date:** [November 30, 2023, 2:32pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffine-tune-zero-shot-classification-on-multi-label-dataset%2F63736%2F5 "2023-11-30T14:32:13Z")

</div>

According to this here

> [@New pipeline for zero-shot text classification](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fnew-pipeline-for-zero-shot-text-classification%2F681%2F15)%3A
>
> Thanks for the helpful answer, @rsk97. Let me just add a bit: I discuss this briefly in my blog post under Classification as Natural Language Inference -\> When Some Annotated Data is Available. In short, if you have a limited amount of labeled data, you can further fine-tune the pre-trained NLI model. Pass the true label for a given sequence in the same way as you would during inference, e.g. \<cls\> Who are you voting for in 2020 ? \<sep\> This text is about politics . \<sep\>, and calculate the l…

The recommend approach is what you are suggesting in option 1. Basically present each of your multiple labels as entailments separately, but the author also suggests presenting an equal number of contradictions.
