Where Hallucinations Come From
Introduction
From Logits to Probabilities (Softmax), Greedy Decoding vs Sampling, Temperature, Top-k & Top-p Explained, Controlling Output: Stop Sequences, Max Tokens, Penalties and The Probabilistic Nature of AI (Determinism, Seeds) built one picture: a model gives every possible next token a share, a token is picked from those shares, and the loop goes again. This lesson is about the failure that picture leads to: a hallucination, an answer that reads well and is wrong.
Three causes, each measured or quoted below: the loop that writes never checks what it writes against the world; a model writes something even when it has nothing to go on; and the way models are scored rewards a guess over "I don't know". Then where it comes most, whether a model can tell, and how to design around it.
What a Hallucination Is
Ji and colleagues' survey of the field, in ACM Computing Surveys, defines a hallucination as generated content that is "nonsensical or unfaithful to the provided source content", and names two kinds:
- Intrinsic: "The generated output that contradicts the source content." You paste a contract, and the summary misstates a clause.
- Extrinsic: "The generated output that cannot be verified from the source content": the source neither supports it nor contradicts it. The survey adds that it "is not always erroneous": a date the source never gave can still be right. A citation to a paper that does not exist is extrinsic and false.
With no source at all, the same word covers what Kalai and colleagues (2025) describe: "producing plausible yet incorrect statements instead of admitting uncertainty." Either way the wrong text comes out of the same loop as the right text, in the same tone, which is what makes it hard to spot.
Plausible Is Not True
At every step the model gives each possible next token a share, one is picked, and it is written; then the loop goes again. No step in that loop checks the text against the world. Kalai and colleagues put the consequence in one line: "If incorrect statements cannot be distinguished from facts, then hallucinations in pretrained language models will arise through natural statistical pressures."
Measured on the answer-tuned tiny GPT of Supervised Fine-Tuning (SFT): Teaching Instruction-Following, asked what a Python function does. Its confidence below is the geometric mean of the shares it gave each character of its answer and the end of the answer.
- A real function: "What does
inspect.iscodedo?" got "Return true if the object is a type." at a confidence of 0.911. (Its docstring: "Return true if the object is a code object.") - A made-up one: "What does
inspect.imatmuldo?", a name that does not exist in Python, got the same words at 0.910.
Over 40 real functions and 40 made-up ones, all 40 and 40 answers ended the way its answers end, and the median confidence was 0.81 for the real ones and 0.80 for the made-up ones; 17 of the made-up names got an answer surer than the median real one. The model is tiny, and 0 of its 40 real answers matched the docstring: the point is that its confidence was the same whether the function existed or not.

