Tom Aarsen
commited on
Commit
·
b95119c
1
Parent(s):
cf10b70
Revert inadvertent config, tokenizer updates
Browse filesThis reverts commit dc78db37e83f9a6b4916554ef3776819a24b7cb0.
- README.md +68 -68
- config.json +36 -40
- merges.txt +1 -1
- special_tokens_map.json +1 -51
- tokenizer.json +0 -0
- tokenizer_config.json +1 -65
README.md
CHANGED
@@ -1,69 +1,69 @@
|
|
1 |
-
---
|
2 |
-
language: en
|
3 |
-
pipeline_tag: zero-shot-classification
|
4 |
-
tags:
|
5 |
-
- transformers
|
6 |
-
datasets:
|
7 |
-
- nyu-mll/multi_nli
|
8 |
-
- stanfordnlp/snli
|
9 |
-
metrics:
|
10 |
-
- accuracy
|
11 |
-
license: apache-2.0
|
12 |
-
base_model:
|
13 |
-
- nreimers/MiniLMv2-L6-H768-distilled-from-RoBERTa-Large
|
14 |
-
library_name: sentence-transformers
|
15 |
-
---
|
16 |
-
|
17 |
-
# Cross-Encoder for Natural Language Inference
|
18 |
-
This model was trained using [SentenceTransformers](https://sbert.net) [Cross-Encoder](https://www.sbert.net/examples/applications/cross-encoder/README.html) class.
|
19 |
-
|
20 |
-
## Training Data
|
21 |
-
The model was trained on the [SNLI](https://nlp.stanford.edu/projects/snli/) and [MultiNLI](https://cims.nyu.edu/~sbowman/multinli/) datasets. For a given sentence pair, it will output three scores corresponding to the labels: contradiction, entailment, neutral.
|
22 |
-
|
23 |
-
## Performance
|
24 |
-
For evaluation results, see [SBERT.net - Pretrained Cross-Encoder](https://www.sbert.net/docs/pretrained_cross-encoders.html#nli).
|
25 |
-
|
26 |
-
## Usage
|
27 |
-
|
28 |
-
Pre-trained models can be used like this:
|
29 |
-
```python
|
30 |
-
from sentence_transformers import CrossEncoder
|
31 |
-
model = CrossEncoder('cross-encoder/nli-MiniLM2-L6-H768')
|
32 |
-
scores = model.predict([('A man is eating pizza', 'A man eats something'), ('A black race car starts up in front of a crowd of people.', 'A man is driving down a lonely road.')])
|
33 |
-
|
34 |
-
#Convert scores to labels
|
35 |
-
label_mapping = ['contradiction', 'entailment', 'neutral']
|
36 |
-
labels = [label_mapping[score_max] for score_max in scores.argmax(axis=1)]
|
37 |
-
```
|
38 |
-
|
39 |
-
## Usage with Transformers AutoModel
|
40 |
-
You can use the model also directly with Transformers library (without SentenceTransformers library):
|
41 |
-
```python
|
42 |
-
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
43 |
-
import torch
|
44 |
-
|
45 |
-
model = AutoModelForSequenceClassification.from_pretrained('cross-encoder/nli-MiniLM2-L6-H768')
|
46 |
-
tokenizer = AutoTokenizer.from_pretrained('cross-encoder/nli-MiniLM2-L6-H768')
|
47 |
-
|
48 |
-
features = tokenizer(['A man is eating pizza', 'A black race car starts up in front of a crowd of people.'], ['A man eats something', 'A man is driving down a lonely road.'], padding=True, truncation=True, return_tensors="pt")
|
49 |
-
|
50 |
-
model.eval()
|
51 |
-
with torch.no_grad():
|
52 |
-
scores = model(**features).logits
|
53 |
-
label_mapping = ['contradiction', 'entailment', 'neutral']
|
54 |
-
labels = [label_mapping[score_max] for score_max in scores.argmax(dim=1)]
|
55 |
-
print(labels)
|
56 |
-
```
|
57 |
-
|
58 |
-
## Zero-Shot Classification
|
59 |
-
This model can also be used for zero-shot-classification:
|
60 |
-
```python
|
61 |
-
from transformers import pipeline
|
62 |
-
|
63 |
-
classifier = pipeline("zero-shot-classification", model='cross-encoder/nli-MiniLM2-L6-H768')
|
64 |
-
|
65 |
-
sent = "Apple just announced the newest iPhone X"
|
66 |
-
candidate_labels = ["technology", "sports", "politics"]
|
67 |
-
res = classifier(sent, candidate_labels)
|
68 |
-
print(res)
|
69 |
```
|
|
|
1 |
+
---
|
2 |
+
language: en
|
3 |
+
pipeline_tag: zero-shot-classification
|
4 |
+
tags:
|
5 |
+
- transformers
|
6 |
+
datasets:
|
7 |
+
- nyu-mll/multi_nli
|
8 |
+
- stanfordnlp/snli
|
9 |
+
metrics:
|
10 |
+
- accuracy
|
11 |
+
license: apache-2.0
|
12 |
+
base_model:
|
13 |
+
- nreimers/MiniLMv2-L6-H768-distilled-from-RoBERTa-Large
|
14 |
+
library_name: sentence-transformers
|
15 |
+
---
|
16 |
+
|
17 |
+
# Cross-Encoder for Natural Language Inference
|
18 |
+
This model was trained using [SentenceTransformers](https://sbert.net) [Cross-Encoder](https://www.sbert.net/examples/applications/cross-encoder/README.html) class.
|
19 |
+
|
20 |
+
## Training Data
|
21 |
+
The model was trained on the [SNLI](https://nlp.stanford.edu/projects/snli/) and [MultiNLI](https://cims.nyu.edu/~sbowman/multinli/) datasets. For a given sentence pair, it will output three scores corresponding to the labels: contradiction, entailment, neutral.
|
22 |
+
|
23 |
+
## Performance
|
24 |
+
For evaluation results, see [SBERT.net - Pretrained Cross-Encoder](https://www.sbert.net/docs/pretrained_cross-encoders.html#nli).
|
25 |
+
|
26 |
+
## Usage
|
27 |
+
|
28 |
+
Pre-trained models can be used like this:
|
29 |
+
```python
|
30 |
+
from sentence_transformers import CrossEncoder
|
31 |
+
model = CrossEncoder('cross-encoder/nli-MiniLM2-L6-H768')
|
32 |
+
scores = model.predict([('A man is eating pizza', 'A man eats something'), ('A black race car starts up in front of a crowd of people.', 'A man is driving down a lonely road.')])
|
33 |
+
|
34 |
+
#Convert scores to labels
|
35 |
+
label_mapping = ['contradiction', 'entailment', 'neutral']
|
36 |
+
labels = [label_mapping[score_max] for score_max in scores.argmax(axis=1)]
|
37 |
+
```
|
38 |
+
|
39 |
+
## Usage with Transformers AutoModel
|
40 |
+
You can use the model also directly with Transformers library (without SentenceTransformers library):
|
41 |
+
```python
|
42 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
43 |
+
import torch
|
44 |
+
|
45 |
+
model = AutoModelForSequenceClassification.from_pretrained('cross-encoder/nli-MiniLM2-L6-H768')
|
46 |
+
tokenizer = AutoTokenizer.from_pretrained('cross-encoder/nli-MiniLM2-L6-H768')
|
47 |
+
|
48 |
+
features = tokenizer(['A man is eating pizza', 'A black race car starts up in front of a crowd of people.'], ['A man eats something', 'A man is driving down a lonely road.'], padding=True, truncation=True, return_tensors="pt")
|
49 |
+
|
50 |
+
model.eval()
|
51 |
+
with torch.no_grad():
|
52 |
+
scores = model(**features).logits
|
53 |
+
label_mapping = ['contradiction', 'entailment', 'neutral']
|
54 |
+
labels = [label_mapping[score_max] for score_max in scores.argmax(dim=1)]
|
55 |
+
print(labels)
|
56 |
+
```
|
57 |
+
|
58 |
+
## Zero-Shot Classification
|
59 |
+
This model can also be used for zero-shot-classification:
|
60 |
+
```python
|
61 |
+
from transformers import pipeline
|
62 |
+
|
63 |
+
classifier = pipeline("zero-shot-classification", model='cross-encoder/nli-MiniLM2-L6-H768')
|
64 |
+
|
65 |
+
sent = "Apple just announced the newest iPhone X"
|
66 |
+
candidate_labels = ["technology", "sports", "politics"]
|
67 |
+
res = classifier(sent, candidate_labels)
|
68 |
+
print(res)
|
69 |
```
|
config.json
CHANGED
@@ -1,40 +1,36 @@
|
|
1 |
-
{
|
2 |
-
"
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
"
|
7 |
-
"
|
8 |
-
"eos_token_id": 2,
|
9 |
-
"gradient_checkpointing": false,
|
10 |
-
"hidden_act": "gelu",
|
11 |
-
"hidden_dropout_prob": 0.1,
|
12 |
-
"hidden_size": 768,
|
13 |
-
"id2label": {
|
14 |
-
"0": "contradiction",
|
15 |
-
"1": "entailment",
|
16 |
-
"2": "neutral"
|
17 |
-
},
|
18 |
-
"initializer_range": 0.02,
|
19 |
-
"intermediate_size": 3072,
|
20 |
-
"label2id": {
|
21 |
-
"contradiction": 0,
|
22 |
-
"entailment": 1,
|
23 |
-
"neutral": 2
|
24 |
-
},
|
25 |
-
"layer_norm_eps": 1e-05,
|
26 |
-
"max_position_embeddings": 514,
|
27 |
-
"model_type": "roberta",
|
28 |
-
"num_attention_heads": 12,
|
29 |
-
"num_hidden_layers": 6,
|
30 |
-
"pad_token_id": 1,
|
31 |
-
"position_embedding_type": "absolute",
|
32 |
-
"
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
"type_vocab_size": 1,
|
38 |
-
"use_cache": true,
|
39 |
-
"vocab_size": 50265
|
40 |
-
}
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "nreimers/MiniLMv2-L6-H768-distilled-from-RoBERTa-Large",
|
3 |
+
"architectures": [
|
4 |
+
"RobertaForSequenceClassification"
|
5 |
+
],
|
6 |
+
"attention_probs_dropout_prob": 0.1,
|
7 |
+
"bos_token_id": 0,
|
8 |
+
"eos_token_id": 2,
|
9 |
+
"gradient_checkpointing": false,
|
10 |
+
"hidden_act": "gelu",
|
11 |
+
"hidden_dropout_prob": 0.1,
|
12 |
+
"hidden_size": 768,
|
13 |
+
"id2label": {
|
14 |
+
"0": "contradiction",
|
15 |
+
"1": "entailment",
|
16 |
+
"2": "neutral"
|
17 |
+
},
|
18 |
+
"initializer_range": 0.02,
|
19 |
+
"intermediate_size": 3072,
|
20 |
+
"label2id": {
|
21 |
+
"contradiction": 0,
|
22 |
+
"entailment": 1,
|
23 |
+
"neutral": 2
|
24 |
+
},
|
25 |
+
"layer_norm_eps": 1e-05,
|
26 |
+
"max_position_embeddings": 514,
|
27 |
+
"model_type": "roberta",
|
28 |
+
"num_attention_heads": 12,
|
29 |
+
"num_hidden_layers": 6,
|
30 |
+
"pad_token_id": 1,
|
31 |
+
"position_embedding_type": "absolute",
|
32 |
+
"transformers_version": "4.6.1",
|
33 |
+
"type_vocab_size": 1,
|
34 |
+
"use_cache": true,
|
35 |
+
"vocab_size": 50265
|
36 |
+
}
|
|
|
|
|
|
|
|
merges.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
#version: 0.2
|
2 |
Ġ t
|
3 |
Ġ a
|
4 |
h e
|
|
|
1 |
+
#version: 0.2 - Trained by `huggingface/tokenizers`
|
2 |
Ġ t
|
3 |
Ġ a
|
4 |
h e
|
special_tokens_map.json
CHANGED
@@ -1,51 +1 @@
|
|
1 |
-
{
|
2 |
-
"bos_token": {
|
3 |
-
"content": "<s>",
|
4 |
-
"lstrip": false,
|
5 |
-
"normalized": false,
|
6 |
-
"rstrip": false,
|
7 |
-
"single_word": false
|
8 |
-
},
|
9 |
-
"cls_token": {
|
10 |
-
"content": "<s>",
|
11 |
-
"lstrip": false,
|
12 |
-
"normalized": false,
|
13 |
-
"rstrip": false,
|
14 |
-
"single_word": false
|
15 |
-
},
|
16 |
-
"eos_token": {
|
17 |
-
"content": "</s>",
|
18 |
-
"lstrip": false,
|
19 |
-
"normalized": false,
|
20 |
-
"rstrip": false,
|
21 |
-
"single_word": false
|
22 |
-
},
|
23 |
-
"mask_token": {
|
24 |
-
"content": "<mask>",
|
25 |
-
"lstrip": true,
|
26 |
-
"normalized": false,
|
27 |
-
"rstrip": false,
|
28 |
-
"single_word": false
|
29 |
-
},
|
30 |
-
"pad_token": {
|
31 |
-
"content": "<pad>",
|
32 |
-
"lstrip": false,
|
33 |
-
"normalized": false,
|
34 |
-
"rstrip": false,
|
35 |
-
"single_word": false
|
36 |
-
},
|
37 |
-
"sep_token": {
|
38 |
-
"content": "</s>",
|
39 |
-
"lstrip": false,
|
40 |
-
"normalized": false,
|
41 |
-
"rstrip": false,
|
42 |
-
"single_word": false
|
43 |
-
},
|
44 |
-
"unk_token": {
|
45 |
-
"content": "<unk>",
|
46 |
-
"lstrip": false,
|
47 |
-
"normalized": false,
|
48 |
-
"rstrip": false,
|
49 |
-
"single_word": false
|
50 |
-
}
|
51 |
-
}
|
|
|
1 |
+
{"bos_token": "<s>", "eos_token": "</s>", "unk_token": "<unk>", "sep_token": "</s>", "pad_token": "<pad>", "cls_token": "<s>", "mask_token": {"content": "<mask>", "single_word": false, "lstrip": true, "rstrip": false, "normalized": false}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tokenizer.json
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
CHANGED
@@ -1,65 +1 @@
|
|
1 |
-
{
|
2 |
-
"add_prefix_space": false,
|
3 |
-
"added_tokens_decoder": {
|
4 |
-
"0": {
|
5 |
-
"content": "<s>",
|
6 |
-
"lstrip": false,
|
7 |
-
"normalized": false,
|
8 |
-
"rstrip": false,
|
9 |
-
"single_word": false,
|
10 |
-
"special": true
|
11 |
-
},
|
12 |
-
"1": {
|
13 |
-
"content": "<pad>",
|
14 |
-
"lstrip": false,
|
15 |
-
"normalized": false,
|
16 |
-
"rstrip": false,
|
17 |
-
"single_word": false,
|
18 |
-
"special": true
|
19 |
-
},
|
20 |
-
"2": {
|
21 |
-
"content": "</s>",
|
22 |
-
"lstrip": false,
|
23 |
-
"normalized": false,
|
24 |
-
"rstrip": false,
|
25 |
-
"single_word": false,
|
26 |
-
"special": true
|
27 |
-
},
|
28 |
-
"3": {
|
29 |
-
"content": "<unk>",
|
30 |
-
"lstrip": false,
|
31 |
-
"normalized": false,
|
32 |
-
"rstrip": false,
|
33 |
-
"single_word": false,
|
34 |
-
"special": true
|
35 |
-
},
|
36 |
-
"50264": {
|
37 |
-
"content": "<mask>",
|
38 |
-
"lstrip": true,
|
39 |
-
"normalized": false,
|
40 |
-
"rstrip": false,
|
41 |
-
"single_word": false,
|
42 |
-
"special": true
|
43 |
-
}
|
44 |
-
},
|
45 |
-
"bos_token": "<s>",
|
46 |
-
"clean_up_tokenization_spaces": false,
|
47 |
-
"cls_token": "<s>",
|
48 |
-
"eos_token": "</s>",
|
49 |
-
"errors": "replace",
|
50 |
-
"extra_special_tokens": {},
|
51 |
-
"mask_token": "<mask>",
|
52 |
-
"max_length": 512,
|
53 |
-
"model_max_length": 512,
|
54 |
-
"pad_to_multiple_of": null,
|
55 |
-
"pad_token": "<pad>",
|
56 |
-
"pad_token_type_id": 0,
|
57 |
-
"padding_side": "right",
|
58 |
-
"sep_token": "</s>",
|
59 |
-
"stride": 0,
|
60 |
-
"tokenizer_class": "RobertaTokenizer",
|
61 |
-
"trim_offsets": true,
|
62 |
-
"truncation_side": "right",
|
63 |
-
"truncation_strategy": "longest_first",
|
64 |
-
"unk_token": "<unk>"
|
65 |
-
}
|
|
|
1 |
+
{"unk_token": "<unk>", "bos_token": "<s>", "eos_token": "</s>", "add_prefix_space": false, "errors": "replace", "sep_token": "</s>", "cls_token": "<s>", "pad_token": "<pad>", "mask_token": "<mask>", "model_max_length": 512, "special_tokens_map_file": null, "name_or_path": "nreimers/MiniLMv2-L6-H768-distilled-from-RoBERTa-Large"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|