SAVRN
Search Contact SAVRN

Open-weight model · Zero-shot classification

multilingual-MiniLMv2-L6-mnli-xnli

by Moritz Borrett-Laurer (formerly Laurer) MoritzLaurer/multilingual-MiniLMv2-L6-mnli-xnli

multilingual - zero-shot-classification - text-classification - nli - pytorch - accuracy - multinli - xnli pipelinetag: zero-shot-classification candidatelabels: "politics, economy, entertainment, environment" This multilingual model can perform natural…

Parameters107M
Context514
Weights1.3 GB
Licensemit
AccessOpen weights
Monthly Downloads15.4k

Runs On

What it takes to serve multilingual-MiniLMv2-L6-mnli-xnli (107M parameters): the memory its weights need at each precision, and the cheapest way to rent enough data-center GPUs to hold them.

PrecisionWeightsMemory neededCheapest setupPer hourAlso fits
16-bit 0.2 GB 0.3 GB 1x MI300X (192 GB)
Vultr
$1.85 1x H100 $1.99 · 1x MI325X $2.00
8-bit 0.1 GB 0.1 GB 1x MI300X (192 GB)
Vultr
$1.85 1x H100 $1.99 · 1x MI325X $2.00
4-bit 0.1 GB 0.1 GB 1x MI300X (192 GB)
Vultr
$1.85 1x H100 $1.99 · 1x MI325X $2.00

Memory is the weights at that precision plus 20% for the runtime and a short context; a long context needs more. Prices are the lowest on-demand hourly rates in the SAVRN Index, read Sep 18, 2026.

Model Card

By Moritz Borrett-Laurer (formerly Laurer), published under mit, revision 0a71e92a985b.

multilingual - zero-shot-classification - text-classification - nli - pytorch - accuracy - multinli - xnli pipelinetag: zero-shot-classification candidatelabels: "politics, economy, entertainment, environment" This multilingual model can perform natural language inference (NLI) on 100+ languages and is therefore also suitable for multilingual zero-shot classification. The underlying multilingual-MiniLM-L6 model was created by Microsoft and was distilled from XLM-RoBERTa-large (see details in the original paper and newer information in this repo). The model was then fine-tuned on the XNLI dataset, which contains hypothesis-premise pairs from 15 languages, as well as the English MNLI dataset.…

Read Moritz Borrett-Laurer (formerly Laurer)'s full model card

Multilingual MiniLMv2-L6-mnli-xnli

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 multilingual-MiniLM-L6 model was created by Microsoft and was distilled from XLM-RoBERTa-large (see details in the original paper and newer information in this repo). The model was then fine-tuned on the XNLI dataset, which contains hypothesis-premise pairs from 15 languages, as well as the English MNLI dataset.

The main advantage of distilled models is that they are smaller (faster inference, lower memory requirements) than their teachers (XLM-RoBERTa-large). The disadvantage is that they lose some of the performance of their larger teachers.

For highest inference speed, I recommend using this 6-layer model. For higher performance I recommend mDeBERTa-v3-base-mnli-xnli (as of 14.02.2023).

How to use the model

