mDeBERTa v3 base xnli multilingual nli 2mil7
Overview
Highlights
- High-performance cross-lingual natural language inference
- Optimized DeBERTa-v3 architecture for better logical reasoning
- Ideal for zero-shot text classification across languages
- Efficient base-model size for low-latency production deployment
- Permissive MIT license for commercial integration
Usage
# Install Hugging Face transformers
pip install transformers torch
# Load model with transformers
from transformers import AutoModel, AutoTokenizer
model = AutoModel.from_pretrained("MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7")
tokenizer = AutoTokenizer.from_pretrained("MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7")
Hugging Face Download
We recommend downloading the model via the Hugging Face CLI or Hub SDK.
Guidance:Before downloading, install huggingface_hub with:
pip install -U huggingface_hub
CLI Download
Download the full repository
huggingface-cli download MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7
Download a single file to a local folder (e.g. config.json into ./dir)
huggingface-cli download MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7 config.json --local-dir ./dir
See the official docs for more CLI options
SDK Download
# 模型下载
from huggingface_hub import snapshot_download
model_dir = snapshot_download('MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7')
Git Download
Make sure git-lfs is installed first
git lfs install
git clone https://huggingface.co/MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7
To skip LFS large-file downloads, use:
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7
Model files are hosted on the Hugging Face Hub — download directly via HF CLI / SDK / Git, not through this site.
PyTorch / Transformers Usage
Install Transformers
pip install -U transformers torch
Load the model and run inference
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained('MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7')
tokenizer = AutoTokenizer.from_pretrained('MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7')
Full Documentation
---
language:
- multilingual
- zh
- ja
- ar
- ko
- de
- fr
- es
- pt
- hi
- id
- it
- tr
- ru
- bn
- ur
- mr
- ta
- vi
- fa
- pl
- uk
- nl
- sv
- he
- sw
- ps
license: mit
tags:
- zero-shot-classification
- text-classification
- nli
- pytorch
datasets:
- MoritzLaurer/multilingual-NLI-26lang-2mil7
- xnli
- multi_nli
- facebook/anli
- fever
- lingnli
- alisawuffles/WANLI
metrics:
- accuracy
pipeline_tag: zero-shot-classification
widget:
- text: Angela Merkel ist eine Politikerin in Deutschland und Vorsitzende der CDU
candidate_labels: politics, economy, entertainment, environment
model-index:
- name: DeBERTa-v3-base-xnli-multilingual-nli-2mil7
results:
- task:
type: text-classification
name: Natural Language Inference
dataset:
name: MultiNLI-matched
type: multi_nli
split: validation_matched
metrics:
- type: accuracy
value: 0,857
verified: false
- task:
type: text-classification
name: Natural Language Inference
dataset:
name: MultiNLI-mismatched
type: multi_nli
split: validation_mismatched
metrics:
- type: accuracy
value: 0,856
verified: false
- task:
type: text-classification
name: Natural Language Inference
dataset:
name: ANLI-all
type: anli
split: test_r1+test_r2+test_r3
metrics:
- type: accuracy
value: 0,537
verified: false
- task:
type: text-classification
name: Natural Language Inference
dataset:
name: ANLI-r3
type: anli
split: test_r3
metrics:
- type: accuracy
value: 0,497
verified: false
- task:
type: text-classification
name: Natural Language Inference
dataset:
name: WANLI
type: alisawuffles/WANLI
split: test
metrics:
- type: accuracy
value: 0,732
verified: false
- task:
type: text-classification
name: Natural Language Inference
dataset:
name: LingNLI
type: lingnli
split: test
metrics:
- type: accuracy
value: 0,788
verified: false
- task:
type: text-classification
name: Natural Language Inference
dataset:
name: fever-nli
type: fever-nli
split: test
metrics:
- type: accuracy
value: 0,761
verified: false
---
Model card for mDeBERTa-v3-base-xnli-multilingual-nli-2mil7
Model description
This multilingual model can perform natural language inference (NLI) on 100 languages and is therefore also suitable for multilingual zero-shot classification. The underlying mDeBERTa-v3-base model was pre-trained by Microsoft on the CC100 multilingual dataset with 100 languages. The model was then fine-tuned on the XNLI dataset and on the multilingual-NLI-26lang-2mil7 dataset. Both datasets contain more than 2.7 million hypothesis-premise pairs in 27 languages spoken by more than 4 billion people.
As of December 2021, mDeBERTa-v3-base is the best performing multilingual base-sized transformer model introduced by Microsoft in this paper.
How to use the model
#### Simple zero-shot classification pipelinefrom transformers import pipeline
classifier = pipeline("zero-shot-classification", model="MoritzLaurer/mDeBERTa-v3-base-mnli-xnli")
sequence_to_classify = "Angela Merkel ist eine Politikerin in Deutschland und Vorsitzende der CDU"
candidate_labels = ["politics", "economy", "entertainment", "environment"]
output = classifier(sequence_to_classify, candidate_labels, multi_label=False)
print(output)from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
model_name = "MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
premise = "Angela Merkel ist eine Politikerin in Deutschland und Vorsitzende der CDU"
hypothesis = "Emmanuel Macron is the President of France"
input = tokenizer(premise, hypothesis, truncation=True, return_tensors="pt")
output = model(input["input_ids"].to(device)) # device = "cuda:0" or "cpu"
prediction = torch.softmax(output["logits"][0], -1).tolist()
label_names = ["entailment", "neutral", "contradiction"]
prediction = {name: round(float(pred) * 100, 1) for pred, name in zip(prediction, label_names)}
print(prediction)
Training data
This model was trained on the multilingual-nli-26lang-2mil7 dataset and the XNLI validation dataset.The multilingual-nli-26lang-2mil7 dataset contains 2 730 000 NLI hypothesis-premise pairs in 26 languages spoken by more than 4 billion people. The dataset contains 105 000 text pairs per language. It is based on the English datasets MultiNLI, Fever-NLI, ANLI, LingNLI and WANLI and was created using the latest open-source machine translation models. The languages in the dataset are: ['ar', 'bn', 'de', 'es', 'fa', 'fr', 'he', 'hi', 'id', 'it', 'ja', 'ko', 'mr', 'nl', 'pl', 'ps', 'pt', 'ru', 'sv', 'sw', 'ta', 'tr', 'uk', 'ur', 'vi', 'zh'] (see ISO language codes. For more details, see the datasheet. In addition, a sample of 105 000 text pairs was also added for English following the same sampling method as the other languages, leading to 27 languages.
Moreover, for each language a random set of 10% of the hypothesis-premise pairs was added where an English hypothesis was paired with the premise in the other language (and the same for English premises and other language hypotheses). This mix of languages in the text pairs should enable users to formulate a hypothesis in English for a target text in another language.
The XNLI validation set consists of 2490 professionally translated texts from English to 14 other languages (37350 texts in total) (see this paper). Note that XNLI also contains a training set of 14 machine translated versions of the MultiNLI dataset for 14 languages, but this data was excluded due to quality issues with the machine translations from 2018.
Note that for evaluation purposes, three languages were excluded from the XNLI training data and only included in the test data: ["bg","el","th"]. This was done in order to test the performance of the model on languages it has not seen during NLI fine-tuning on 27 languages, but only during pre-training on 100 languages - see evaluation metrics below.
The total training dataset had a size of 3 287 280 hypothesis-premise pairs.
Training procedure
mDeBERTa-v3-base-mnli-xnli was trained using the Hugging Face trainer with the following hyperparameters.training_args = TrainingArguments(
num_train_epochs=3, # total number of training epochs
learning_rate=2e-05,
per_device_train_batch_size=32, # batch size per device during training
gradient_accumulation_steps=2, # to double the effective batch size for
warmup_ratio=0.06, # number of warmup steps for learning rate scheduler
weight_decay=0.01, # strength of weight decay
fp16=False
)