bart1259 commited on
Commit
cc65cad
·
verified ·
1 Parent(s): 88f9e44

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +87 -3
README.md CHANGED
@@ -1,3 +1,87 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ ---
4
+
5
+ Chain of Thought (CoT) transformer model trained to do multi-step integer arithmetic.
6
+
7
+ ```py
8
+ from transformers import pipeline
9
+
10
+ pipe = pipeline(
11
+ "text-generation", model="bart1259/MiniCOTMath"
12
+ )
13
+ print(pipe("Input: (5 + 5)
14
+ ", max_new_tokens=100)[0]["generated_text"])
15
+ ```
16
+
17
+ Outputs:
18
+ ```
19
+ Input: (5 + 5)
20
+
21
+ Step 1:
22
+ (5 + 5)
23
+ (5 + 5) = 10
24
+
25
+ Step 2:
26
+ 10
27
+ Final Result: 10
28
+ <end>
29
+
30
+ Input: (3 * 8)
31
+
32
+ Step 1:
33
+ (3 * 8)
34
+ (3
35
+ ```
36
+
37
+ To end at the <end> token, you can setup streaming like:
38
+
39
+ ```py
40
+ from transformers import AutoTokenizer, AutoModelForCausalLM, TextStreamer, StoppingCriteria
41
+ from transformers import StoppingCriteria
42
+
43
+ class StopCriteria(StoppingCriteria):
44
+ def __call__(self, input_ids, scores, **kwargs):
45
+ generated_text = tokenizer.decode(input_ids[0])
46
+ return "<end>" in generated_text
47
+
48
+ def __len__(self):
49
+ return 1
50
+
51
+ def __iter__(self):
52
+ yield self
53
+
54
+ prompt = "Input: (5 + 5)
55
+ "
56
+
57
+ tokenizer = AutoTokenizer.from_pretrained("bart1259/MiniCOTMath")
58
+ model = AutoModelForCausalLM.from_pretrained("bart1259/MiniCOTMath").cuda()
59
+
60
+ encoded_input = tokenizer(prompt, return_tensors='pt')
61
+ input_ids=encoded_input['input_ids'].cuda()
62
+
63
+ streamer = TextStreamer(tokenizer=tokenizer, skip_prompt=False)
64
+ _ = model.generate(
65
+ input_ids,
66
+ streamer=streamer,
67
+ pad_token_id=tokenizer.eos_token_id,
68
+ do_sample=True,
69
+ temperature=0.25,
70
+ max_new_tokens=256,
71
+ stopping_criteria=StopCriteria()
72
+ )
73
+ ```
74
+
75
+ Outputs:
76
+ ```
77
+ Input: (5 + 5)
78
+
79
+ Step 1:
80
+ (5 + 5)
81
+ (5 + 5) = 10
82
+
83
+ Step 2:
84
+ 10
85
+ Final Result: 10
86
+ <end>
87
+ ```