tomaarsen HF Staff commited on
Commit
8e88d7c
·
verified ·
1 Parent(s): 0cfec96

Add new CrossEncoder model

Browse files
Files changed (7) hide show
  1. README.md +68 -68
  2. config.json +46 -42
  3. merges.txt +1 -1
  4. onnx/model.onnx +3 -0
  5. special_tokens_map.json +51 -1
  6. tokenizer.json +0 -0
  7. 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
- "_name_or_path": "microsoft/deberta-base",
3
- "architectures": [
4
- "DebertaForSequenceClassification"
5
- ],
6
- "attention_probs_dropout_prob": 0.1,
7
- "hidden_act": "gelu",
8
- "hidden_dropout_prob": 0.1,
9
- "hidden_size": 768,
10
- "id2label": {
11
- "0": "contradiction",
12
- "1": "entailment",
13
- "2": "neutral"
14
- },
15
- "initializer_range": 0.02,
16
- "intermediate_size": 3072,
17
- "label2id": {
18
- "contradiction": 0,
19
- "entailment": 1,
20
- "neutral": 2
21
- },
22
- "layer_norm_eps": 1e-07,
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
- "tokenizer_class": "DebertaTokenizerFast",
39
- "transformers_version": "4.7.0",
40
- "type_vocab_size": 0,
41
- "vocab_size": 50265
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 - Trained by `huggingface/tokenizers`
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
- {"bos_token": {"content": "[CLS]", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, "eos_token": {"content": "[SEP]", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, "unk_token": {"content": "[UNK]", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, "sep_token": {"content": "[SEP]", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, "pad_token": {"content": "[PAD]", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, "cls_token": {"content": "[CLS]", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, "mask_token": {"content": "[MASK]", "single_word": false, "lstrip": true, "rstrip": false, "normalized": true}}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- {"unk_token": {"content": "[UNK]", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "bos_token": {"content": "[CLS]", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "eos_token": {"content": "[SEP]", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "add_prefix_space": false, "errors": "replace", "sep_token": {"content": "[SEP]", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "cls_token": {"content": "[CLS]", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "pad_token": {"content": "[PAD]", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "mask_token": {"content": "[MASK]", "single_word": false, "lstrip": true, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "do_lower_case": false, "vocab_type": "gpt2", "model_max_length": 512, "special_tokens_map_file": null, "name_or_path": "nli-deberta-base/"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }