Thomas Müller commited on
Commit
7a58444
1 Parent(s): 55cc1c6

Updates example.

Browse files
Files changed (1) hide show
  1. README.md +12 -4
README.md CHANGED
@@ -38,10 +38,18 @@ import numpy as np
38
  model = AutoModelForSequenceClassification.from_pretrained("symanto/xlm-roberta-base-snli-mnli-anli-xnli")
39
  tokenizer = AutoTokenizer.from_pretrained("symanto/xlm-roberta-base-snli-mnli-anli-xnli")
40
 
41
- input_pairs = [("I like this pizza.", "The sentence is positive."), ("I like this pizza.", "The sentence is negative.")]
42
- inputs = tokenizer(["</s></s>".join(input_pair) for input_pair in input_pairs], return_tensors="pt")
 
 
 
 
 
 
 
43
  logits = model(**inputs).logits
44
- probs = torch.softmax(logits, dim=1).tolist()
 
45
  print("probs", probs)
46
- np.testing.assert_almost_equal(probs, [[0.86, 0.14, 0.00], [0.16, 0.15, 0.69]], decimal=2)
47
  ```
 
38
  model = AutoModelForSequenceClassification.from_pretrained("symanto/xlm-roberta-base-snli-mnli-anli-xnli")
39
  tokenizer = AutoTokenizer.from_pretrained("symanto/xlm-roberta-base-snli-mnli-anli-xnli")
40
 
41
+ input_pairs = [
42
+ ("I like this pizza.", "The sentence is positive."),
43
+ ("I like this pizza.", "The sentence is negative."),
44
+ ("I mag diese Pizza.", "Der Satz ist positiv."),
45
+ ("I mag diese Pizza.", "Der Satz ist negativ."),
46
+ ("Me gusta esta pizza.", "Esta frase es positivo."),
47
+ ("Me gusta esta pizza.", "Esta frase es negativo."),
48
+ ]
49
+ inputs = tokenizer(input_pairs, truncation="only_first", return_tensors="pt", padding=True)
50
  logits = model(**inputs).logits
51
+ probs = torch.softmax(logits, dim=1)
52
+ probs = probs[..., [0]].tolist()
53
  print("probs", probs)
54
+ np.testing.assert_almost_equal(probs, [[0.83], [0.04], [1.00], [0.00], [1.00], [0.00]], decimal=2)
55
  ```