Performance improvement for TA + mathprompter
Browse filesFiles changed (4)
- TA.py+23-18
- app.py+10-2
- mathprompter.py+3-3
- prompt.py+4-18
26 unmodified lines27282930313233343536373839404142434445464748495051525326 unmodified linesquery = query.strip()query += "\n"code = generate_response(query, 0.9, token)splitting_string = "```" if "```python" not in code else "```python"code = code.split(splitting_string)[-2].split("```")[0].strip()print(code)# code preprocessingcode = post_process_code(code, question)print(code)# code runningif "input(" in code:return None, codepred = Nonetry:pred = run_code(code)except Exception as ex:return None, codereturn pred, codeif __name__ == "__main__":q = "What is the 7th Fibonacci number? Write the Python code"print(solve_ta(q))26 unmodified lines272829303132333435363738394041424344454647484950515253545556575826 unmodified linesquery = query.strip()query += "\n"code = generate_response(query, 0.9, token)n = len(TA_prompt.strip())code = code[n:].strip().split("-----")[0]# print(code)splitting_string = "```" if "```python" not in code else "```python"if "```" in code:code = code.split(splitting_string)[1].split("```")[0].strip()# code preprocessingcode = post_process_code(code, question)print(code)# code runningif "input(" in code:return None, codepred = Nonetry:pred = run_code(code)except Exception as ex:return None, codereturn pred, codeelse:res = re.findall(r"Assistant:(.*)", code)[0]return res, ""if __name__ == "__main__":q = "What is the smallest even prime number?"# q = "Write the code to find the 1st even prime number"print(solve_ta(q, "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"))
41 unmodified lines42434445464742 unmodified lines9091929394959697989923 unmodified lines12312412541 unmodified linesdef run_edits(code):try:code_op = run_code(code)return code_op, code42 unmodified linesaccess_token = gr.Textbox(type="password", label="Hugging Face Access Token")with gr.Row():methods = gr.Dropdown(choices=['PAL', 'TA', 'MathPrompter'], interactive=True, label="Evaluation Strategies")question_input = gr.Textbox(label="Question", lines=1, placeholder="Enter your question here...")instruction = gr.Textbox(label="Instructions", visible=False, interactive=False)methods.change(fn=render_instruction, inputs=methods, outputs=instruction)question_output = gr.Textbox(label="Answer", interactive=False)23 unmodified lines)demo.launch()41 unmodified lines424344454647484942 unmodified lines929394959697989910010123 unmodified lines12512612712812913013113213341 unmodified linesdef run_edits(code):if "input(" in code:return "Code execution failed, Please remove any input statement or bugs", codetry:code_op = run_code(code)return code_op, code42 unmodified linesaccess_token = gr.Textbox(type="password", label="Hugging Face Access Token")with gr.Row():methods = gr.Dropdown(choices=['PAL', 'TA', 'MathPrompter'], value="PAL",interactive=True, label="Evaluation Strategies")question_input = gr.Textbox(label="Question", lines=1, placeholder="Enter your question here...")instruction = gr.Textbox(label="Instructions", visible=True, interactive=False, value=render_instruction("PAL")['value'])methods.change(fn=render_instruction, inputs=methods, outputs=instruction)question_output = gr.Textbox(label="Answer", interactive=False)23 unmodified lines)demo.launch()'''Carol was playing a trivia game. In the first round she scored 17 points and in the second round she scored 6 points. In the last round she lost 16 points. How many points did she have at the end of the game?While on vacation, Debby took 24 pictures at the zoo and 12 at the museum. If she later deleted 14 of the pictures, how many pictures from her vacation did she still have?I had 5 apples, I gave 3 to my brother and 4 to my uncle. How many apples I am left with?'''
18 unmodified lines1920212223242510 unmodified lines3637383940417 unmodified lines495051525354555618 unmodified linesreturn question, var_mapdef generate_algebric_expression(question, variables, param, token):question = question.strip()query = algebric_prompt.format(question=question).strip() + "\n"response = generate_response(query, param, token)10 unmodified linesdef run(question, random_candidates, hps, token):question, var_map = generate_algebric_template(question)# generating the random candidates for argumentsrandom_mapping = pd.DataFrame(columns=list(var_map.keys()))7 unmodified linesN = len(hps)for i in range(N):variables = list(var_map.keys())expression = generate_algebric_expression(question, variables, hps[i], token)code = generate_python_code(question, expression, hps[i], token)candidates.append((expression, code))current_acc = 018 unmodified lines1920212223242510 unmodified lines363738394041427 unmodified lines5051525354555618 unmodified linesreturn question, var_mapdef generate_algebric_expression(question, param, token):question = question.strip()query = algebric_prompt.format(question=question).strip() + "\n"response = generate_response(query, param, token)10 unmodified linesdef run(question, random_candidates, hps, token):question, var_map = generate_algebric_template(question)print(question)# generating the random candidates for argumentsrandom_mapping = pd.DataFrame(columns=list(var_map.keys()))7 unmodified linesN = len(hps)for i in range(N):expression = generate_algebric_expression(question, hps[i], token)code = generate_python_code(question, expression, hps[i], token)candidates.append((expression, code))current_acc = 0
1234552 unmodified lines585960616263646566677 unmodified lines7576777879808182838485868788891 unmodified line919293949596979899100101102103104105# todo: Improve the prompt of mathprompter tooprompt = '''def solution():#Ques: For Halloween Debby and her sister combined the candy they received. Debby had 32 pieces of candy while her sister had 42. If they ate 35 pieces the first night, how many pieces do they have left?52 unmodified linesAnswer = (A + B) - C#Ques: Roger had A dollars. If he spent B bucks on a new game, how many C dollar toys could he buy with the money he had left?Answer = (A - B) // C#Ques: A waiter had A customers in his section. If B of them left and the rest of his tables had C people at each table, how many tables did he have?Answer = (A - B) / C7 unmodified linespython_prompt = '''#Ques: For Halloween Debby and her sister combined the candy they received. Debby had A pieces of candy while her sister had B. If they ate C pieces the first night, how many pieces do they have left?# Expression = (A + B) - C# Function for above Expression is:def solution(A, B, C):return (A + B) - C#Ques: A waiter had A customers in his section. If B of them left and the rest of his tables had C people at each table, how many tables did he have?# Expression = (A - B) / C# Function for above expression is:1 unmodified linereturn (A - B) / C#Ques: Roger had A dollars. If he spent B bucks on a new game, how many C dollar toys could he buy with the money he had left?# Expression = (A - B) // C# Function for above expression is:def solution(A, B, C):return (A - B) // C#Ques: There were A friends playing a video game online when B players quit. If each player left had C lives, how many lives did they have total? "# Expression = (A - B) * C# Function for above expression is:12352 unmodified lines5657585960617 unmodified lines6970717273747576777879808182831 unmodified line85868788899091prompt = '''def solution():#Ques: For Halloween Debby and her sister combined the candy they received. Debby had 32 pieces of candy while her sister had 42. If they ate 35 pieces the first night, how many pieces do they have left?52 unmodified linesAnswer = (A + B) - C#Ques: A waiter had A customers in his section. If B of them left and the rest of his tables had C people at each table, how many tables did he have?Answer = (A - B) / C7 unmodified linespython_prompt = '''# Ques: For Halloween Debby and her sister combined the candy they received. Debby had A pieces of candy while her sister had B . If they ate C pieces the first night, how many pieces do they have left?# Expression = (A + B) - C# Function for above Expression and Ques is:def solution(A, B, C):return (A + B) - C# Ques: A waiter had A customers in his section. If B of them left and the rest of his tables had C people at each table, how many tables did he have?# Expression = (A - B) / C# Function for above expression is:1 unmodified linereturn (A - B) / C# Ques: There were A friends playing a video game online when B more players joined the game. If each player had C lives, how many lives did they have total?# Expression = (A - B) * C# Function for above expression is:
TA.py+23-18
app.py+10-2
mathprompter.py+3-3
prompt.py+4-18