Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,95 @@
|
|
1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
license: mit
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
datasets:
|
3 |
+
- glue
|
4 |
+
- anli
|
5 |
+
model-index:
|
6 |
+
- name: bge-large-en-mnli-anli
|
7 |
+
results: []
|
8 |
+
pipeline_tag: zero-shot-classification
|
9 |
+
language:
|
10 |
+
- en
|
11 |
license: mit
|
12 |
---
|
13 |
+
|
14 |
+
# bge-large-en-mnli-anli
|
15 |
+
|
16 |
+
This model is a fine-tuned version of [BAAI/bge-large-en](https://huggingface.co/BAAI/bge-large-en) on the glue and ANLI dataset.
|
17 |
+
|
18 |
+
## Model description
|
19 |
+
|
20 |
+
[RetroMAE: Pre-Training Retrieval-oriented Language Models Via Masked Auto-Encoder](https://arxiv.org/abs/2205.12035).
|
21 |
+
Shitao Xiao, Zheng Liu, Yingxia Shao, Zhao Cao, arXiv 2022
|
22 |
+
|
23 |
+
## How to use the model
|
24 |
+
|
25 |
+
### With the zero-shot classification pipeline
|
26 |
+
|
27 |
+
The model can be loaded with the `zero-shot-classification` pipeline like so:
|
28 |
+
|
29 |
+
```python
|
30 |
+
from transformers import pipeline
|
31 |
+
classifier = pipeline("zero-shot-classification",
|
32 |
+
model="mjwong/bge-large-en-mnli-anli")
|
33 |
+
```
|
34 |
+
|
35 |
+
You can then use this pipeline to classify sequences into any of the class names you specify.
|
36 |
+
|
37 |
+
```python
|
38 |
+
sequence_to_classify = "one day I will see the world"
|
39 |
+
candidate_labels = ['travel', 'cooking', 'dancing']
|
40 |
+
classifier(sequence_to_classify, candidate_labels)
|
41 |
+
```
|
42 |
+
|
43 |
+
If more than one candidate label can be correct, pass `multi_class=True` to calculate each class independently:
|
44 |
+
|
45 |
+
```python
|
46 |
+
candidate_labels = ['travel', 'cooking', 'dancing', 'exploration']
|
47 |
+
classifier(sequence_to_classify, candidate_labels, multi_class=True)
|
48 |
+
```
|
49 |
+
|
50 |
+
### With manual PyTorch
|
51 |
+
|
52 |
+
The model can also be applied on NLI tasks like so:
|
53 |
+
|
54 |
+
```python
|
55 |
+
import torch
|
56 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
57 |
+
# device = "cuda:0" or "cpu"
|
58 |
+
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
59 |
+
model_name = "mjwong/bge-large-en-mnli-anli"
|
60 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
61 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
62 |
+
premise = "But I thought you'd sworn off coffee."
|
63 |
+
hypothesis = "I thought that you vowed to drink more coffee."
|
64 |
+
input = tokenizer(premise, hypothesis, truncation=True, return_tensors="pt")
|
65 |
+
output = model(input["input_ids"].to(device))
|
66 |
+
prediction = torch.softmax(output["logits"][0], -1).tolist()
|
67 |
+
label_names = ["entailment", "neutral", "contradiction"]
|
68 |
+
prediction = {name: round(float(pred) * 100, 2) for pred, name in zip(prediction, label_names)}
|
69 |
+
print(prediction)
|
70 |
+
```
|
71 |
+
|
72 |
+
### Eval results
|
73 |
+
The model was also evaluated using the dev sets for MultiNLI and test sets for ANLI. The metric used is accuracy.
|
74 |
+
|
75 |
+
|Datasets|mnli_dev_m|mnli_dev_mm|anli_test_r1|anli_test_r2|anli_test_r3|
|
76 |
+
| :---: | :---: | :---: | :---: | :---: | :---: |
|
77 |
+
|[bge-large-en-mnli-anli](https://huggingface.co/mjwong/bge-large-en-mnli-anli)|0.846|0.842|0.602|0.451|0.452|
|
78 |
+
|
79 |
+
### Training hyperparameters
|
80 |
+
|
81 |
+
The following hyperparameters were used during training:
|
82 |
+
|
83 |
+
- learning_rate: 2e-05
|
84 |
+
- train_batch_size: 16
|
85 |
+
- eval_batch_size: 16
|
86 |
+
- seed: 42
|
87 |
+
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
|
88 |
+
- lr_scheduler_type: linear
|
89 |
+
- lr_scheduler_warmup_ratio: 0.1
|
90 |
+
|
91 |
+
### Framework versions
|
92 |
+
- Transformers 4.28.1
|
93 |
+
- Pytorch 2.0.1+cu118
|
94 |
+
- Datasets 2.11.0
|
95 |
+
- Tokenizers 0.13.3
|