10/16
Part 5 of 7 · Ask several timesLearn

Ask the same question several times, and answer only when the answers agree

Anthropic's docs suggest running the same prompt several times and comparing the outputs, since inconsistencies across them could indicate hallucinations. SelfCheckGPT built a detector on the same idea: sample several responses and check them against each other, with no external database.

The simulation below asks 1,000 questions five times each. On 70% of them the model knows the answer and almost always gives it. On the rest it guesses among four answers. Each question's confidence is the share of its five samples that agree with the most common one. majority returns that answer and that share, and you'll write it in the next step.

rng = random.Random(8)
# (share of 5 samples that agree, majority answer is right)
results = []
for _ in range(1000):
    # the model knows this answer, or is guessing
    knows = rng.random() < 0.7
    samples = []
    for _ in range(5):
        if knows:
            samples.append("right" if rng.random() < 0.95 else rng.choice("abc"))
        else:
            samples.append(rng.choice(["right", "a", "b", "c"]))
    top, agree = majority(samples)
    results.append((agree, top == "right"))
for cut in (0.0, 0.6, 0.8):
    kept = [right for agree, right in results if agree >= cut]
    wrong = len(kept) - sum(kept)
    print(f"answer when {cut:.0%}+ agree: {len(kept) / len(results):5.1%} answered, {wrong:3} wrong, {len(results) - len(kept):3} handed off")
Predict

Answering only when at least 4 of 5 samples agree: about what share of the questions get answered?

Pick one to see what it prints.
Pick an answer above to see the rest