georgiyozhegov commited on
Commit
b9bfd0f
·
verified ·
1 Parent(s): 4890871

Add usage example

Browse files
Files changed (1) hide show
  1. README.md +32 -0
README.md CHANGED
@@ -13,6 +13,38 @@ Model-calculator.
13
 
14
  Works well with single-digit numbers, but with numbers with more than 2 digits it starts to make mistakes.
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  # Good Examples
17
 
18
  ```
 
13
 
14
  Works well with single-digit numbers, but with numbers with more than 2 digits it starts to make mistakes.
15
 
16
+ # Usage
17
+
18
+ ```python
19
+ from transformers import AutoTokenizer, AutoModelForCausalLM
20
+
21
+ tokenizer = AutoTokenizer.from_pretrained("georgiyozhegov/calculator")
22
+ model = AutoModelForCausalLM.from_pretrained("georgiyozhegov/calculator")
23
+
24
+ prompt = "find 2 + 3\nstep"
25
+
26
+ inputs = tokenizer(prompt, return_tensors="pt", return_token_type_ids=False)
27
+
28
+ with torch.no_grad():
29
+ outputs = model.generate(
30
+ input_ids=inputs["input_ids"],
31
+ attention_mask=inputs["attention_mask"],
32
+ max_length=32,
33
+ do_sample=True,
34
+ top_k=50,
35
+ top_p=0.98
36
+ )
37
+
38
+ # Cut the rest
39
+ count = 0
40
+ for index, token in enumerate(outputs[0]):
41
+ if token == 6: count += 1
42
+ if count >= 2: break
43
+
44
+ output = tokenizer.decode(outputs[0][:index])
45
+ print(output)
46
+ ```
47
+
48
  # Good Examples
49
 
50
  ```