AI Compass
Compass

Why models hallucinate

Not a bug but a consequence of the design: where invented statements come from, which signals precede them, and what actually helps.

·2 min read·By Fachredaktion Technik
DETAIL
3 sections

The idea

A model picks every word so that it fits the text so far. It has no register of what it knows and does not know. When no matching information is available, a plausible continuation still emerges: only an invented one.

That also explains why invented statements sound especially convincing: that is exactly what the method optimises for.

Where it happens most

  • With case numbers, sections, standards and citations.
  • With figures, years and statistics.
  • With quotations and source attributions.
  • With very specialised questions on which little text exists.
  • With questions containing a false premise.

What actually helps

MeasureEffectEffort
Retrieval with a citation dutyvery largemedium
Verifying citations against the sourcelargemedium
"If not in the sources, say so"largesmall
Low temperature for factual questionsmediumnone
Self-consistency across several runsmediumhigh
Tools for figures and dateslarge, within scopesmall
A polite instruction in the promptsmallnone

The last row is the most common measure and the weakest. "Do not invent anything" in the prompt lowers the rate measurably, but far less than grounding in real sources.

A signal from the distribution

import numpy as np

def uncertainty(logprobs_per_token):
    """Mean negative log probability of the chosen tokens.
    High values suggest guessing."""
    return float(-np.mean(logprobs_per_token))

# In practice: fix a threshold on your own evaluation set and route
# answers above it to review.

Why it is structural

The training objective

min_θ D_KL( P_data ‖ P_θ )

What is minimised is distance to the distribution of training texts, not distance to truth.

P_θ
the model distribution
P_data
the distribution of the training data

Truth does not appear in that objective. A model that reproduces the text distribution perfectly also reproduces the frequency of false statements in the training material. On top of that: for a question the data says nothing about, every continuation is equally probable: the model rolls dice, and the result sounds certain.

Two kinds of uncertainty

KindCauseRecognised by
AleatoricThe question is ambiguousHigh entropy across all runs
EpistemicThe model does not knowHigh variance between several runs

The second is the relevant one. It can be measured by asking the same question several times at temperature above zero and evaluating agreement. Low agreement on a factual question is a strong warning sign, however confident each individual answer sounds.

Measuring grounding

Faithfulness of an answer

faithfulness = |A ∩ G| / |A|

The share of statements in the answer that can be found in the supplied sources.

A
the set of statements in the answer
G
the set of statements covered by the supplied sources

This can be estimated automatically: split the answer into individual claims and check each against the supplied passages. Faithfulness below 0.9 means every tenth claim is unsupported: not tenable for legal or medical information.

The right not to answer

The single most effective measure is to explicitly permit and reward non-answers. A system that says "that is not in the documents available to me" in 8 percent of cases is more useful than one that always answers and is wrong 8 percent of the time. The refusal rate therefore belongs tracked as a metric, not treated as a defect. See Troubleshooting.

Was this page helpful?
Why models hallucinate