CoolFace
Modelpublic

mjwong/multilingual-e5-large-instruct-xnli

sourceHugging Facemitupdated 2y agoView on Hugging Face
0likes41downloads
Model Card

multilingual-e5-large-instruct-xnli

This model is a fine-tuned version of intfloat/multilingual-e5-large-instruct on the XNLI dataset.

Model description

Text Embeddings by Weakly-Supervised Contrastive Pre-training. Liang Wang, Nan Yang, Xiaolong Huang, Binxing Jiao, Linjun Yang, Daxin Jiang, Rangan Majumder, Furu Wei, arXiv 2022

How to use the model

With the zero-shot classification pipeline

The model can be loaded with the zero-shot-classification pipeline like so:

python
from transformers import pipeline
classifier = pipeline("zero-shot-classification",
                      model="mjwong/multilingual-e5-large-instruct-xnli")

You can then use this pipeline to classify sequences into any of the class names you specify.

python
sequence_to_classify = "Angela Merkel ist eine Politikerin in Deutschland und Vorsitzende der CDU"
candidate_labels = ["politics", "economy", "entertainment", "environment"]
classifier(sequence_to_classify, candidate_labels)

If more than one candidate label can be correct, pass multi_class=True to calculate each class independently:

python
candidate_labels = ["politics", "economy", "entertainment", "environment"]
classifier(sequence_to_classify, candidate_labels, multi_label=True)

With manual PyTorch

The model can also be applied on NLI tasks like so:

python
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification

# device = "cuda:0" or "cpu"
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")

model_name = "mjwong/multilingual-e5-large-instruct-xnli"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)

premise = "But I thought you'd sworn off coffee."
hypothesis = "I thought that you vowed to drink more coffee."

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", "neutral", "contradiction"]
prediction = {name: round(float(pred) * 100, 2) for pred, name in zip(prediction, label_names)}
print(prediction)

Eval results

The model was evaluated using the XNLI test sets on 15 languages: English (en), Arabic (ar), Bulgarian (bg), German (de), Greek (el), Spanish (es), French (fr), Hindi (hi), Russian (ru), Swahili (sw), Thai (th), Turkish (tr), Urdu (ur), Vietnam (vi) and Chinese (zh). The metric used is accuracy.

Datasetsenarbgdeelesfrhiruswthtrurvizh
multilingual-e5-base-xnli0.8490.7680.8030.8000.7920.8090.8050.7380.7820.7280.7560.7660.7130.7870.785
multilingual-e5-base-xnli-anli0.8110.7110.7510.7590.7460.7780.7650.6850.7280.6620.7050.7160.6830.7360.740
multilingual-e5-large-xnli0.8670.7910.8320.8250.8230.8370.8240.7780.8060.7490.7870.7930.7380.8130.808
multilingual-e5-large-xnli-anli0.8650.7650.8110.8110.7950.8230.8160.7430.7850.7130.7650.7740.7060.7880.787
multilingual-e5-large-instruct-xnli0.8640.7930.8390.8210.8240.8370.8230.7700.8100.7440.7840.7910.7160.8070.807
multilingual-e5-large-instruct-xnli-anli0.8610.7800.8160.8080.8060.8250.8160.7580.7990.7270.7750.7800.7210.7870.795

The model was also evaluated using the dev sets for MultiNLI and test sets for ANLI. The metric used is accuracy.

Datasetsmnli_dev_mmnli_dev_mmanli_test_r1anli_test_r2anli_test_r3
multilingual-e5-base-xnli0.8350.8370.2870.2760.301
multilingual-e5-base-xnli-anli0.8140.8110.5880.4370.439
multilingual-e5-large-xnli0.8650.8650.3120.3160.300
multilingual-e5-large-xnli-anli0.8630.8630.6230.4560.455
multilingual-e5-large-instruct-xnli0.8670.8660.3410.3300.323
multilingual-e5-large-instruct-xnli-anli0.8620.8620.6150.4590.462

Training hyperparameters

The following hyperparameters were used during training:

  • learning_rate: 2e-05
  • trainbatchsize: 16
  • evalbatchsize: 16
  • seed: 42
  • optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
  • lrschedulertype: linear
  • lrschedulerwarmup_ratio: 0.1
  • num_epochs: 1

Framework versions

  • Transformers 4.28.1
  • Pytorch 1.12.1+cu116
  • Datasets 2.19.2
  • Tokenizers 0.12.1