It Always Writes Something
A decoding loop picks a token at every step; it has no step that stops and says "I don't know". A model can still be trained to give that answer as a token. Whisper was: its paper says that when a segment of audio has no speech, the model is trained to predict a <|nospeech|> token. Then the system around the model decides what to do with it.
Measured on Whisper base.en, the numpy copy from The Transformer Architecture — The Big Picture, decoded as Whisper's own code decodes with timestamps off:
- Ten seconds of digital silence: at the first step the no-speech token got 94% of the share. It still wrote
you, at 43% (Youhad 29%,Thank2%), with a mean log-probability of-0.43. - Ten seconds of faint white noise: 89% for no speech; it wrote
youat 3%, a mean of-1.75.
Whisper's transcribe() reads both numbers: it skips a window when the no-speech share is over its default of 0.6, unless the mean log-probability is over its default of -1.0. Its code, as saved on 20 November 2026, says so in a comment: "don't skip if the logprob is high enough, despite the no_speech_prob". The same rule, on the lab's numbers:
clips = { # the lab's numbers: no-speech share, mean log-probability, text written
"silence": (0.9372, -0.4319, " you"),
"faint noise": (0.8907, -1.7522, " you"),
"bank in noise": (0.1741, -0.1660, " to open the bank account today."),
}
for name, (no_speech, mean, text) in clips.items():
skip = no_speech > 0.6 # as Whisper's transcribe() does, with its defaults
if mean > -1.0:
skip = False # sure enough of what it wrote: keep it
print(f"{name:14} {'skipped' if skip else 'kept: ' + text.strip()}")
It prints:
silence kept: you
faint noise skipped
bank in noise kept: to open the bank account today.
The silence is kept as "you" because Whisper was sure of what it wrote; the faint noise is skipped because it was not. (When the mean is below -1.0 and the window does not count as silence, transcribe() decodes it again with sampling; every window here keeps its first pass.) faster-whisper uses the same rule with the same defaults.
On real recordings, Koenecke and colleagues (2024) found that "roughly 1% of audio transcriptions contained entire hallucinated phrases or sentences which did not exist in any form in the underlying audio", that "38% of hallucinations include explicit harms", and that they come more often for people "who speak with longer shares of non-vocal durations".
Why Models Guess: the Scoring
If a model can be unsure, why does it answer anyway? Kalai and colleagues' answer (2025, from OpenAI and Georgia Tech): "Like students facing hard exam questions, large language models sometimes guess when uncertain", and "language models hallucinate because the training and evaluation procedures reward guessing over acknowledging uncertainty".
The exam is the scoring. Under a test that gives 1 point for a right answer and nothing otherwise, "guessing when unsure maximizes the expected score under a binary 0-1 scheme that awards 1 point for a correct answer and none for blanks or IDKs." And "Many language-model benchmarks mirror standardized human exams, using binary metrics such as accuracy or pass-rate." Their fix is to state a confidence target in the instructions: "Answer only if you are > t confident, since mistakes are penalized t/(1 − t) points, while correct answers receive 1 point, and an answer of “I don’t know” receives 0 points." The arithmetic, for a guess that is right with probability p:
def expected(p, cost):
# right scores 1, "I don't know" scores 0, wrong costs `cost`
return p - (1 - p) * cost
for t in (0, 0.5, 0.9):
cost = t / (1 - t)
scores = [round(expected(p, cost), 2) for p in (0.3, 0.6, 0.95)]
print(f"t={t}: wrong costs {cost:g}, guesses score {scores}")
It prints:
t=0: wrong costs 0, guesses score [0.3, 0.6, 0.95]
t=0.5: wrong costs 1, guesses score [-0.4, 0.2, 0.9]
t=0.9: wrong costs 9, guesses score [-6.0, -3.0, 0.5]
With no cost for a wrong answer, a guess never scores below 0, the score of "I don't know", so guessing always pays. With a cost of 1 (t of 0.5), a guess at 0.3 loses; with a cost of 9 (t of 0.9), only a guess above 0.9 pays.
Where It Comes Most
Hallucinations are not spread evenly. The sources point to these places:
- Facts seen once, or never. Kalai and colleagues: "if 20% of birthday facts appear exactly once in the pretraining data, then one expects base models to hallucinate on at least 20% of birthday facts", while "Large language models seldom err on frequently referenced facts". Facts absent from the training data are the extreme case, and anything after a model's training cutoff is absent from it.
- Exact details. "Bluffs are often overconfident and specific, such as "September 30" rather than "Sometime in autumn" for a question about a date." Exact dates, numbers, quotes, citations and API names are easy to write and hard to recall.
- The middle of a long context. Liu and colleagues (2023): "performance is often highest when relevant information occurs at the beginning or end of the input context, and significantly degrades when models must access relevant information in the middle of long contexts". A fact you gave the model can still be missed.
- Noise and silence in audio, as measured above.
- Common misconceptions. On TruthfulQA, questions some people answer wrong from a false belief, "The best model was truthful on 58% of questions, while human performance was 94%." "Models generated many false answers that mimic popular misconceptions", and "The largest models were generally the least truthful." A bigger model is not always a more truthful one.
See It: Nothing to Hear
Whisper base.en on nine clips: speech, speech in noise, and no speech at all. Each decode shows the sound it reads, the share it gives no speech at the first step, every token it writes with its share (words nobody said in red), the least sure step beside the two tokens that nearly won it, every step's log share with their mean, and the gate. Try Whisper's rule, the no-speech share alone, and no gate at all. Every number is the lab's.

