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
| 18 |
+
- zh
|
| 19 |
+
license: mit
|
| 20 |
+
datasets:
|
| 21 |
+
- xnli
|
| 22 |
+
pipeline_tag: zero-shot-classification
|
| 23 |
+
base_model: Alibaba-NLP/gte-multilingual-base
|
| 24 |
+
model-index:
|
| 25 |
+
- name: gte-multilingual-base-xnli
|
| 26 |
+
results: []
|
| 27 |
+
---
|
| 28 |
+
|
| 29 |
+
# gte-multilingual-base-xnli
|
| 30 |
+
|
| 31 |
+
This model is a fine-tuned version of [Alibaba-NLP/gte-multilingual-base](https://huggingface.co/Alibaba-NLP/gte-multilingual-base) on the XNLI dataset.
|
| 32 |
+
|
| 33 |
+
## Model description
|
| 34 |
+
|
| 35 |
+
[mGTE: Generalized Long-Context Text Representation and Reranking Models for Multilingual Text Retrieval](https://arxiv.org/pdf/2407.19669)
|
| 36 |
+
|
| 37 |
+
## How to use the model
|
| 38 |
+
|
| 39 |
+
### With the zero-shot classification pipeline
|
| 40 |
+
|
| 41 |
+
The model can be loaded with the `zero-shot-classification` pipeline like so:
|
| 42 |
+
|
| 43 |
+
```python
|
| 44 |
+
from transformers import pipeline
|
| 45 |
+
model = "mjwong/gte-multilingual-base-xnli"
|
| 46 |
+
tokenizer = AutoTokenizer.from_pretrained(model)
|
| 47 |
+
classifier = pipeline("zero-shot-classification",
|
| 48 |
+
model=model,
|
| 49 |
+
tokenizer=tokenizer,
|
| 50 |
+
trust_remote_code=True
|
| 51 |
+
)
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
You can then use this pipeline to classify sequences into any of the class names you specify.
|
| 55 |
+
|
| 56 |
+
```python
|
| 57 |
+
sequence_to_classify = "one day I will see the world"
|
| 58 |
+
candidate_labels = ['travel', 'cooking', 'dancing']
|
| 59 |
+
classifier(sequence_to_classify, candidate_labels)
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
If more than one candidate label can be correct, pass `multi_class=True` to calculate each class independently:
|
| 63 |
+
|
| 64 |
+
```python
|
| 65 |
+
candidate_labels = ['travel', 'cooking', 'dancing', 'exploration']
|
| 66 |
+
classifier(sequence_to_classify, candidate_labels, multi_class=True)
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
### With manual PyTorch
|
| 70 |
+
|
| 71 |
+
The model can also be applied on NLI tasks like so:
|
| 72 |
+
|
| 73 |
+
```python
|
| 74 |
+
import torch
|
| 75 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 76 |
+
# device = "cuda:0" or "cpu"
|
| 77 |
+
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
| 78 |
+
model_name = "mjwong/gte-multilingual-base-xnli"
|
| 79 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 80 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name, trust_remote_code=True)
|
| 81 |
+
premise = "But I thought you'd sworn off coffee."
|
| 82 |
+
hypothesis = "I thought that you vowed to drink more coffee."
|
| 83 |
+
input = tokenizer(premise, hypothesis, truncation=True, return_tensors="pt")
|
| 84 |
+
output = model(input["input_ids"].to(device))
|
| 85 |
+
prediction = torch.softmax(output["logits"][0], -1).tolist()
|
| 86 |
+
label_names = ["entailment", "neutral", "contradiction"]
|
| 87 |
+
prediction = {name: round(float(pred) * 100, 2) for pred, name in zip(prediction, label_names)}
|
| 88 |
+
print(prediction)
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
### Eval results
|
| 92 |
+
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.
|
| 93 |
+
|
| 94 |
+
|Datasets|en|ar|bg|de|el|es|fr|hi|ru|sw|th|tr|ur|vi|zh|
|
| 95 |
+
| :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
|
| 96 |
+
|[gte-multilingual-base-xnli](https://huggingface.co/mjwong/gte-multilingual-base-xnli)|0.854|0.767|0.811|0.798|0.801|0.820|0.818|0.753|0.792|0.719|0.766|0.769|0.701|0.799|0.798|
|
| 97 |
+
|[gte-multilingual-base-xnli-anli](https://huggingface.co/mjwong/gte-multilingual-base-xnli-anli)|0.843|0.738|0.793|0.773|0.776|0.801|0.788|0.727|0.775|0.689|0.746|0.747|0.687|0.773|0.779|
|
| 98 |
+
|
| 99 |
+
The model was also evaluated using the dev sets for MultiNLI and test sets for ANLI. The metric used is accuracy.
|
| 100 |
+
|
| 101 |
+
|Datasets|mnli_dev_m|mnli_dev_mm|anli_test_r1|anli_test_r2|anli_test_r3|
|
| 102 |
+
| :---: | :---: | :---: | :---: | :---: | :---: |
|
| 103 |
+
|[gte-multilingual-base-xnli](https://huggingface.co/mjwong/gte-multilingual-base-xnli)|0.852|0.852|0.295|0.292|0.336|
|
| 104 |
+
|[gte-multilingual-base-xnli-anli](https://huggingface.co/mjwong/gte-multilingual-base-xnli-anli)|0.834|0.837|0.567|0.445|0.443|
|
| 105 |
+
|
| 106 |
+
### Training hyperparameters
|
| 107 |
+
|
| 108 |
+
The following hyperparameters were used during training:
|
| 109 |
+
|
| 110 |
+
- learning_rate: 2e-05
|
| 111 |
+
- train_batch_size: 16
|
| 112 |
+
- eval_batch_size: 16
|
| 113 |
+
- seed: 42
|
| 114 |
+
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
|
| 115 |
+
- lr_scheduler_type: linear
|
| 116 |
+
- lr_scheduler_warmup_ratio: 0.1
|
| 117 |
+
|
| 118 |
+
### Framework versions
|
| 119 |
+
- Transformers 4.41.0
|
| 120 |
+
- Pytorch 2.6.0+cu124
|
| 121 |
+
- Datasets 3.2.0
|
| 122 |
+
- Tokenizers 0.19.1
|