Views
No views yet
SuperCorrect: Supervising and Correcting Language Models with Error-Driven Insights Ling Yang*, Zhaochen Yu*, Tianjun Zhang, Minkai Xu, Joseph E. Gonzalez,Bin Cui, Shuicheng YanPeking University, Skywork AI, UC Berkeley, Stanford University


transformers>=4.37.0 is needed for Qwen2.5-Math models. The latest version is recommended.[!Warning]🚨 This is a must because `transformers` integrated Qwen2 codes since `4.37.0`.
1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_name = "BitStarWalkin/SuperCorrect-7B"
4device = "cuda"
5
6model = AutoModelForCausalLM.from_pretrained(
7 model_name,
8 torch_dtype="auto",
9 device_map="auto"
10)
11tokenizer = AutoTokenizer.from_pretrained(model_name)
12
13prompt = "Find the distance between the foci of the ellipse \[9x^2 + \frac{y^2}{9} = 99.\]"
14hierarchical_prompt = "Solve the following math problem in a step-by-step XML format, each step should be enclosed within tags like <Step1></Step1>. For each step enclosed within the tags, determine if this step is challenging and tricky, if so, add detailed explanation and analysis enclosed within <Key> </Key> in this step, as helpful annotations to help you thinking and remind yourself how to conduct reasoning correctly. After all the reasoning steps, summarize the common solution and reasoning steps to help you and your classmates who are not good at math generalize to similar problems within <Generalized></Generalized>. Finally present the final answer within <Answer> </Answer>."
15# HT
16messages = [
17 {"role": "system", "content":hierarchical_prompt },
18 {"role": "user", "content": prompt}
19]
20
21text = tokenizer.apply_chat_template(
22 messages,
23 tokenize=False,
24 add_generation_prompt=True
25)
26model_inputs = tokenizer([text], return_tensors="pt").to(device)
27
28generated_ids = model.generate(
29 **model_inputs,
30 max_new_tokens=1024
31)
32generated_ids = [
33 output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
34]
35
36response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
37print(response)
1@article{yang2024supercorrect,
2title={SuperCorrect: Supervising and Correcting Language Models with Error-Driven Insights}
3 author={Yang, Ling and Yu, Zhaochen and Zhang, Tianjun and Xu, Minkai and Gonzalez, Joseph E and Cui, Bin and Yan, Shuicheng},
4 journal={arXiv preprint arXiv:2410.09008},
5 year={2024}
6}
7@article{yang2024buffer,
8 title={Buffer of Thoughts: Thought-Augmented Reasoning with Large Language Models},
9 author={Yang, Ling and Yu, Zhaochen and Zhang, Tianjun and Cao, Shiyi and Xu, Minkai and Zhang, Wentao and Gonzalez, Joseph E and Cui, Bin},
10 journal={arXiv preprint arXiv:2406.04271},
11 year={2024}
12}