plaguss HF staff commited on
Commit
ca81c5c
1 Parent(s): 0b92d52

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +74 -4
README.md CHANGED
@@ -17,13 +17,83 @@ 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.1", 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
 
26
+ pipe = pipeline("token-classification", model="plaguss/Mistral-7B-v0.1-Math-Shepherd-PRM-0.1")
27
+ dataset = load_dataset("trl-lib/math_shepherd")
28
+ example = dataset["test"][10]
29
+
30
+ print("\n".join((example["prompt"], *example["completions"])))
31
+ for idx in range(1, len(example["completions"])+1):
32
+ text = "\n".join((example["prompt"], *example["completions"][0:idx])) + "\n"
33
+ score = float(pipe(text)[-1]["score"])
34
+ print(f"Step {idx}\tScore: {score:.4f}\tLabel: {example['labels'][idx-1]}")
35
+
36
+ # Asking to truncate to max_length but no maximum length is provided and the model has no predefined maximum length. Default to no truncation.
37
+ # Step 1 Score: 1.00 Label: True
38
+ # Step 2 Score: 1.00 Label: True
39
+ # Step 3 Score: 1.00 Label: True
40
+ # Step 4 Score: 0.96 Label: True
41
+ # Step 5 Score: 0.95 Label: True
42
+ # Step 6 Score: 0.88 Label: False
43
+ # Step 7 Score: 0.73 Label: False
44
+ # Step 8 Score: 0.86 Label: False
45
+ # Step 9 Score: 0.96 Label: False
46
+ ```
47
+
48
+ Original case from the Math-Shepherd paper
49
+
50
+ ```python
51
+ from datasets import load_dataset
52
+ from transformers import pipeline
53
+
54
+ pipe = pipeline("token-classification", model="plaguss/Mistral-7B-v0.1-Math-Shepherd-PRM-0.1", device="cuda")
55
+
56
+ examples = [
57
+ {
58
+ "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?",
59
+ "completions": [
60
+ "Step 1: Janet's ducks lay 16 eggs per day.",
61
+ 'Step 2: She eats three for breakfast every morning, so she has 16 - 3 = 13 eggs left.',
62
+ 'Step 3: She bakes muffins for her friends every day with four eggs, so she has 13 - 4 = 9 eggs left.',
63
+ "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"
64
+ ],
65
+ "labels": [True, True, True, True]
66
+ },
67
+ {
68
+ "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?",
69
+ "completions": [
70
+ "Step 1: Janet's ducks lay 16 eggs per day.",
71
+ 'Step 2: She eats three for breakfast every morning, so she has 16 - 3 = 13 eggs left.',
72
+ 'Step 3: She bakes muffins for her friends every day with four eggs, so she has 13 - 4 = 9 eggs left.',
73
+ "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"
74
+ ],
75
+ "labels": [True, True, True, False]
76
+ },
77
+
78
+ ]
79
+
80
+ for i, example in enumerate(examples):
81
+ print(f"- Example {i}:")
82
+ for idx in range(1, len(example["completions"])+1):
83
+ text = "\n".join((example["prompt"], *example["completions"][0:idx])) + "\n"
84
+ score = float(pipe(text)[-1]["score"])
85
+ print(f"Step {idx}\tScore: {score:.2f}\tLabel: {example['labels'][idx-1]}")
86
+
87
+ # - Example 0:
88
+ # Step 1 Score: 1.00 Label: True
89
+ # Step 2 Score: 1.00 Label: True
90
+ # Step 3 Score: 1.00 Label: True
91
+ # Step 4 Score: 1.00 Label: True
92
+ # - Example 1:
93
+ # Step 1 Score: 1.00 Label: True
94
+ # Step 2 Score: 1.00 Label: True
95
+ # Step 3 Score: 1.00 Label: True
96
+ # Step 4 Score: 0.98 Label: False
97
  ```
98
 
99
  ## Training procedure