Model Overview
Model Features
Model Capabilities
Use Cases
đ deberta-v3-base-zeroshot-v1.1-all-33
This model is designed for zero-shot classification with the Hugging Face pipeline, offering a universal solution for text classification tasks.
đ Quick Start
The model is designed for zero-shot classification with the Hugging Face pipeline. It can perform a universal classification task: determining whether a hypothesis is "true" or "not true" given a text (entailment
vs. not_entailment
). This task format is based on the Natural Language Inference task (NLI), and any classification task can be reformulated into this task.
A detailed description of how the model was trained and how it can be used is available in this paper.
⨠Features
- Universal Classification: Can handle any classification task by reformulating it into the NLI-based task.
- English Data Training: Trained solely on English data, suitable for English text classification. For multilingual use, machine translation to English is recommended.
- Two-Class Prediction: Predicts two classes (
entailment
vs.not_entailment
) instead of the typical three classes (entailment/neutral/contradiction) in NLI models.
đĻ Installation
To use this model, you need to install the transformers
library with sentencepiece
. You can run the following command:
pip install transformers[sentencepiece]
đģ Usage Examples
Basic Usage
#!pip install transformers[sentencepiece]
from transformers import pipeline
text = "Angela Merkel is a politician in Germany and leader of the CDU"
hypothesis_template = "This example is about {}"
classes_verbalized = ["politics", "economy", "entertainment", "environment"]
zeroshot_classifier = pipeline("zero-shot-classification", model="MoritzLaurer/deberta-v3-base-zeroshot-v1.1-all-33")
output = zeroshot_classifier(text, classes_verbalized, hypothesis_template=hypothesis_template, multi_label=False)
print(output)
Advanced Usage
You can formulate your own hypotheses by changing the hypothesis_template
of the zeroshot pipeline. For example:
from transformers import pipeline
text = "Angela Merkel is a politician in Germany and leader of the CDU"
hypothesis_template = "Merkel is the leader of the party: {}"
classes_verbalized = ["CDU", "SPD", "Greens"]
zeroshot_classifier = pipeline("zero-shot-classification", model="MoritzLaurer/deberta-v3-base-zeroshot-v1.1-all-33")
output = zeroshot_classifier(text, classes_verbalized, hypothesis_template=hypothesis_template, multi_label=False)
print(output)
đ Documentation
Training data
The model was trained on a mixture of 33 datasets and 387 classes that have been reformatted into this universal format.
- Five NLI datasets with ~885k texts: "mnli", "anli", "fever", "wanli", "ling"
- 28 classification tasks reformatted into the universal NLI format. ~51k cleaned texts were used to avoid overfitting: 'amazonpolarity', 'imdb', 'appreviews', 'yelpreviews', 'rottentomatoes', 'emotiondair', 'emocontext', 'empathetic', 'financialphrasebank', 'banking77', 'massive', 'wikitoxic_toxicaggregated', 'wikitoxic_obscene', 'wikitoxic_threat', 'wikitoxic_insult', 'wikitoxic_identityhate', 'hateoffensive', 'hatexplain', 'biasframes_offensive', 'biasframes_sex', 'biasframes_intent', 'agnews', 'yahootopics', 'trueteacher', 'spam', 'wellformedquery', 'manifesto', 'capsotu'.
See details on each dataset here: https://github.com/MoritzLaurer/zeroshot-classifier/blob/main/datasets_overview.csv
Details on data and training
The code for preparing the data and training & evaluating the model is fully open-source here: https://github.com/MoritzLaurer/zeroshot-classifier/tree/main
Hyperparameters and other details are available in this Weights & Biases repo: https://wandb.ai/moritzlaurer/deberta-v3-base-zeroshot-v1-1-all-33/table?workspace=user-
Metrics
Balanced accuracy is reported for all datasets.
deberta-v3-base-zeroshot-v1.1-all-33
was trained on all datasets, with only maximum 500 texts per class to avoid overfitting.
The metrics on these datasets are therefore not strictly zeroshot, as the model has seen some data for each task during training.
deberta-v3-base-zeroshot-v1.1-heldout
indicates zeroshot performance on the respective dataset.
To calculate these zeroshot metrics, the pipeline was run 28 times, each time with one dataset held out from training to simulate a zeroshot setup.
Property | Details |
---|---|
Model Type | A model for zero-shot classification using the Hugging Face pipeline |
Training Data | Trained on a mixture of 33 datasets and 387 classes reformatted into the universal NLI format. Five NLI datasets with ~885k texts and 28 classification tasks with ~51k cleaned texts. |
deberta-v3-base-mnli-fever-anli-ling-wanli-binary | deberta-v3-base-zeroshot-v1.1-heldout | deberta-v3-base-zeroshot-v1.1-all-33 | |
---|---|---|---|
datasets mean (w/o nli) | 62 | 70.7 | 84 |
amazonpolarity (2) | 91.7 | 95.7 | 96 |
imdb (2) | 87.3 | 93.6 | 94.5 |
appreviews (2) | 91.3 | 92.2 | 94.4 |
yelpreviews (2) | 95.1 | 97.4 | 98.3 |
rottentomatoes (2) | 83 | 88.7 | 90.8 |
emotiondair (6) | 46.5 | 42.6 | 74.5 |
emocontext (4) | 58.5 | 57.4 | 81.2 |
empathetic (32) | 31.3 | 37.3 | 52.7 |
financialphrasebank (3) | 78.3 | 68.9 | 91.2 |
banking77 (72) | 18.9 | 46 | 73.7 |
massive (59) | 44 | 56.6 | 78.9 |
wikitoxic_toxicaggreg (2) | 73.7 | 82.5 | 90.5 |
wikitoxic_obscene (2) | 77.3 | 91.6 | 92.6 |
wikitoxic_threat (2) | 83.5 | 95.2 | 96.7 |
wikitoxic_insult (2) | 79.6 | 91 | 91.6 |
wikitoxic_identityhate (2) | 83.9 | 88 | 94.4 |
hateoffensive (3) | 55.2 | 66.1 | 86 |
hatexplain (3) | 44.1 | 57.6 | 76.9 |
biasframes_offensive (2) | 56.8 | 85.4 | 87 |
biasframes_sex (2) | 85.4 | 87 | 91.8 |
biasframes_intent (2) | 56.3 | 85.2 | 87.8 |
agnews (4) | 77.3 | 80 | 90.5 |
yahootopics (10) | 53.6 | 57.7 | 72.8 |
trueteacher (2) | 51.4 | 49.5 | 82.4 |
spam (2) | 51.8 | 50 | 97.2 |
wellformedquery (2) | 49.9 | 52.5 | 77.2 |
manifesto (56) | 5.8 | 18.9 | 39.1 |
capsotu (21) | 25.2 | 64 | 72.5 |
mnli_m (2) | 92.4 | nan | 92.7 |
mnli_mm (2) | 92.4 | nan | 92.5 |
fevernli (2) | 89 | nan | 89.1 |
anli_r1 (2) | 79.4 | nan | 80 |
anli_r2 (2) | 68.4 | nan | 68.4 |
anli_r3 (2) | 66.2 | nan | 68 |
wanli (2) | 81.6 | nan | 81.8 |
lingnli (2) | 88.4 | nan | 88.4 |
Limitations and bias
The model can only do text classification tasks.
Please consult the original DeBERTa paper and the papers for the different datasets for potential biases.
Hypotheses used for classification
The hypotheses in the tables below were used to fine-tune the model.
Inspecting them can help users get a feeling for which type of hypotheses and tasks the model was trained on.
You can formulate your own hypotheses by changing the hypothesis_template
of the zeroshot pipeline.
đ§ Technical Details
The model's training and usage details are based on the Natural Language Inference task (NLI). It was trained on a large and diverse set of datasets to ensure its generalization ability. The code for data preparation, training, and evaluation is open-source, and hyperparameters can be found in the Weights & Biases repo.
đ License
The base model (DeBERTa-v3) is published under the MIT license. The datasets the model was fine-tuned on are published under a diverse set of licenses. The following table provides an overview of the non-NLI datasets used for fine-tuning, information on licenses, the underlying papers etc.: https://github.com/MoritzLaurer/zeroshot-classifier/blob/main/datasets_overview.csv
đ Citation
If you use this model academically, please cite:
@misc{laurer_building_2023,
title = {Building {Efficient} {Universal} {Classifiers} with {Natural} {Language} {Inference}},
url = {http://arxiv.org/abs/2312.17543},
doi = {10.48550/arXiv.2312.17543},
abstract = {Generative Large Language Models (LLMs) have become the mainstream choice for fewshot and zeroshot learning thanks to the universality of text generation. Many users, however, do not need the broad capabilities of generative LLMs when they only want to automate a classification task. Smaller BERT-like models can also learn universal tasks, which allow them to do any text classification task without requiring fine-tuning (zeroshot classification) or to learn new tasks with only a few examples (fewshot), while being significantly more efficient than generative LLMs. This paper (1) explains how Natural Language Inference (NLI) can be used as a universal classification task that follows similar principles as instruction fine-tuning of generative LLMs, (2) provides a step-by-step guide with reusable Jupyter notebooks for building a universal classifier, and (3) shares the resulting universal classifier that is trained on 33 datasets with 389 diverse classes. Parts of the code we share has been used to train our older zeroshot classifiers that have been downloaded more than 55 million times via the Hugging Face Hub as of December 2023. Our new classifier improves zeroshot performance by 9.4\%.},
urldate = {2024-01-05},
publisher = {arXiv},
author = {Laurer, Moritz and van Atteveldt, Wouter and Casas, Andreu and Welbers, Kasper},
month = dec,
year = {2023},
note = {arXiv:2312.17543 [cs]},
keywords = {Computer Science - Artificial Intelligence, Computer Science - Computation and Language},
}
đĄ Usage Tip
If you have questions or ideas for cooperation, contact me at m{dot}laurer{at}vu{dot}nl or LinkedIn
â ī¸ Important Note
Note that DeBERTa-v3 was released on 06.12.21 and older versions of HF Transformers can have issues running the model (e.g. resulting in an issue with the tokenizer). Using Transformers>=4.13 might solve some issues.
Also make sure to install sentencepiece to avoid tokenizer errors. Run: pip install transformers[sentencepiece]
or pip install sentencepiece






