mjwong commited on
Commit
96645d3
·
1 Parent(s): 1891e99

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +27 -0
README.md CHANGED
@@ -21,6 +21,8 @@ Liang Wang, Nan Yang, Xiaolong Huang, Binxing Jiao, Linjun Yang, Daxin Jiang, Ra
21
 
22
  ## How to use the model
23
 
 
 
24
  The model can be loaded with the `zero-shot-classification` pipeline like so:
25
 
26
  ```python
@@ -43,6 +45,31 @@ If more than one candidate label can be correct, pass `multi_class=True` to calc
43
  candidate_labels = ['travel', 'cooking', 'dancing', 'exploration']
44
  classifier(sequence_to_classify, candidate_labels, multi_class=True)
45
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
  ### Eval results
48
  The model was evaluated using the dev sets for MultiNLI and test sets for ANLI. The metric used is accuracy.
 
21
 
22
  ## How to use the model
23
 
24
+ ### With the zero-shot classification pipeline
25
+
26
  The model can be loaded with the `zero-shot-classification` pipeline like so:
27
 
28
  ```python
 
45
  candidate_labels = ['travel', 'cooking', 'dancing', 'exploration']
46
  classifier(sequence_to_classify, candidate_labels, multi_class=True)
47
  ```
48
+ ### With manual PyTorch
49
+
50
+ The model can also be applied on NLI tasks like so:
51
+
52
+ ```python
53
+ import torch
54
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
55
+
56
+ # device = "cuda:0" or "cpu"
57
+ device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
58
+
59
+ model_name = "mjwong/e5-large-v2-mnli"
60
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
61
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
62
+
63
+ premise = "But I thought you'd sworn off coffee."
64
+ hypothesis = "I thought that you vowed to drink more coffee."
65
+
66
+ input = tokenizer(premise, hypothesis, truncation=True, return_tensors="pt")
67
+ output = model(input["input_ids"].to(device))
68
+ prediction = torch.softmax(output["logits"][0], -1).tolist()
69
+ label_names = ["entailment", "neutral", "contradiction"]
70
+ prediction = {name: round(float(pred) * 100, 2) for pred, name in zip(prediction, label_names)}
71
+ print(prediction)
72
+ ```
73
 
74
  ### Eval results
75
  The model was evaluated using the dev sets for MultiNLI and test sets for ANLI. The metric used is accuracy.