Fix: Add missing sentence-transformers installation in example code

#8
Files changed (1) hide show
  1. README.md +72 -71
README.md CHANGED
@@ -1,72 +1,73 @@
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-v3-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. This model is based on [microsoft/deberta-v3-large](https://huggingface.co/microsoft/deberta-v3-large)
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
- - Accuracy on SNLI-test dataset: 92.20
25
- - Accuracy on MNLI mismatched set: 90.49
26
-
27
- For futher evaluation results, see [SBERT.net - Pretrained Cross-Encoder](https://www.sbert.net/docs/pretrained_cross-encoders.html#nli).
28
-
29
- ## Usage
30
-
31
- Pre-trained models can be used like this:
32
- ```python
33
- from sentence_transformers import CrossEncoder
34
- model = CrossEncoder('cross-encoder/nli-deberta-v3-large')
35
- 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.')])
36
-
37
- #Convert scores to labels
38
- label_mapping = ['contradiction', 'entailment', 'neutral']
39
- labels = [label_mapping[score_max] for score_max in scores.argmax(axis=1)]
40
- ```
41
-
42
- ## Usage with Transformers AutoModel
43
- You can use the model also directly with Transformers library (without SentenceTransformers library):
44
- ```python
45
- from transformers import AutoTokenizer, AutoModelForSequenceClassification
46
- import torch
47
-
48
- model = AutoModelForSequenceClassification.from_pretrained('cross-encoder/nli-deberta-v3-large')
49
- tokenizer = AutoTokenizer.from_pretrained('cross-encoder/nli-deberta-v3-large')
50
-
51
- 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")
52
-
53
- model.eval()
54
- with torch.no_grad():
55
- scores = model(**features).logits
56
- label_mapping = ['contradiction', 'entailment', 'neutral']
57
- labels = [label_mapping[score_max] for score_max in scores.argmax(dim=1)]
58
- print(labels)
59
- ```
60
-
61
- ## Zero-Shot Classification
62
- This model can also be used for zero-shot-classification:
63
- ```python
64
- from transformers import pipeline
65
-
66
- classifier = pipeline("zero-shot-classification", model='cross-encoder/nli-deberta-v3-large')
67
-
68
- sent = "Apple just announced the newest iPhone X"
69
- candidate_labels = ["technology", "sports", "politics"]
70
- res = classifier(sent, candidate_labels)
71
- print(res)
 
72
  ```
 
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-v3-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. This model is based on [microsoft/deberta-v3-large](https://huggingface.co/microsoft/deberta-v3-large)
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
+ - Accuracy on SNLI-test dataset: 92.20
25
+ - Accuracy on MNLI mismatched set: 90.49
26
+
27
+ For futher evaluation results, see [SBERT.net - Pretrained Cross-Encoder](https://www.sbert.net/docs/pretrained_cross-encoders.html#nli).
28
+
29
+ ## Usage
30
+
31
+ Pre-trained models can be used like this:
32
+ ```python
33
+ # Requires: sentence-transformers
34
+ from sentence_transformers import CrossEncoder
35
+ model = CrossEncoder('cross-encoder/nli-deberta-v3-large')
36
+ 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.')])
37
+
38
+ #Convert scores to labels
39
+ label_mapping = ['contradiction', 'entailment', 'neutral']
40
+ labels = [label_mapping[score_max] for score_max in scores.argmax(axis=1)]
41
+ ```
42
+
43
+ ## Usage with Transformers AutoModel
44
+ You can use the model also directly with Transformers library (without SentenceTransformers library):
45
+ ```python
46
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
47
+ import torch
48
+
49
+ model = AutoModelForSequenceClassification.from_pretrained('cross-encoder/nli-deberta-v3-large')
50
+ tokenizer = AutoTokenizer.from_pretrained('cross-encoder/nli-deberta-v3-large')
51
+
52
+ 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")
53
+
54
+ model.eval()
55
+ with torch.no_grad():
56
+ scores = model(**features).logits
57
+ label_mapping = ['contradiction', 'entailment', 'neutral']
58
+ labels = [label_mapping[score_max] for score_max in scores.argmax(dim=1)]
59
+ print(labels)
60
+ ```
61
+
62
+ ## Zero-Shot Classification
63
+ This model can also be used for zero-shot-classification:
64
+ ```python
65
+ from transformers import pipeline
66
+
67
+ classifier = pipeline("zero-shot-classification", model='cross-encoder/nli-deberta-v3-large')
68
+
69
+ sent = "Apple just announced the newest iPhone X"
70
+ candidate_labels = ["technology", "sports", "politics"]
71
+ res = classifier(sent, candidate_labels)
72
+ print(res)
73
  ```