๐ DeBERTa-v3-xsmall-mnli-fever-anli-ling-binary
A model trained on multiple NLI datasets for zero - shot text classification, based on the DeBERTa - v3 architecture.
๐ Quick Start
This model is designed for zero - shot classification tasks. It was trained on binary NLI to predict either "entailment" or "not - entailment". For highest performance (but less speed), I recommend using https://huggingface.co/MoritzLaurer/DeBERTa - v3 - large - mnli - fever - anli - ling - wanli.
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
model_name = "MoritzLaurer/DeBERTa-v3-xsmall-mnli-fever-anli-ling-binary"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
premise = "I first thought that I liked the movie, but upon second thought it was actually disappointing."
hypothesis = "The movie was good."
input = tokenizer(premise, hypothesis, truncation=True, return_tensors="pt")
output = model(input["input_ids"].to(device))
prediction = torch.softmax(output["logits"][0], -1).tolist()
label_names = ["entailment", "not_entailment"]
prediction = {name: round(float(pred) * 100, 1) for pred, name in zip(prediction, label_names)}
print(prediction)
โจ Features
- Trained on 782 357 hypothesis - premise pairs from 4 NLI datasets: MultiNLI, [Fever - NLI](https://github.com/easonnie/combine - FEVER - NSMN/blob/master/other_resources/nli_fever.md), LingNLI and ANLI.
- Specifically designed for zero - shot classification, predicting binary NLI results.
- Based on the DeBERTa - v3 architecture, which substantially outperforms previous versions by including a different pre - training objective.
๐ฆ Installation
No specific installation steps are provided in the original document.
๐ป Usage Examples
Basic Usage
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
model_name = "MoritzLaurer/DeBERTa-v3-xsmall-mnli-fever-anli-ling-binary"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
premise = "I first thought that I liked the movie, but upon second thought it was actually disappointing."
hypothesis = "The movie was good."
input = tokenizer(premise, hypothesis, truncation=True, return_tensors="pt")
output = model(input["input_ids"].to(device))
prediction = torch.softmax(output["logits"][0], -1).tolist()
label_names = ["entailment", "not_entailment"]
prediction = {name: round(float(pred) * 100, 1) for pred, name in zip(prediction, label_names)}
print(prediction)
๐ Documentation
Training data
This model was trained on 782 357 hypothesis - premise pairs from 4 NLI datasets: MultiNLI, [Fever - NLI](https://github.com/easonnie/combine - FEVER - NSMN/blob/master/other_resources/nli_fever.md), LingNLI and ANLI.
Training procedure
DeBERTa - v3 - xsmall - mnli - fever - anli - ling - binary was trained using the Hugging Face trainer with the following hyperparameters.
training_args = TrainingArguments(
num_train_epochs=5, # total number of training epochs
learning_rate=2e-05,
per_device_train_batch_size=32, # batch size per device during training
per_device_eval_batch_size=32, # batch size for evaluation
warmup_ratio=0.1, # number of warmup steps for learning rate scheduler
weight_decay=0.06, # strength of weight decay
fp16=True # mixed precision training
)
Eval results
The model was evaluated using the binary test sets for MultiNLI, ANLI, LingNLI and the binary dev set for Fever - NLI (two classes instead of three). The metric used is accuracy.
Property |
mnli - m - 2c |
mnli - mm - 2c |
fever - nli - 2c |
anli - all - 2c |
anli - r3 - 2c |
lingnli - 2c |
Accuracy |
0.925 |
0.922 |
0.892 |
0.676 |
0.665 |
0.888 |
Speed (text/sec, CPU, 128 batch) |
6.0 |
6.3 |
3.0 |
5.8 |
5.0 |
7.6 |
Speed (text/sec, GPU Tesla P100, 128 batch) |
473 |
487 |
230 |
390 |
340 |
586 |
๐ง Technical Details
The base model is [DeBERTa - v3 - xsmall from Microsoft](https://huggingface.co/microsoft/deberta - v3 - xsmall). The v3 variant of DeBERTa substantially outperforms previous versions of the model by including a different pre - training objective, see the DeBERTa - V3 paper.
๐ License
This model is licensed under the MIT license.
Limitations and bias
Please consult the original DeBERTa paper and literature on different NLI datasets for potential biases.
Citation
If you use this model, please cite: Laurer, Moritz, Wouter van Atteveldt, Andreu Salleras Casas, and Kasper Welbers. 2022. โLess Annotating, More Classifying โ Addressing the Data Scarcity Issue of Supervised Machine Learning with Deep Transfer Learning and BERT - NLIโ. Preprint, June. Open Science Framework. https://osf.io/74b8k.
Ideas for cooperation or questions?
If you have questions or ideas for cooperation, contact me at m{dot}laurer{at}vu{dot}nl or [LinkedIn](https://www.linkedin.com/in/moritz - laurer/)
Debugging and issues
โ ๏ธ Important Note
DeBERTa - v3 was released on 06.12.21 and older versions of HF Transformers seem to have issues running the model (e.g. resulting in an issue with the tokenizer). Using Transformers>=4.13 might solve some issues.