Views
No views yet
1from transformers import pipeline
2
3pipe = pipeline("token-classification", model="HuggingFaceH4/Qwen2.5-Math-7B-Instruct-PRM-0.2", device="cuda")
4
5example = {
6 "prompt": "Let $a,$ $b,$ and $c$ be positive real numbers. Find the set of all possible values of\n\\[\\frac{c}{a} + \\frac{a}{b + c} + \\frac{b}{c}.\\]",
7 "completions": [
8 "This problem involves finding the range of an expression involving three variables.",
9 "One possible strategy is to try to eliminate some variables and write the expression in terms of one variable only.",
10 "To do this, I might look for some common factors or symmetries in the expression.",
11 "I notice that the first and last terms have $c$ in the denominator, so I can factor out $c$ from the whole expression and get\n\\[\\frac{1}{c}\\left(c + \\frac{a^2}{b + c} + b\\right).\\]"
12 ],
13 "labels": [True, True, True, False],
14}
15
16
17separator = "\n\n" # It's important to use the same separator as the one used during training
18
19for idx in range(1, len(example["completions"]) + 1):
20 steps = example["completions"][0:idx]
21 text = separator.join((example["prompt"], *steps)) + separator # Add a separator between the prompt and each steps
22 pred_entity = pipe(text)[-1]["entity"]
23 pred = {"LABEL_0": False, "LABEL_1": True}[pred_entity]
24 label = example["labels"][idx - 1]
25 print(f"Step {idx}\tPredicted: {pred} \tLabel: {label}")
26
27# Step 1 Predicted: True Label: True
28# Step 2 Predicted: True Label: True
29# Step 3 Predicted: True Label: True
30# Step 4 Predicted: False 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}