AnReu commited on
Commit
e5bbfad
1 Parent(s): 3bc6964

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +26 -0
README.md CHANGED
@@ -5,9 +5,35 @@ This model is further pre-trained on the Mathematics StackExchange questions and
5
  ## Usage
6
  ```
7
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
 
8
 
9
  tokenizer = AutoTokenizer.from_pretrained("albert-base-v2")
10
  model = AutoModelForSequenceClassification.from_pretrained("AnReu/albert-for-math-ar-base-ft")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  ```
12
 
13
  ## Reference
 
5
  ## Usage
6
  ```
7
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
8
+ import torch
9
 
10
  tokenizer = AutoTokenizer.from_pretrained("albert-base-v2")
11
  model = AutoModelForSequenceClassification.from_pretrained("AnReu/albert-for-math-ar-base-ft")
12
+
13
+ classes = ["non relevant", "relevant"]
14
+
15
+ sequence_0 = "How can I calculate x in $3x = 5$"
16
+ sequence_1 = "Just divide by 3: $x = \\frac{5}{3}$"
17
+ sequence_2 = "The general rule for squaring a sum is $(a+b)^2=a^2+2ab+b^2$"
18
+
19
+ # The tokenizer will automatically add any model specific separators (i.e. <CLS> and <SEP>) and tokens to
20
+ # the sequence, as well as compute the attention masks.
21
+ irrelevant = tokenizer(sequence_0, sequence_2, return_tensors="pt")
22
+ relevant = tokenizer(sequence_0, sequence_1, return_tensors="pt")
23
+
24
+ irrelevant_classification_logits = model(**irrelevant).logits
25
+ relevant_classification_logits = model(**relevant).logits
26
+
27
+ irrelevant_results = torch.softmax(irrelevant_classification_logits, dim=1).tolist()[0]
28
+ relevant_results = torch.softmax(relevant_classification_logits, dim=1).tolist()[0]
29
+
30
+ # Should be irrelevant
31
+ for i in range(len(classes)):
32
+ print(f"{classes[i]}: {int(round(irrelevant_results[i] * 100))}%")
33
+
34
+ # Should be relevant
35
+ for i in range(len(classes)):
36
+ print(f"{classes[i]}: {int(round(relevant_results[i] * 100))}%")
37
  ```
38
 
39
  ## Reference