Views
No views yet
1from datasets import load_dataset
2from transformers import pipeline
3import os
4os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
5
6model_name = "plaguss/Llama-3.1-8B-Math-Shepherd-PRM-0.2"
7
8pipe = pipeline("token-classification", model=model_name, device="cuda")
9dataset = load_dataset("trl-lib/math_shepherd")
10example = dataset["test"][10]
11
12sep = "\n"
13
14print(sep.join((example["prompt"], *example["completions"])))
15for idx in range(1, len(example["completions"])+1):
16 text = sep.join((example["prompt"], *example["completions"][0:idx])) + sep
17 output = pipe(text)
18 score = float(output[-1]["score"])
19 pred = True if output[-1]["entity"] == "LABEL_1" else False
20 print(f"Step {idx}\tPredicted (score): {pred} ({score:.2f})\tLabel: {example['labels'][idx-1]}")
21
22# 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?
23# Step 1: Let $b$ be the number of raisins Bryce received and $c$ be the number of raisins Carter received.
24# Step 2: We are given that $b = c + 6$ and $c = \frac{1}{2}b$.
25# Step 3: Substituting the second equation into the first equation, we get $b = c + 6 = \frac{1}{2}b + 6$.
26# Step 4: Simplifying, we have $b = \frac{1}{2}b + 6$.
27# Step 5: Subtracting $\frac{1}{2}b$ from both sides, we get $\frac{1}{2}b - b = 6$.
28# Step 6: Simplifying further, we have $\frac{1}{2}b - 2b = 6$.
29# Step 7: Combining like terms, we have $-\frac{1}{2}b = 6$.
30# Step 8: Multiplying both sides by $-2$, we get $b = -12$.
31# Step 9: Therefore, Bryce received $\boxed{-12}$ raisins.The answer is: -12
32# Step 1 Predicted (score): True (0.99) Label: True
33# Step 2 Predicted (score): True (1.00) Label: True
34# Step 3 Predicted (score): True (0.97) Label: True
35# Step 4 Predicted (score): True (0.77) Label: True
36# Step 5 Predicted (score): True (0.68) Label: True
37# Step 6 Predicted (score): False (0.70) Label: False
38# Step 7 Predicted (score): False (0.82) Label: False
39# Step 8 Predicted (score): False (0.97) Label: False
40# Step 9 Predicted (score): False (0.99) Label: False1from datasets import load_dataset
2from transformers import pipeline
3import os
4os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
5
6model_name = "plaguss/Llama-3.1-8B-Math-Shepherd-PRM-0.2"
7
8pipe = pipeline("token-classification", model=model_name, device="cuda")
9dataset = load_dataset("trl-lib/math_shepherd")
10i = 32 # 10, 32
11example = dataset["test"][i]
12
13sep = "\n"
14
15print(sep.join((example["prompt"], *example["completions"])))
16for idx in range(1, len(example["completions"])+1):
17 text = sep.join((example["prompt"], *example["completions"][0:idx])) + sep
18 output = pipe(text)
19 score = float(output[-1]["score"])
20 pred = True if output[-1]["entity"] == "LABEL_1" else False
21 print(f"Step {idx}\tPredicted (score): {pred} ({score:.2f})\tLabel: {example['labels'][idx-1]}")
22
23
24# 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?
25# Step 1: Draymond earned 12 points, Curry earned twice the points as Draymond, which is 2*12 = 24 points.
26# Step 2: Kelly earned 9 points, Durant earned twice the points as Kelly, which is 2*9 = 18 points.
27# Step 3: Klay earned half the points as Draymond, which is 12/2 = <<12/2=6>>6 points.
28# Step 4: The Golden State Team had 12+24+9+18+6 = <<12+24+9+18+6=51>>51 points. The answer is: 51
29# Step 1 Predicted (score): True (0.99) Label: True
30# Step 2 Predicted (score): True (1.00) Label: True
31# Step 3 Predicted (score): True (1.00) Label: True
32# Step 4 Predicted (score): False (0.99) Label: False1from datasets import load_dataset
2from transformers import pipeline
3import os
4os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
5
6model_name = "plaguss/Llama-3.1-8B-Math-Shepherd-PRM-0.2"
7
8pipe = pipeline("token-classification", model=model_name, device="cuda")
9
10examples = [
11 {
12 "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?",
13 "completions": [
14 "Step 1: Janet's ducks lay 16 eggs per day.",
15 'Step 2: She eats three for breakfast every morning, so she has 16 - 3 = 13 eggs left.',
16 'Step 3: She bakes muffins for her friends every day with four eggs, so she has 13 - 4 = 9 eggs left.',
17 "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"
18 ],
19 "labels": [True, True, True, True]
20 },
21 {
22 "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?",
23 "completions": [
24 "Step 1: Janet's ducks lay 16 eggs per day.",
25 'Step 2: She eats three for breakfast every morning, so she has 16 - 3 = 13 eggs left.',
26 'Step 3: She bakes muffins for her friends every day with four eggs, so she has 13 - 4 = 9 eggs left.',
27 "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"
28 ],
29 "labels": [True, True, True, False]
30 },
31
32]
33
34
35sep = "\n"
36
37for i, example in enumerate(examples):
38 print(f"- Example {i}:")
39 for idx in range(1, len(example["completions"])+1):
40 text = "\n".join((example["prompt"], *example["completions"][0:idx])) + "\n"
41 output = pipe(text)
42 score = float(output[-1]["score"])
43 pred = True if output[-1]["entity"] == "LABEL_1" else False
44 print(f"Step {idx}\tPredicted (score): {pred} ({score:.2f})\tLabel: {example['labels'][idx-1]}")
45
46# - Example 0:
47# Step 1 Predicted (score): True (0.98) Label: True
48# Step 2 Predicted (score): True (0.86) Label: True
49# Step 3 Predicted (score): True (0.91) Label: True
50# Step 4 Predicted (score): True (0.84) Label: True
51# - Example 1:
52# Step 1 Predicted (score): True (0.98) Label: True
53# Step 2 Predicted (score): True (0.86) Label: True
54# Step 3 Predicted (score): True (0.91) Label: True
55# Step 4 Predicted (score): False (0.99) Label: False1@article{uesato2022solving,
2 title = {Solving Math Word Problems With Process- and Outcome-Based Feedback},
3 author = {Uesato, Jonathan and Kushman, Nate and Kumar, Ramana and Song, Francis and Siegel, Noah and Wang, Lisa and Creswell, Antonia and Irving, Geoffrey and Higgins, Irina},
4 year = 2022,
5 journal = {arXiv preprint arXiv:2211.14275}
6}1@misc{vonwerra2022trl,
2 title = {{TRL: Transformer Reinforcement Learning}},
3 author = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallouédec},
4 year = 2020,
5 journal = {GitHub repository},
6 publisher = {GitHub},
7 howpublished = {\url{https://github.com/huggingface/trl}}
8}