- Introduced by
- Yin, Hay & Roth
- Year
- 2019
- Type
- NLP text-classification task
What does it do?
Zero-shot classification is a natural-language processing task that assigns text to categories described in plain language, without any labelled training examples.
Yin, Hay and Roth (2019) framed it as an entailment problem, in which a pretrained language model judges whether a text supports each category name treated as a hypothesis.
The intuition behind the method
A standard classifier must see labelled examples of each category before it can recognise that category. Zero-shot classification skips this step. You supply the category names as ordinary words, such as politics, sports or science, and a pretrained language model scores how well each name fits the text. Because the model's language knowledge comes from pretraining rather than from your data, a category can be added or renamed by editing the candidate list, without collecting and labelling new examples.
History
Yin, Hay and Roth (2019) benchmarked zero-shot text classification and framed it as an entailment problem, in which each candidate label is treated as a hypothesis to be checked against the text. Brown et al. (2020) reported on large language models performing tasks with few or no task-specific examples, a line of work that is related to, but distinct from, the entailment-based approach.
When to use it
Choose zero-shot classification when you have text to categorise, no labelled examples for the target categories, and a category set that may change or grow. It requires access to a large pretrained model with entailment-style scoring, and it requires candidate labels that can be stated clearly. It is a reasonable choice for early prototyping and for settings where labelling examples for every class is impractical. Do not choose it when a substantial labelled dataset already exists for your categories, because a supervised classifier trained on that data can be expected to fit your categories more closely.
Limitations and considerations
- The method depends on a large pretrained model, and running it carries the computational cost of that model at scoring time.
- Because nothing is fitted to your corpus, the scores cannot be calibrated to your category frequencies or to the wording conventions of your documents.
- Results depend on how clearly the candidate labels are worded; a label that is ambiguous in the model's language will be scored ambiguously.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- No labelled training data is needed: categories are described in plain language and matched by the pretrained model.
- New categories can be added by extending the candidate-label list, with no retraining step.
- The scoring uses the language knowledge already encoded in a large pretrained model, so the procedure does not start from scratch on your corpus.
Applications
- Categorising documents into label sets that change often, without retraining a model.
- Rapid prototyping of a classification scheme before any labelled data has been collected.
- Tagging incoming text, such as topics or intents, from category names alone.
- Exploring categories in a corpus where the label set is not yet settled.
How it works
How it works
You describe the target categories as natural-language candidate labels: short phrases the model can read directly. Each label should be worded clearly. For single-label assignment the labels should also be mutually exclusive, because the final decision picks one winner; for multi-label use, overlap is acceptable, since each label is judged on its own.
Each candidate label is first inserted into a short hypothesis sentence, for example 'This text is about {label}'. The text and these hypothesis sentences are then passed to a large pretrained language model, such as a BART- or RoBERTa-based model. Nothing is fitted on your own data at this stage. The model represents the text and each hypothesis using knowledge acquired during pretraining. The wording of the hypothesis template can change the scores, so choose it deliberately and report it with your results.
Each candidate label is scored by treating the task as natural-language inference: the text is checked for whether it supports the hypothesis that it belongs to that label. Each label is checked against the text separately, and the resulting scores are then used according to the assignment rule described below.
In single-label use, the label with the highest score is assigned to the text. In multi-label use, the labels whose scores meet the decision threshold you set are assigned, and the result is a ranked set rather than one category. Choose the threshold on a small sample of your own texts that you have checked by hand, because raw entailment scores are not calibrated probabilities. Adding a new category requires only adding its name to the candidate list.
Common pitfalls
- Vague or overlapping labels, in a single-label setting, lead to a winner chosen between labels that the model cannot separate. Define each label precisely and keep single-label sets mutually exclusive.
- Expecting zero-shot accuracy to match a supervised classifier when a large labelled dataset is available. In that case a supervised model is the better choice.
- Using a small or general-purpose language model that has not been trained for entailment-style scoring weakens the comparison between the text and each label.
- Writing labels in a language or register the pretrained model handles poorly lowers the reliability of the scores.
- Reading raw entailment scores as calibrated probabilities, or setting a multi-label threshold without checking it on a sample of your own texts.
Frequently asked questions
Does zero-shot classification need any training data?
No labelled examples are needed for your categories. Categories are described as natural-language candidate labels, and a pretrained model scores how well each label fits the text. The pretrained model itself was built from other training data, so the method is zero-shot only with respect to your categories.
Which model does it rely on?
It relies on a large pretrained language model, such as a BART- or RoBERTa-based model with entailment-style scoring. Results depend on using a capable model of this kind rather than a small general-purpose one.
How should I write the candidate labels?
State each label clearly. For single-label assignment, keep the labels mutually exclusive, since the highest-scoring label is chosen. Vague or overlapping labels make the decision harder for the model.
Is it as accurate as a supervised classifier?
Not necessarily. When a large labelled dataset exists, a supervised classifier trained on it is usually the better choice. Zero-shot classification is most useful when labelled data is scarce or the category set keeps changing.
Related methods
Sources
Yin, W., Hay, J. & Roth, D. (2019). Benchmarking Zero-shot Text Classification: Datasets, Evaluation and Entailment Approach. EMNLP, 3914-3923.
Open DOI referenceBrown, T. et al. (2020). Language Models are Few-Shot Learners. NeurIPS.
Open publication reference