Checking answers

Does this sound plausible?

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 F

from ice.recipe import recipe


def make_verification_prompt(question: str, answer: str) -> str:
    return F(
        f"""Consider this question: "{question}"

Potential answer: "{answer}"

Q: Is the potential answer above correct? Say "A: Yes" or "A: No".
A:"""
    )


async def verify_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.

Sanity checks

Let’s test it:

Good.

Basic sanity checks pass.

Also correct.

Execution trace (view online)

A math problem

Let’s try something harder: A problem from the GSM8K math problems dataset:

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?

The correct answer is 6, but it takes a few steps of reasoning to work that out.

The model can’t see that the answer is correct.

What if we also give the reasoning steps?

Now the answer is judged to be more likely to be correct, but still less than 50% correct. What if we check the answer step by step?

Last updated