Views
No views yet
1from datasets import load_dataset
2from transformers import pipeline
3
4pipe = pipeline("token-classification", model="plaguss/Mistral-7B-v0.1-Math-Shepherd-PRM-0.1")
5dataset = load_dataset("trl-lib/math_shepherd")
6example = dataset["test"][10]
7
8print("\n".join((example["prompt"], *example["completions"])))
9for idx in range(1, len(example["completions"])+1):
10 text = "\n".join((example["prompt"], *example["completions"][0:idx])) + "\n"
11 score = float(pipe(text)[-1]["score"])
12 print(f"Step {idx}\tScore: {score:.4f}\tLabel: {example['labels'][idx-1]}")
13
14# Asking to truncate to max_length but no maximum length is provided and the model has no predefined maximum length. Default to no truncation.
15# Step 1 Score: 1.00 Label: True
16# Step 2 Score: 1.00 Label: True
17# Step 3 Score: 1.00 Label: True
18# Step 4 Score: 0.96 Label: True
19# Step 5 Score: 0.95 Label: True
20# Step 6 Score: 0.88 Label: False
21# Step 7 Score: 0.73 Label: False
22# Step 8 Score: 0.86 Label: False
23# Step 9 Score: 0.96 Label: False1from datasets import load_dataset
2from transformers import pipeline
3
4pipe = pipeline("token-classification", model="plaguss/Mistral-7B-v0.1-Math-Shepherd-PRM-0.1", device="cuda")
5
6examples = [
7 {
8 "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?",
9 "completions": [
10 "Step 1: Janet's ducks lay 16 eggs per day.",
11 'Step 2: She eats three for breakfast every morning, so she has 16 - 3 = 13 eggs left.',
12 'Step 3: She bakes muffins for her friends every day with four eggs, so she has 13 - 4 = 9 eggs left.',
13 "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"
14 ],
15 "labels": [True, True, True, True]
16 },
17 {
18 "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?",
19 "completions": [
20 "Step 1: Janet's ducks lay 16 eggs per day.",
21 'Step 2: She eats three for breakfast every morning, so she has 16 - 3 = 13 eggs left.',
22 'Step 3: She bakes muffins for her friends every day with four eggs, so she has 13 - 4 = 9 eggs left.',
23 "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"
24 ],
25 "labels": [True, True, True, False]
26 },
27
28]
29
30for i, example in enumerate(examples):
31 print(f"- Example {i}:")
32 for idx in range(1, len(example["completions"])+1):
33 text = "\n".join((example["prompt"], *example["completions"][0:idx])) + "\n"
34 score = float(pipe(text)[-1]["score"])
35 print(f"Step {idx}\tScore: {score:.2f}\tLabel: {example['labels'][idx-1]}")
36
37# - Example 0:
38# Step 1 Score: 1.00 Label: True
39# Step 2 Score: 1.00 Label: True
40# Step 3 Score: 1.00 Label: True
41# Step 4 Score: 1.00 Label: True
42# - Example 1:
43# Step 1 Score: 1.00 Label: True
44# Step 2 Score: 1.00 Label: True
45# Step 3 Score: 1.00 Label: True
46# Step 4 Score: 0.98 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}