Simple zero-shot classification pipeline
from transformers import pipeline
classifier = pipeline("zero-shot-classification", model="MoritzLaurer/multilingual-MiniLMv2-L6-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)
NLI use-case
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")

model_name = "MoritzLaurer/multilingual-MiniLMv2-L6-mnli-xnli"
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 XNLI development dataset and the MNLI train dataset. The XNLI development set consists of 2490 professionally translated texts from English to 14 other languages (37350 texts in total) (see this paper). Note that the XNLI contains a training set of 15 machine translated versions of the MNLI dataset for 15 languages, but due to quality issues with these machine translations, this model was only trained on the professional translations from the XNLI development set and the original English MNLI training set (392 702 texts). Not using machine translated texts can avoid overfitting the model to the 15 languages; avoids catastrophic forgetting of the other languages it was pre-trained on; and significantly reduces training costs.

Training procedure

The model was trained using the Hugging Face trainer with the following hyperparameters. The exact underlying model is mMiniLMv2-L6-H384-distilled-from-XLMR-Large.

training_args = TrainingArguments(
    num_train_epochs=3,              # total number of training epochs
    learning_rate=4e-05,
    per_device_train_batch_size=64,   # batch size per device during training
    per_device_eval_batch_size=120,    # batch size for evaluation
    warmup_ratio=0.06,                # number of warmup steps for learning rate scheduler
    weight_decay=0.01,               # strength of weight decay
)

Eval results

The model was evaluated on the XNLI test set on 15 languages (5010 texts per language, 75150 in total). Note that multilingual NLI models are capable of classifying NLI texts without receiving NLI training data in the specific language (cross-lingual transfer). This means that the model is also able of doing NLI on the other languages it was training on, but performance is most likely lower than for those languages available in XNLI.

The average XNLI performance of multilingual-MiniLM-L6 reported in the paper is 0.68 (see table 11). This reimplementation has an average performance of 0.713. This increase in performance is probably thanks to the addition of MNLI in the training data and this model was distilled from XLM-RoBERTa-large instead of -base (multilingual-MiniLM-L6-v2).

Datasets avg_xnli ar bg de el en es fr hi ru sw th tr ur vi zh
Accuracy 0.713 0.687 0.742 0.719 0.723 0.789 0.748 0.741 0.691 0.714 0.642 0.699 0.696 0.664 0.723 0.721
Speed text/sec (A100 GPU, eval_batch=120) 6093.0 6210.0 6003.0 6053.0 5409.0 6531.0 6205.0 5615.0 5734.0 5970.0 6219.0 6289.0 6533.0 5851.0 5970.0 6798.0
Datasets mnli_m mnli_mm
Accuracy 0.782 0.8
Speed text/sec (A100 GPU, eval_batch=120) 4430.0 4395.0

Limitations and bias

Please consult the original 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

Configuration

Architecture
XLMRobertaForSequenceClassification
Context length (tokens)
514
Layers
6
Hidden size
384
Feed-forward size
1,536
Attention heads
12
Vocabulary size
250,002
Stored precision
float32
Model type
xlm-roberta

Identity and Version

Repository
MoritzLaurer/multilingual-MiniLMv2-L6-mnli-xnli
Publisher
Moritz Borrett-Laurer (formerly Laurer)
Task
Zero-shot classification
Modality
Text
Library
transformers
Parameters
107M parameters
Languages
en, ar, bg, de, el, es, fr, hi
Revision
0a71e92a985b6e1ad1828cf67ce9c459639c1dca
First published
2023-02-11
Last updated
2024-04-22

Files and Weights

15 files, 1.3 GB in total. The weights are 3 files totalling 1.3 GB in bin, onnx, safetensors.

Weights3 files · 1.3 GB
Configuration4 files · 3.2 KB
Tokenizer4 files · 34.2 MB
Documentation1 file · 6.7 KB
Other2 files · 10.1 MB
Repository1 file · 1.5 KB
Every file
FileTypeSizeSHA-256
model.safetensorsWeights428.0 MB 91b323ccf247
onnx/model.onnxWeights428.1 MB 79f8cda2b123
pytorch_model.binWeights428.0 MB 46298086b629
config.jsonConfiguration1.0 KB
onnx/config.jsonConfiguration921 B
onnx/special_tokens_map.jsonConfiguration964 B
special_tokens_map.jsonConfiguration280 B
README.mdDocumentation6.7 KB
onnx/sentencepiece.bpe.modelOther5.1 MB cfc8146abe2a
sentencepiece.bpe.modelOther5.1 MB cfc8146abe2a
.gitattributesRepository1.5 KB
onnx/tokenizer.jsonTokenizer17.1 MB b2116c05e730
onnx/tokenizer_config.jsonTokenizer1.3 KB
tokenizer.jsonTokenizer17.1 MB 098c131bb442
tokenizer_config.jsonTokenizer565 B

License and Download

License
mit
Access
Open weights, no gate
Download size
1.3 GB
Download from Moritz Borrett-Laurer (formerly Laurer)

Released by Moritz Borrett-Laurer (formerly Laurer) through its official repository on Hugging Face. Read the license.

Built From

Memory Requirements

PrecisionWeights in memory
As published1.3 GB
16-bit0.2 GB
8-bit0.1 GB
4-bit0.1 GB

Weights only, from the published parameter count; the key-value cache and runtime add to this.

Questions About multilingual-MiniLMv2-L6-mnli-xnli

How much GPU memory does multilingual-MiniLMv2-L6-mnli-xnli need?

About 0.3 GB at 16-bit and 0.1 GB at 4-bit: the weights (107M parameters) plus a working margin. A long context needs more.

What is the cheapest GPU to run multilingual-MiniLMv2-L6-mnli-xnli on?

At 16-bit, 1x MI300X from $1.85 an hour; at 4-bit, 1x MI300X from $1.85 an hour, at the lowest on-demand prices the SAVRN Index lists.

Can I use multilingual-MiniLMv2-L6-mnli-xnli commercially?

Yes. multilingual-MiniLMv2-L6-mnli-xnli is released under MIT License. The MIT License is a short permissive license. It permits commercial use, modification and redistribution, provided the copyright notice and permission notice are included.

What is multilingual-MiniLMv2-L6-mnli-xnli's context length?

514 tokens, from the maximum position embeddings in its published configuration.

Similar Models

Model · Zero-shot classification

bert-base-spanish-wwm-cased-xnli

Recognai

UPDATE, 15.10.2021: Check out our new zero-shot classifiers, much more lightweight and even outperforming this one: zero-shot SELECTRA small and zero-shot SELECTRA medium. This model is a fine-tuned version of the spanish BERT model with the Spanish portion of the XNLI dataset. You can have a look at the training script for details of the training. You can use this model with Hugging Face's zero-shot-classification pipeline

Open weights mit 110M parameters 512 tokens transformers

multilingual - zero-shot-classification - text-classification - nli - pytorch - accuracy - multinli - xnli pipelinetag: zero-shot-classification candidatelabels: "politics, economy, entertainment, environment" This multilingual model can perform natural language inference (NLI) on 100+ languages and is therefore also suitable for multilingual zero-shot classification. The underlying multilingual-MiniLM-L12 model was created by Microsoft and was distilled from XLM-RoBERTa-large (see details in the original paper and newer information in this repo). The model was then fine-tuned on the XNLI dataset, which contains hypothesis-premise pairs from 15 languages, as well as the English MNLI…

Open weights mit 118M parameters 514 tokens transformers

Models in this series are designed for efficient zeroshot classification with the Hugging Face pipeline. These models can do classification without training data and run on both GPUs and CPUs. An overview of the latest zeroshot classifiers is available in my Zeroshot Classifier Collection. The main update of this zeroshot-v2.0 series of models is that several models are trained on fully commercially-friendly data for users with strict license requirements. These models can do one universal classification task: determine whether a hypothesis is "true" or "not true" given a text (entailment vs. notentailment). This task format is based on the Natural Language Inference task (NLI). The task is…

Open weights mit 125M parameters 514 tokens transformers

Model · Zero-shot classification

nli-roberta-base

Sentence Transformers - Cross-Encoders

This model was trained using SentenceTransformers Cross-Encoder class. The model was trained on the SNLI and MultiNLI datasets. For a given sentence pair, it will output three scores corresponding to the labels: contradiction, entailment, neutral. For evaluation results, see SBERT.net - Pretrained Cross-Encoder. Pre-trained models can be used like this: You can use the model also directly with Transformers library (without SentenceTransformers library): This model can also be used for zero-shot-classification

Open weights apache-2.0 125M parameters 514 tokens sentence-transformers

This model was trained using SentenceTransformers Cross-Encoder class. The model was trained on the SNLI and MultiNLI datasets. For a given sentence pair, it will output three scores corresponding to the labels: contradiction, entailment, neutral. For evaluation results, see SBERT.net - Pretrained Cross-Encoder. Pre-trained models can be used like this: You can use the model also directly with Transformers library (without SentenceTransformers library): This model can also be used for zero-shot-classification

Open weights apache-2.0 82M parameters 514 tokens sentence-transformers

This model was trained using SentenceTransformers Cross-Encoder class. The model was trained on the SNLI and MultiNLI datasets. For a given sentence pair, it will output three scores corresponding to the labels: contradiction, entailment, neutral. For evaluation results, see SBERT.net - Pretrained Cross-Encoder. Pre-trained models can be used like this: You can use the model also directly with Transformers library (without SentenceTransformers library): This model can also be used for zero-shot-classification

Open weights apache-2.0 82M parameters 514 tokens sentence-transformers