Add new CrossEncoder model
Browse files- README.md +68 -68
- config.json +46 -42
- merges.txt +1 -1
- onnx/model.onnx +3 -0
- special_tokens_map.json +51 -1
- tokenizer.json +0 -0
- tokenizer_config.json +66 -1
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 |
-
- microsoft/deberta-base
|
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-deberta-base')
|
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-deberta-base')
|
46 |
-
tokenizer = AutoTokenizer.from_pretrained('cross-encoder/nli-deberta-base')
|
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-deberta-base')
|
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 |
+
- microsoft/deberta-base
|
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-deberta-base')
|
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-deberta-base')
|
46 |
+
tokenizer = AutoTokenizer.from_pretrained('cross-encoder/nli-deberta-base')
|
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-deberta-base')
|
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,42 +1,46 @@
|
|
1 |
-
{
|
2 |
-
"
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
"
|
7 |
-
"
|
8 |
-
"
|
9 |
-
"
|
10 |
-
|
11 |
-
"
|
12 |
-
"
|
13 |
-
|
14 |
-
|
15 |
-
"
|
16 |
-
"
|
17 |
-
|
18 |
-
"
|
19 |
-
"
|
20 |
-
|
21 |
-
|
22 |
-
"
|
23 |
-
"max_position_embeddings": 512,
|
24 |
-
"max_relative_positions": -1,
|
25 |
-
"model_type": "deberta",
|
26 |
-
"num_attention_heads": 12,
|
27 |
-
"num_hidden_layers": 12,
|
28 |
-
"pad_token_id": 0,
|
29 |
-
"pooler_dropout": 0,
|
30 |
-
"pooler_hidden_act": "gelu",
|
31 |
-
"pooler_hidden_size": 768,
|
32 |
-
"pos_att_type": [
|
33 |
-
"c2p",
|
34 |
-
"p2c"
|
35 |
-
],
|
36 |
-
"position_biased_input": false,
|
37 |
-
"relative_attention": true,
|
38 |
-
"
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"DebertaForSequenceClassification"
|
4 |
+
],
|
5 |
+
"attention_probs_dropout_prob": 0.1,
|
6 |
+
"hidden_act": "gelu",
|
7 |
+
"hidden_dropout_prob": 0.1,
|
8 |
+
"hidden_size": 768,
|
9 |
+
"id2label": {
|
10 |
+
"0": "contradiction",
|
11 |
+
"1": "entailment",
|
12 |
+
"2": "neutral"
|
13 |
+
},
|
14 |
+
"initializer_range": 0.02,
|
15 |
+
"intermediate_size": 3072,
|
16 |
+
"label2id": {
|
17 |
+
"contradiction": 0,
|
18 |
+
"entailment": 1,
|
19 |
+
"neutral": 2
|
20 |
+
},
|
21 |
+
"layer_norm_eps": 1e-07,
|
22 |
+
"legacy": true,
|
23 |
+
"max_position_embeddings": 512,
|
24 |
+
"max_relative_positions": -1,
|
25 |
+
"model_type": "deberta",
|
26 |
+
"num_attention_heads": 12,
|
27 |
+
"num_hidden_layers": 12,
|
28 |
+
"pad_token_id": 0,
|
29 |
+
"pooler_dropout": 0,
|
30 |
+
"pooler_hidden_act": "gelu",
|
31 |
+
"pooler_hidden_size": 768,
|
32 |
+
"pos_att_type": [
|
33 |
+
"c2p",
|
34 |
+
"p2c"
|
35 |
+
],
|
36 |
+
"position_biased_input": false,
|
37 |
+
"relative_attention": true,
|
38 |
+
"sentence_transformers": {
|
39 |
+
"activation_fn": "torch.nn.modules.linear.Identity",
|
40 |
+
"version": "4.1.0.dev0"
|
41 |
+
},
|
42 |
+
"tokenizer_class": "DebertaTokenizerFast",
|
43 |
+
"transformers_version": "4.52.0.dev0",
|
44 |
+
"type_vocab_size": 0,
|
45 |
+
"vocab_size": 50265
|
46 |
+
}
|
merges.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
#version: 0.2
|
2 |
Ġ t
|
3 |
Ġ a
|
4 |
h e
|
|
|
1 |
+
#version: 0.2
|
2 |
Ġ t
|
3 |
Ġ a
|
4 |
h e
|
onnx/model.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e21552123e1329ef20edc8b64d02c0dca67396496cbcc86391dea9ae5d13c9b1
|
3 |
+
size 557350444
|
special_tokens_map.json
CHANGED
@@ -1 +1,51 @@
|
|
1 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token": {
|
3 |
+
"content": "[CLS]",
|
4 |
+
"lstrip": false,
|
5 |
+
"normalized": true,
|
6 |
+
"rstrip": false,
|
7 |
+
"single_word": false
|
8 |
+
},
|
9 |
+
"cls_token": {
|
10 |
+
"content": "[CLS]",
|
11 |
+
"lstrip": false,
|
12 |
+
"normalized": true,
|
13 |
+
"rstrip": false,
|
14 |
+
"single_word": false
|
15 |
+
},
|
16 |
+
"eos_token": {
|
17 |
+
"content": "[SEP]",
|
18 |
+
"lstrip": false,
|
19 |
+
"normalized": true,
|
20 |
+
"rstrip": false,
|
21 |
+
"single_word": false
|
22 |
+
},
|
23 |
+
"mask_token": {
|
24 |
+
"content": "[MASK]",
|
25 |
+
"lstrip": true,
|
26 |
+
"normalized": true,
|
27 |
+
"rstrip": false,
|
28 |
+
"single_word": false
|
29 |
+
},
|
30 |
+
"pad_token": {
|
31 |
+
"content": "[PAD]",
|
32 |
+
"lstrip": false,
|
33 |
+
"normalized": true,
|
34 |
+
"rstrip": false,
|
35 |
+
"single_word": false
|
36 |
+
},
|
37 |
+
"sep_token": {
|
38 |
+
"content": "[SEP]",
|
39 |
+
"lstrip": false,
|
40 |
+
"normalized": true,
|
41 |
+
"rstrip": false,
|
42 |
+
"single_word": false
|
43 |
+
},
|
44 |
+
"unk_token": {
|
45 |
+
"content": "[UNK]",
|
46 |
+
"lstrip": false,
|
47 |
+
"normalized": true,
|
48 |
+
"rstrip": false,
|
49 |
+
"single_word": false
|
50 |
+
}
|
51 |
+
}
|
tokenizer.json
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
CHANGED
@@ -1 +1,66 @@
|
|
1 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"add_prefix_space": false,
|
3 |
+
"added_tokens_decoder": {
|
4 |
+
"0": {
|
5 |
+
"content": "[PAD]",
|
6 |
+
"lstrip": false,
|
7 |
+
"normalized": true,
|
8 |
+
"rstrip": false,
|
9 |
+
"single_word": false,
|
10 |
+
"special": true
|
11 |
+
},
|
12 |
+
"1": {
|
13 |
+
"content": "[CLS]",
|
14 |
+
"lstrip": false,
|
15 |
+
"normalized": true,
|
16 |
+
"rstrip": false,
|
17 |
+
"single_word": false,
|
18 |
+
"special": true
|
19 |
+
},
|
20 |
+
"2": {
|
21 |
+
"content": "[SEP]",
|
22 |
+
"lstrip": false,
|
23 |
+
"normalized": true,
|
24 |
+
"rstrip": false,
|
25 |
+
"single_word": false,
|
26 |
+
"special": true
|
27 |
+
},
|
28 |
+
"3": {
|
29 |
+
"content": "[UNK]",
|
30 |
+
"lstrip": false,
|
31 |
+
"normalized": true,
|
32 |
+
"rstrip": false,
|
33 |
+
"single_word": false,
|
34 |
+
"special": true
|
35 |
+
},
|
36 |
+
"50264": {
|
37 |
+
"content": "[MASK]",
|
38 |
+
"lstrip": true,
|
39 |
+
"normalized": true,
|
40 |
+
"rstrip": false,
|
41 |
+
"single_word": false,
|
42 |
+
"special": true
|
43 |
+
}
|
44 |
+
},
|
45 |
+
"bos_token": "[CLS]",
|
46 |
+
"clean_up_tokenization_spaces": false,
|
47 |
+
"cls_token": "[CLS]",
|
48 |
+
"do_lower_case": false,
|
49 |
+
"eos_token": "[SEP]",
|
50 |
+
"errors": "replace",
|
51 |
+
"extra_special_tokens": {},
|
52 |
+
"mask_token": "[MASK]",
|
53 |
+
"max_length": 512,
|
54 |
+
"model_max_length": 512,
|
55 |
+
"pad_to_multiple_of": null,
|
56 |
+
"pad_token": "[PAD]",
|
57 |
+
"pad_token_type_id": 0,
|
58 |
+
"padding_side": "right",
|
59 |
+
"sep_token": "[SEP]",
|
60 |
+
"stride": 0,
|
61 |
+
"tokenizer_class": "DebertaTokenizer",
|
62 |
+
"truncation_side": "right",
|
63 |
+
"truncation_strategy": "longest_first",
|
64 |
+
"unk_token": "[UNK]",
|
65 |
+
"vocab_type": "gpt2"
|
66 |
+
}
|