All courses

Why models hallucinate

Explain hallucination from the mechanisms: the model produces fluent, plausible continuations for facts it saw rarely or never. Explain how fine-tuning on unknown facts and grading that never rewards 'I don't know' encourage confident guessing.

Builds on: Calibration of model probabilities, Supervised fine-tuning on demonstrations

▶ Watch this lesson Start the whole course

What the animation says

Confident and wrong

Ask a model when a minor nineteenth-century chemist, Dr. X, was born. It answers 1847, smoothly, with no hedge. And it's wrong. Nothing inside the network looks facts up or checks them. It only predicts the next token. For a famous person, the birth year appears all over the training text, so the probability piles onto one year. Dr. X appears once, maybe never. The model learned the shape, a four-digit year after 'born in', but not the value. So its probability spreads thin over many years. It still has to emit a token. What comes out?

Fine-tuning on unknown facts

It emits a specific year, and a wrong year reads exactly as fluently as the true one. Now fine-tuning. A demonstration says: Dr. X was born in 1852. But the base model barely knows Dr. X. A few examples like this rarely become real knowledge. The model picks such facts up slowly, if at all. Yet its behavior does change, and fast. Tap what this demonstration teaches quickest.

Scores that never reward "I don't know"

It's the habit: when asked, assert. Hedges vanish, and stated confidence stops tracking what the model knows. That's lost calibration. Then evaluation. Most tests give one point for correct, and zero for wrong or for I don't know. Let q be the chance the answer is right. Guessing averages q. Abstaining averages zero. For any q above zero, guess. Now charge c points for each wrong answer. Guessing averages q, minus c times the chance of being wrong. That beats abstaining only when q is greater than c over one plus c. Pick models on one-zero scores, and confident guessers win.

Dr. X, scored three ways

Back to Dr. X. The model's belief: 1852 at a quarter, 1850 at a fifth, 1848 at fifteen percent, the rest spread out. If it's calibrated, its best guess, 1852, is right a quarter of the time. So q is 0.25. One-zero scoring: guessing earns 0.25, abstaining zero. Guess. Penalty of one per wrong answer: 0.25 minus 0.75 is minus a half. The threshold is one half. Abstain. Now the penalty is one third per wrong answer. Which pays more?

Same knowledge, different behavior

A tie. Guessing earns 0.25 minus a third of 0.75, exactly zero. The threshold, a third over four thirds, is one quarter. Same model, same knowledge. The scoring rule alone decides whether bluffing pays, and that's the behavior selection rewards. So hallucination is the model doing what it was trained to do: emit a fluent continuation, even when its probability on the truth is thin. Fine-tuning on unknown facts, and grading that gives I don't know zero credit, both turn that uncertainty into confident guesses.

Where do confident false answers come from?

Ask a model for the birth year of a minor 19th-century chemist. It may answer "1847" fluently and without any hedge, and be wrong. Nothing in the network looks facts up or checks them. So where does a specific, confident, false answer come from? And why does training make it *more* likely rather than less?

Rare facts: the shape is learned, not the value

Pretraining minimizes next-token cross-entropy. A famous person's birth year is repeated across the corpus, so probability concentrates on it. A person mentioned once or never still fits a learned pattern: "born in" is followed by a plausible four-digit year. So $p_\theta$ spreads over many candidate years. Generation must emit *some* token, and a wrong year reads exactly as fluently as the true one.

SFT on unknown facts teaches bluffing

Suppose an SFT demonstration says "Dr. X was born in 1852" but the base model barely knows Dr. X. A few demos mostly fail to turn this into real knowledge. The model picks such facts up slowly, if at all. What the gradient does reinforce quickly is "state a specific answer in this format", even when the model's internal evidence is weak. The lesson learned is *when asked, assert*. Hedges the base model might have produced get trained away. Its stated confidence then stops tracking what it actually knows, which is a loss of calibration.

Grading that never rewards abstaining

Most tests score 1 for correct and 0 for wrong **or** "I don't know". Let $q$ be the chance that the model's answer is right: $$\mathbb{E}[\text{guess}] = q,\qquad \mathbb{E}[\text{abstain}] = 0.$$ Guessing wins for every $q>0$. If each wrong answer costs $c$, then $\mathbb{E}[\text{guess}] = q - c(1-q)$. Guessing now beats abstaining only when $q > \tfrac{c}{1+c}$. When people pick models, or adjust how they train them, to raise 1/0 scores, confident guessers come out ahead.

Dr. X's birth year, scored three ways

The model's belief: 1852: 0.25, 1850: 0.20, 1848: 0.15, others: 0.40. If it is calibrated, its best guess, 1852, is right with $q=0.25$. Here is what maximizes expected score: - **1/0/0 scoring:** guessing earns 0.25 and abstaining earns 0, so guess. - **Penalty $c=1$:** guessing earns $0.25-0.75=-0.5$ and the threshold is $\tfrac12$, so abstain. - **Penalty $c=\tfrac13$:** guessing earns $0.25-\tfrac13(0.75)=0$, a tie (threshold $\tfrac14$). The scoring rule decides whether bluffing pays, and that is the behavior selection rewards. The knowledge is the same in all three cases.

Remember

Hallucination is the model doing what it was trained to do: emit a fluent, plausible continuation even when its probability mass on the true fact is spread thin. Fine-tuning on facts the model doesn't know, and grading that gives "I don't know" zero credit, both teach it to turn that uncertainty into confident guesses.

On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.