Three things to see. The silence is kept as "you" under Whisper's rule, because its mean log-probability is high. A gate on the no-speech share alone skips it, and keeps every clip of speech here, even the soft one at 34%. And the bank account in louder noise comes back as "to open the bank account today." with a mean of -0.17, surer than the soft Paris at -0.29, which it writes word for word: three words nobody said, written with more confidence than a right answer. Even the clean Paris comes back as "the capital of France as Paris.", "as" for "is".
Do Models Know What They Know?
Sometimes, if they are asked the right way. Kadavath and colleagues (2022): "We first show that larger models are well-calibrated on diverse multiple choice and true/false questions when they are provided in the right format." They also trained models to predict "the probability that "I know" the answer to a question", and found that models "perform well at predicting P(IK) and partially generalize across tasks, though they struggle with calibration of P(IK) on new tasks."
So a signal of not knowing can exist, as Whisper's no-speech token does. The decoding loop does not read it: a system has to, as Whisper's transcribe() reads its two numbers. And a signal is not proof. Whisper was surer of the noisy bank account it got wrong than of the soft Paris it got right, and the tiny GPT was as sure of a function that does not exist as of one that does.
Reducing It
None of these makes a model always right. Each makes a wrong answer rarer or easier to catch.
- Answer from sources. Give the model the facts instead of asking it to recall them. Shuster and colleagues (2021) found that retrieval-augmented models, "as verified by human evaluations, substantially reduce the well-known problem of knowledge hallucination in state-of-the-art chatbots." RAG & Retrieval Systems is the course on it, and a retrieved fact in the middle of a long context can still be missed.
- Allow "I don't know". Anthropic's guide: "Explicitly give Claude permission to admit uncertainty. This technique can drastically reduce false information."
- Quote, then answer, then cite. For long documents, "ask Claude to extract word-for-word quotes first before performing its task", and "Make Claude's response auditable by having it cite quotes and sources for each of its claims."
- Ask again and compare. "Run Claude through the same prompt multiple times and compare the outputs. Inconsistencies across outputs could indicate hallucinations."
- Gate on a signal. Whisper's rule reads two numbers before a window is shown. faster-whisper can also filter out the parts of the audio without speech before decoding, with its
vad_filter, which is off by default.
Not on the list: a lower temperature. Temperature changes how a token is picked from the shares, not the shares; the tiny GPT and Whisper above were both greedy, at temperature 0, when they wrote what they wrote.
What It Means for Your Code
- Treat factual output as unchecked until it is checked: citations, numbers, names, dates and API names above all. A confident tone is not evidence: the made-up function got the same confidence as the real one.
- Give the model the facts it needs, and make its answers checkable with quotes and sources.
- Read the signals you have. For speech, Whisper's no-speech share and mean log-probability; for a language model, an explicit "I don't know" that your prompt allows.
- Score "I don't know" above a wrong answer in your own evaluations, or your tests will reward guessing the way the exams in Kalai and colleagues' paper do.
- Measure on your own data. Rates differ by task and by input: on real recordings, by how long a speaker pauses.
- Show sources in the product, so people can check what matters to them.
Check Yourself
Eight questions on the ideas above. Each answer says why, and where to look again.
Check Yourself: Where Hallucinations Come From
1 / 8Multiple choice
Multiple choice
Multiple choice
Multiple choice
Multiple choice
Multiple choice
Multiple choice
Multiple choice
Key Takeaways
- A hallucination is content "nonsensical or unfaithful to the provided source content". Intrinsic ones contradict the source; extrinsic ones cannot be checked against it, and can still be true.
- No step checks the world. The loop gives each token a share, picks one and writes it: a wrong answer comes out in the same tone as a right one. The tiny GPT answered a made-up function as surely as a real one.
- It always writes something, unless a token for "nothing here" is trained, as Whisper's no-speech token is, and the system reads it: Whisper kept "you" from silence because it was sure of it.
- The scoring rewards guessing. With 1 point for right and nothing for "I don't know", a guess always pays; a cost for wrong answers changes that (Kalai and colleagues, 2025).
- It comes most with facts seen once or never, exact details, the middle of a long context, noise and silence, and common misconceptions.
- Reduce it: answer from sources, allow "I don't know", quote and cite, ask again and compare, gate on a signal, and check what matters.
That ends the section on how a model writes. The next section turns to building: Anatomy of an LLM API Call (Messages, Roles, Params) is where it starts.