plaguss HF staff commited on
Commit
97f6149
1 Parent(s): 9791a93

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +141 -4
README.md CHANGED
@@ -17,13 +17,150 @@ It has been trained using [TRL](https://github.com/huggingface/trl).
17
 
18
  ## Quick start
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  ```python
 
21
  from transformers import pipeline
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
- question = "If you had a time machine, but could only go to the past or the future once and never return, which would you choose and why?"
24
- generator = pipeline("text-generation", model="plaguss/Mistral-7B-v0.1-Math-Shepherd-PRM-0.2", device="cuda")
25
- output = generator([{"role": "user", "content": question}], max_new_tokens=128, return_full_text=False)[0]
26
- print(output["generated_text"])
 
 
 
 
 
 
 
27
  ```
28
 
29
  ## Training procedure
 
17
 
18
  ## Quick start
19
 
20
+ Example 1)
21
+
22
+ ```python
23
+ from datasets import load_dataset
24
+ from transformers import pipeline
25
+ import os
26
+ os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
27
+
28
+ model_name = "plaguss/Mistral-7B-v0.1-Math-Shepherd-PRM-0.2"
29
+
30
+ pipe = pipeline("token-classification", model=model_name, device="cuda")
31
+ dataset = load_dataset("trl-lib/math_shepherd")
32
+ example = dataset["test"][10]
33
+
34
+ sep = "\n"
35
+
36
+ print(sep.join((example["prompt"], *example["completions"])))
37
+ for idx in range(1, len(example["completions"])+1):
38
+ text = sep.join((example["prompt"], *example["completions"][0:idx])) + sep
39
+ output = pipe(text)
40
+ score = float(output[-1]["score"])
41
+ pred = True if output[-1]["entity"] == "LABEL_1" else False
42
+ print(f"Step {idx}\tPredicted (score): {pred} ({score:.2f})\tLabel: {example['labels'][idx-1]}")
43
+
44
+ # Grandma gave Bryce and Carter some raisins. Bryce received 6 more raisins than Carter, and Carter received half the number of raisins Bryce received. How many raisins did Bryce receive?
45
+ # Step 1: Let $b$ be the number of raisins Bryce received and $c$ be the number of raisins Carter received.
46
+ # Step 2: We are given that $b = c + 6$ and $c = \frac{1}{2}b$.
47
+ # Step 3: Substituting the second equation into the first equation, we get $b = c + 6 = \frac{1}{2}b + 6$.
48
+ # Step 4: Simplifying, we have $b = \frac{1}{2}b + 6$.
49
+ # Step 5: Subtracting $\frac{1}{2}b$ from both sides, we get $\frac{1}{2}b - b = 6$.
50
+ # Step 6: Simplifying further, we have $\frac{1}{2}b - 2b = 6$.
51
+ # Step 7: Combining like terms, we have $-\frac{1}{2}b = 6$.
52
+ # Step 8: Multiplying both sides by $-2$, we get $b = -12$.
53
+ # Step 9: Therefore, Bryce received $\boxed{-12}$ raisins.The answer is: -12
54
+ # Step 1 Predicted (score): True (0.99) Label: True
55
+ # Step 2 Predicted (score): True (0.94) Label: True
56
+ # Step 3 Predicted (score): True (0.94) Label: True
57
+ # Step 4 Predicted (score): True (0.82) Label: True
58
+ # Step 5 Predicted (score): True (0.50) Label: True
59
+ # Step 6 Predicted (score): False (0.71) Label: False
60
+ # Step 7 Predicted (score): False (0.73) Label: False
61
+ # Step 8 Predicted (score): False (0.77) Label: False
62
+ # Step 9 Predicted (score): False (0.97) Label: False
63
+ ```
64
+
65
+
66
+ Example 2)
67
+
68
  ```python
69
+ from datasets import load_dataset
70
  from transformers import pipeline
71
+ import os
72
+ os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
73
+
74
+ model_name = "plaguss/Mistral-7B-v0.1-Math-Shepherd-PRM-0.2"
75
+
76
+ pipe = pipeline("token-classification", model=model_name, device="cuda")
77
+ dataset = load_dataset("trl-lib/math_shepherd")
78
+ i = 32 # 10, 32
79
+ example = dataset["test"][i]
80
+
81
+ sep = "\n"
82
+
83
+ print(sep.join((example["prompt"], *example["completions"])))
84
+ for idx in range(1, len(example["completions"])+1):
85
+ text = sep.join((example["prompt"], *example["completions"][0:idx])) + sep
86
+ output = pipe(text)
87
+ score = float(output[-1]["score"])
88
+ pred = True if output[-1]["entity"] == "LABEL_1" else False
89
+ print(f"Step {idx}\tPredicted (score): {pred} ({score:.2f})\tLabel: {example['labels'][idx-1]}")
90
+
91
+
92
+ # In the Golden State Team, each player earned points. Draymond earned 12 points, Curry earned twice the points as Draymond, Kelly earned 9, Durant earned twice the points as Kelly, Klay earned half the points as Draymond. How many points did the Golden States have in total?
93
+ # Step 1: Draymond earned 12 points, Curry earned twice the points as Draymond, which is 2*12 = 24 points.
94
+ # Step 2: Kelly earned 9 points, Durant earned twice the points as Kelly, which is 2*9 = 18 points.
95
+ # Step 3: Klay earned half the points as Draymond, which is 12/2 = <<12/2=6>>6 points.
96
+ # Step 4: The Golden State Team had 12+24+9+18+6 = <<12+24+9+18+6=51>>51 points. The answer is: 51
97
+ # Step 1 Predicted (score): True (1.00) Label: True
98
+ # Step 2 Predicted (score): True (1.00) Label: True
99
+ # Step 3 Predicted (score): True (1.00) Label: True
100
+ # Step 4 Predicted (score): False (0.99) Label: False
101
+ ```
102
+
103
+ Example 3)
104
+
105
+ This example corresponds to the one shown in the [peiyi9979/math-shepherd-mistral-7b-prm](https://huggingface.co/peiyi9979/math-shepherd-mistral-7b-prm):
106
+
107
+ ```python
108
+ from datasets import load_dataset
109
+ from transformers import pipeline
110
+ import os
111
+ os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
112
+
113
+ model_name = "plaguss/Mistral-7B-v0.1-Math-Shepherd-PRM-0.2"
114
+
115
+ pipe = pipeline("token-classification", model=model_name, device="cuda")
116
+
117
+ examples = [
118
+ {
119
+ "prompt": "Janet\u2019s ducks lay 16 eggs per day. She eats three for breakfast every morning and bakes muffins for her friends every day with four. She sells the remainder at the farmers' market daily for $2 per fresh duck egg. How much in dollars does she make every day at the farmers' market?",
120
+ "completions": [
121
+ "Step 1: Janet's ducks lay 16 eggs per day.",
122
+ 'Step 2: She eats three for breakfast every morning, so she has 16 - 3 = 13 eggs left.',
123
+ 'Step 3: She bakes muffins for her friends every day with four eggs, so she has 13 - 4 = 9 eggs left.',
124
+ "Step 4: She sells the remainder at the farmers' market daily for $2 per fresh duck egg, so she makes 9 * $2 = $18 every day at the farmers' market. The answer is: 18"
125
+ ],
126
+ "labels": [True, True, True, True]
127
+ },
128
+ {
129
+ "prompt": "Janet\u2019s ducks lay 16 eggs per day. She eats three for breakfast every morning and bakes muffins for her friends every day with four. She sells the remainder at the farmers' market daily for $2 per fresh duck egg. How much in dollars does she make every day at the farmers' market?",
130
+ "completions": [
131
+ "Step 1: Janet's ducks lay 16 eggs per day.",
132
+ 'Step 2: She eats three for breakfast every morning, so she has 16 - 3 = 13 eggs left.',
133
+ 'Step 3: She bakes muffins for her friends every day with four eggs, so she has 13 - 4 = 9 eggs left.',
134
+ "Step 4: She sells the remainder at the farmers' market daily for $2 per fresh duck egg, so she makes 9 * $2 = $18 every day at the farmers' market. The answer is: 17"
135
+ ],
136
+ "labels": [True, True, True, False]
137
+ },
138
+
139
+ ]
140
+
141
+
142
+ sep = "\n"
143
+
144
+ for i, example in enumerate(examples):
145
+ print(f"- Example {i}:")
146
+ for idx in range(1, len(example["completions"])+1):
147
+ text = "\n".join((example["prompt"], *example["completions"][0:idx])) + "\n"
148
+ output = pipe(text)
149
+ score = float(output[-1]["score"])
150
+ pred = True if output[-1]["entity"] == "LABEL_1" else False
151
+ print(f"Step {idx}\tPredicted (score): {pred} ({score:.2f})\tLabel: {example['labels'][idx-1]}")
152
 
153
+ # - Example 0:
154
+ # Asking to truncate to max_length but no maximum length is provided and the model has no predefined maximum length. Default to no truncation.
155
+ # Step 1 Predicted (score): True (0.98) Label: True
156
+ # Step 2 Predicted (score): True (0.87) Label: True
157
+ # Step 3 Predicted (score): True (0.93) Label: True
158
+ # Step 4 Predicted (score): True (0.98) Label: True
159
+ # - Example 1:
160
+ # Step 1 Predicted (score): True (0.98) Label: True
161
+ # Step 2 Predicted (score): True (0.87) Label: True
162
+ # Step 3 Predicted (score): True (0.93) Label: True
163
+ # Step 4 Predicted (score): False (0.99) Label: False
164
  ```
165
 
166
  ## Training procedure