Sub topic 10
Asking again: checking consistency across samples
This chapter assumes you have read the chapters on sampling and temperature and on warning signs in an answer. You should be comfortable reading short Python functions. You do not need to call a real model API to follow the examples.
The idea in one paragraph
A model picks each token by sampling from a probability distribution. If you ask the same question several times with a temperature above zero, you get several independent draws from the model's answer distribution. When the model "knows" a fact, most of its probability mass sits on one answer, so the draws agree. When it is guessing, the mass is spread over many plausible answers, so the draws scatter. Self-consistency checking turns that scatter into a signal. Low agreement suggests the model is guessing. High agreement suggests the model has a stable preference, but it does not prove the answer is true.
Why disagreement shows up when the model is guessing
Recall the softmax example from the sampling chapter. A confident model might produce probabilities like 0.9, 0.07, 0.03 for three candidate tokens. A model that has little signal produces something like 0.4, 0.35, 0.25. Sampling five times from the first distribution almost always gives the same token. Sampling five times from the second gives a mix.
This matters most for the high-risk content types you saw earlier: dates, numbers, names, and citations. A fabricated detail is usually one of many fluent options. Each time you sample, the model commits to a different fluent option. A real, well-learned fact tends to come out the same way each time.
Running the check
The procedure has four steps.
- Ask the same question N times in independent conversations. Five to ten samples is a common range.
- Use a temperature above zero. At temperature 0 the model usually returns the same answer every time, so agreement tells you nothing.
- Reduce each response to the part you care about, such as a year, a name, or a yes/no.
- Count the most common answer and compute its share.
The agreement function does steps 3 and 4 for short answers. It lowercases, strips whitespace, and removes a trailing period, so "1889" and "1889." count as the same answer.
from collections import Counter
def agreement(answers):
normalized = [a.strip().lower().rstrip(".") for a in answers]
value, count = Counter(normalized).most_common(1)[0]
return value, count / len(normalized)
samples = ["1889", "1889.", "1887", "1889", "1901"]
print(agreement(samples))This prints ('1889', 0.6). Three of five samples agree. That is a moderate signal, not a strong one.
Wrapping it around a model call
In practice you pass in a function that calls your model. The sketch below uses a stand-in ask function so it runs without any API. Replace fake_model with a real call that sets a nonzero temperature.
import random
from collections import Counter
def agreement(answers):
normalized = [a.strip().lower().rstrip(".") for a in answers]
value, count = Counter(normalized).most_common(1)[0]
return value, count / len(normalized)
def check_consistency(ask, question, n=7, threshold=0.7):
answers = [ask(question) for _ in range(n)]
value, share = agreement(answers)
return {
"answer": value,
"agreement": round(share, 2),
"trusted": share >= threshold,
"all_answers": answers,
}
def fake_model(question):
options = ["1889", "1889.", "1887", "1901"]
return random.choices(options, weights=[5, 2, 2, 1])[0]
random.seed(7)
print(check_consistency(fake_model, "In what year was the tower finished?"))The exact output depends on the random draws. The structure of the result is what matters. You get the winning answer, its agreement share, a flag, and the raw answers so you can look at what the minority said.
Choosing what to compare
The hard part is usually step 3, deciding what counts as "the same answer."
Short, closed answers
Years, names, quantities, and yes/no answers are easy. Normalize formatting and compare. For numbers, parse them first so "1,200" and "1200" match. For units, convert to one unit before comparing.
Long, open answers
Two paragraphs can say the same thing in different words, so exact matching fails. You have three options.
- Ask the model to end each response with a one-line final answer, then compare only that line.
- Split each response into individual claims and check how many samples repeat each claim. A claim that appears in only one of seven samples is a candidate for invention.
- Use a second model call to judge whether two responses agree. This works but adds its own error, so spot check the judge.
Rephrased questions
You can also vary the wording of the question, not only the random draw. If "Who wrote the 1974 paper on X?" and "Which author published on X in 1974?" give different names, the model's answer depends on phrasing. That is a sign of weak knowledge. Combining resampling with rephrasing gives a broader test than resampling alone.
Reading the results
| Pattern across samples | Likely meaning | Suggested action |
|---|---|---|
| Nearly all identical | Strong preference, possibly well learned | Spot check against a source if the stakes are real |
| Clear majority, a few outliers | Mostly stable, some uncertainty | Look at the outliers, verify the majority |
| Two or three answers split the vote | The model is torn between candidates | Verify against a source before using either |
| Every sample different | The model is guessing | Treat as unknown, do not use the answer |
| Same answer but with different supporting details | Core fact may be stable, details are invented | Verify the details separately |
The last row is worth remembering. A model might consistently say a paper exists but give a different journal or page range each time. The variable parts are the fabricated parts.
Edge cases and failure modes
Consistency is a useful signal and a weak proof. Know where it breaks.
Consistent and wrong
The model can be reliably wrong. If a false claim appears often in the training text, such as a popular misconception, the model assigns it high probability and every sample repeats it. Agreement measures how peaked the distribution is, not whether the peak is correct. A false premise in your prompt can also push every sample toward the same wrong answer, as covered in the chapter on context failures.
Samples are not independent in the way you want
Each sample comes from the same model with the same training. Systematic gaps and biases are shared by all draws. Ten samples from one model do not behave like ten independent experts. Checking with a different model can help, but models trained on similar data can share the same mistakes.
Low temperature hides disagreement
If the temperature is very low, or the API applies other settings that narrow the distribution, the samples collapse onto the top choice. You see high agreement that reflects your settings, not the model's knowledge. Always confirm that the samples actually vary on a question where you expect them to vary.
Inconsistent but right
Disagreement can also come from legitimate ambiguity. "What is the largest city in Switzerland?" might return "Zurich" and "Zürich." Questions with several valid answers, or with answers that depend on a date, will scatter for good reasons. Normalization and clear question wording reduce this problem, but do not remove it.
Cost and latency
Seven samples cost roughly seven times as much as one. For long outputs this adds up. Use the check on the claims that matter, not on every sentence.
Where this fits in a workflow
Consistency checking is a cheap filter. It is good at catching guesses and poor at confirming truth. A practical order of use looks like this.
- Use the red flags from the previous chapter to decide which claims look risky.
- Run a consistency check on those claims.
- Drop or flag anything with low agreement.
- For claims with high agreement that you plan to rely on, verify against a primary source. The next chapter covers how.
The check saves effort because it removes obvious guesses before you spend time looking things up. It does not replace the lookup.
Exercise
You sample a model seven times at temperature 0.8 for "Which year did the author publish the book?" and get "2004" seven times. A colleague says this proves the date is correct. What is wrong with that conclusion, and what should you do next?
Show answer
Agreement shows the model's distribution is sharply peaked on 2004, not that 2004 is true. The model could be repeating a common error from its training data, or a false premise in the prompt could be steering every sample. Check the publication date in a primary source such as the publisher's page or a library catalog. Also confirm that the samples really varied in settings by trying a rephrased question, since low variation can come from sampling settings.
Exercise
Five samples for "What are the page numbers of the cited article?" return "112-130", "98-115", "112-130", "204-219", "77-90". Using the agreement function logic, what is the winning answer and its agreement share, and how should you treat it?
Show answer
The winning answer is "112-130" with a share of 2/5 = 0.4. That is low agreement, so treat the page range as a likely guess and verify it in the actual publication or a database. Do not use the value as it stands.