Let’s start with the simplest possible way of verifying an answer—just ask the model whether it’s correct. Our recipe:
verify_answer.py
from fvalues import Ffrom ice.recipe import recipedefmake_verification_prompt(question:str,answer:str)->str:returnF(f"""Consider this question: "{question}"Potential answer: "{answer}"Q: Is the potential answer above correct? Say "A: Yes" or "A: No".A:""")asyncdefverify_answer(question:str,answer:str)->float: prompt =make_verification_prompt(question=question,answer=answer) choice_probs, _ =await recipe.agent().classify(prompt=prompt,choices=(" Yes"," No"))return choice_probs.get(" Yes",0)recipe.main(verify_answer)
The interesting bit here is that we don’t just want a boolean Yes/No answer from the model, but that we want the probability of the “Yes” answer to the correctness question. This way, we get a more graded signal that we can use, e.g., to only show or use model responses when they exceed a threshold.
python verify_answer.py --question "What is 2 + 2?" --answer "4"
0.9948396822920341
python verify_answer.py --question "What is 2 + 2?" --answer "5"
0.0010152581398344962
python verify_answer.py --question "What is the capital of Germany?" --answer "Munich"
0.0005455832226911594
python verify_answer.py --question "Beth bakes 4x 2 dozen batches of cookies in a week. If these cookies are shared amongst 16 people equally, how many cookies does each person consume?" --answer "6"
0.06723949284762187
python verify_answer.py --question "Beth bakes 4x 2 dozen batches of cookies in a week. If these cookies are shared amongst 16 people equally, how many cookies does each person consume?" --answer "Beth bakes 4x 2 dozen batches of cookies for a total of 4*2 = 8 dozen cookies. There are 12 cookies in a dozen and she makes 8 dozen cookies for a total of 12*8 = 96 cookies. She splits the 96 cookies equally amongst 16 people so they each eat 96/16 = 6 cookies. So, the final answer is 6 cookies per person."