# How to select labels for multilabel zero-shot text classification

**URL:** <https://discuss.huggingface.co/t/how-to-select-labels-for-multilabel-zero-shot-text-classification/8756>\
**Category:** Beginners\
**Created:** [July 28, 2021, 10:30am UTC](https://discuss.huggingface.co/t/how-to-select-labels-for-multilabel-zero-shot-text-classification/8756 "2021-07-28T10:30:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Krzysztof](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/krzysztof/32/2318_2.png) [@Krzysztof](https://discuss.huggingface.co/u/Krzysztof)\
**Post date:** [July 28, 2021, 10:30am UTC](https://discuss.huggingface.co/t/how-to-select-labels-for-multilabel-zero-shot-text-classification/8756/1 "2021-07-28T10:30:00Z")

</div>

Hi, I am using transformers pipeline for zero-shot classification on a large set of more than 1m student reviews of courses conducted in the US and the UK. Example of one review is below:  
“Very nice woman, extremely helpful if you go to her office hours, but scheme is a stupid language which makes this class boring and difficult. Very tough exams. Do good on your labs and projects and you’ll be okay.”  
I read that choosing proper labels for zero-shot classification, with many domain-specific words, is key. Can you suggest general rules how to create such labels, they should be long or short, single domain specific words or complex sentences. For example there could be such approaches as:  
1.  
candidate\_labels = [“teaching skills”, “interpersonal skills”, “grading fairness”]  
or  
2.  
candidate\_labels = [“teacher or professor teaching skills”, “teacher or professor interpersonal skills”, “course grading fairness”]  
3.  
candidate\_labels = [“teacher or professor good or bad teaching skills”, “teacher or professor good or bad interpersonal skills”, “course grading fair or unfair”]  
I do not have a labelled test set to compare the accuracy, and I would like to avoid labeling a test set, as it is tedious.  
Any suggestions? Maybe there are some papers that deal with this problem?

---

<div class="post-metadata">

**Author:** ![tsleolima](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/tsleolima/32/5317_2.png) [@tsleolima](https://discuss.huggingface.co/u/tsleolima)\
**Post date:** [July 10, 2022, 5:51pm UTC](https://discuss.huggingface.co/t/how-to-select-labels-for-multilabel-zero-shot-text-classification/8756/2 "2022-07-10T17:51:59Z")

</div>

Hello, did you find out how the condadidate labels work?

---

<div class="post-metadata">

**Author:** ![jgcoke](https://avatars.discourse-cdn.com/v4/letter/j/91b2a8/32.png) [@jgcoke](https://discuss.huggingface.co/u/jgcoke)\
**Post date:** [November 21, 2022, 5:11pm UTC](https://discuss.huggingface.co/t/how-to-select-labels-for-multilabel-zero-shot-text-classification/8756/3 "2022-11-21T17:11:14Z")

</div>

Does anyone have a few basic guidelines to get the labels? I think the main point to improve zero-shot learning is to select good labels, but I didn’t find any resource that addresses this problem.  
I was thinking of measuring the distance between the label embeddings and trying to change the wording to maximize it, which could help to improve the accuracy.

---

<div class="post-metadata">

**Author:** ![mabu](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mabu/32/4596_2.png) [@mabu](https://discuss.huggingface.co/u/mabu)\
**Post date:** [November 21, 2022, 6:13pm UTC](https://discuss.huggingface.co/t/how-to-select-labels-for-multilabel-zero-shot-text-classification/8756/4 "2022-11-21T18:13:47Z")

</div>

Hi, probably not the answer you’re looking for but [SetFit](https://github.com/huggingface/setfit) is a great alternative to the zero-shot pipeline. It can work without labelling data at all, or label as little as 8 examples. This helps with label calibration, although it doesn’t completely avoid label engineering, it does improve model performance. Checkout a training example [here](https://github.com/huggingface/setfit/blob/main/notebooks/zero-shot-classification.ipynb), which also compares to the zero-shot pipeline.

Alternatively, you may wanna settle for some labels and then compare models. I have found for example that `roberta-large-mnli` worked a lot better than the default `bart-large-mnli` on the same labels.

---

<div class="post-metadata">

**Author:** ![miOmiO](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@miOmiO](https://discuss.huggingface.co/u/miOmiO)\
**Post date:** [November 23, 2022, 9:00pm UTC](https://discuss.huggingface.co/t/how-to-select-labels-for-multilabel-zero-shot-text-classification/8756/5 "2022-11-23T21:00:28Z")

</div>

Hi @mabu,

```
I tried to use setfit to perform zero shot clasiification following this link: 

```

[setfit/zero-shot-classification.ipynb at main · huggingface/setfit (github.com)](https://github.com/huggingface/setfit/blob/main/notebooks/zero-shot-classification.ipynb), however the example uses hold-out dataset for evaluation, my case requires to output inference with non-labeled data, currently I have trainer readay :

from setfit import SetFitModel, SetFitTrainer

model = SetFitModel.from\_pretrained(“sentence-transformers/paraphrase-mpnet-base-v2”)  
trainer = SetFitTrainer(  
model=model,  
train\_dataset=train\_dataset  
)  
trainer.train()

Can I directly use trainer for inference? Instead of pushing it to HF hub and reload the model from hub. If yes, could you give me example what next step is? Thank you!

---

<div class="post-metadata">

**Author:** ![mabu](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mabu/32/4596_2.png) [@mabu](https://discuss.huggingface.co/u/mabu)\
**Post date:** [November 24, 2022, 2:19pm UTC](https://discuss.huggingface.co/t/how-to-select-labels-for-multilabel-zero-shot-text-classification/8756/6 "2022-11-24T14:19:39Z")

</div>

@miOmiO yes!

You can do it in a couple of ways.  
Via ` __call__ `: `trainer.model([sequence_to_classify])`  
Via `predict`: `trainer.predict([sequence_to_classify])`  
And I think this is also possible: `trainer.model.predict_proba([sequence_to_classify])`

---

<div class="post-metadata">

**Author:** ![miOmiO](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@miOmiO](https://discuss.huggingface.co/u/miOmiO)\
**Post date:** [November 28, 2022, 5:03pm UTC](https://discuss.huggingface.co/t/how-to-select-labels-for-multilabel-zero-shot-text-classification/8756/7 "2022-11-28T17:03:46Z")

</div>

Thank you so much, just try and it works. @mabu
