Hallucinations and limits
Why is it wrong with such confidence, and what can be done?
Lesson complete
If you like:
In twenty twenty-three, lawyers in New York filed a brief with a court that cited earlier cases, as is customary. The other side could not find most of them.
No voice: the lesson advances on its own with subtitles.
The voice for this lesson is being recorded: for now it advances on its own with subtitles.
Review modeComment on this stepI finished the lesson
What you will achieve
- Explain why a language model can give a false answer in the same confident tone as a true one, starting from how it is trained.
- Recognize three families of error (inventing, going stale because of the knowledge cutoff, and reasoning badly) and read whether a model’s confidence is calibrated.
- Choose mitigations and a level of verification proportional to the risk of each use.
Key ideas
- A hallucination is a fluent, confident answer that is false or unsupported. It is not an occasional breakdown: it follows from how a language model is trained.
- The model is trained to continue text plausibly. No part of that objective checks truth, and “I don’t know” only appears if it is a likely continuation.
- There are three families of error: inventing what it does not know, going stale (it knows nothing after its knowledge cutoff), and reasoning badly. Each is fixed differently.
- The internal probability is informative (more confidence, more right answers), but it is not always calibrated and a chat does not show it. The tone of the text says nothing about truth.
- Mitigations reduce, not eliminate: documents (RAG), tools, constrained outputs, and verification against an independent source, proportional to risk. Responsibility stays with whoever deploys the system.
What many people believe
Common belief If the model gives details and sounds sure, it probably knows; and if you ask whether it was wrong, it will tell you.
What is true A confident tone and rich detail are exactly what it learns best, and they say nothing about truth: “Pablo Neruda” came out at 4% probability and looks just like “Canberra,” at 69%. Asking the same model is not an independent check: the New York lawyer did it. You check against a source.
Check yourself
Four questions. No grade, no account: they just show whether the idea stuck.
Under the hoodFor those who want the math and the code. You do not need it to follow the course.
What training optimizes
Pretraining minimizes cross-entropy on real text:
The loss goes down when the model gives high probability to the piece that actually followed in the text. There is no “truth” variable in the formula: if the text contains an error, the objective rewards it all the same. Afterwards, tuning with human preferences (RLHF, lesson 28) adds another signal and can change calibration: the GPT-4 technical report (OpenAI, 2023) says the pretrained model was highly calibrated and that after post-training the calibration was reduced.
Facts seen only once
Kalai, Nachum, Vempala, and Zhang (2025) formalize the effect of rarity. Let be the fraction of training facts that appear exactly once (the “singleton rate,” from the Good–Turing missing-mass estimator). For arbitrary facts, with no pattern to generalize (like a birthday), a base model’s error satisfies, with probability at least 99%,
where is the number of examples, the set of plausible wrong answers for context , and measures miscalibration. In the authors’ words: if 20% of birthday facts appear exactly once in the pretraining data, one expects base models to hallucinate on at least 20% of birthday facts. It is a theoretical result for facts with no structure; it does not predict the rate of a specific model. Kandpal et al. (2023) observe it in practice: accuracy on factual questions grows with the number of pretraining documents related to the question.
Why tuning does not remove it: exams reward guessing
Kalai et al. (2025) also explain why hallucinations survive post-training: most evaluations that dominate leaderboards grade in a binary way (1 if right, 0 if not), and “I don’t know” scores 0. On a four-option multiple-choice exam, guessing is worth of a point on average and leaving it blank, 0: guessing always pays. They propose stating a confidence threshold in the instructions and penalizing each error with points, so that answering “I don’t know” is worth 0 and guessing stops paying when confidence is low.
Knowledge cutoff and what goes stale
Pythia was trained on The Pile (Gao et al., 2020), released on December 31, 2020: it cannot know anything later. Asked “Who won the 2022 FIFA World Cup?”, with the same five-example prompt and greedy decoding, Pythia-1.4B answers “Germany” with probability 0.46 (Argentina won, according to FIFA). It answers the same for 2014 (right) and for 2018 (wrong: France won). Old facts also linger: asked “What is the capital of Brazil?”, it answers “Rio de Janeiro” (0.53), which stopped being the capital on April 21, 1960, when Brasília was inaugurated (IBGE). Measurements: run-cutoff.py and run-qa.py in the lesson folder.
Calibration and expected calibration error
Split the answers into bins by confidence. With answers in bin , its mean accuracy and mean confidence :
(Guo et al., 2017). With ten equal-width bins, the lesson’s four hundred twenty-four questions give an ECE of ≈ 0.18 for Pythia-1.4B; the scene uses five bins so they read better. Almost all of the error is under-confidence: its answers are right more often than its probability says, partly because the probability of a string splits the mass among ways of writing the same thing (“Cervantes,” “Miguel de Cervantes”). Farquhar et al. (2024) group answers by meaning (semantic entropy) to correct that effect.
The lesson’s data are our own measurements, not a published benchmark: 424 general-knowledge questions written for the lesson (capitals, authors, dates, chemical symbols…), in English, with five solved examples in the prompt and greedy decoding. “Confidence” is the probability of the whole answer string. They are easy questions for a model trained on the internet: with truly rare facts, the error would be higher.
Answer or stay silent
If being right adds 1, being wrong subtracts , and staying silent is worth 0, and the probability of being right is , answering is worth on average. It pays to answer when
which is Chow’s reject rule (1970). With the threshold is . The rule holds if is calibrated. With Pythia’s raw probability the best measured thresholds are lower, precisely because of its under-confidence: you must recalibrate (for example, with temperature scaling, Guo et al., 2017) or set the threshold directly on your own data.
TruthfulQA, in detail
Lin, Hilton, and Evans (2021) wrote 817 questions in 38 categories (health, law, finance, politics…) that some people would answer wrongly because of a false belief. The best model (175-billion-parameter GPT-3 with a “helpful” prompt) was truthful on 58% of the questions, but only 21% of its answers were both truthful and informative: “I have no comment” counts as truthful. People reached 94%. Within each model family, the largest models were generally the least truthful, because they imitate the falsehoods in their texts better (“inverse scaling”).
In code
def bins(conf, ok, n_bins=5):
"""Group by confidence (equal-width bins) and return (ECE, [(n, mean confidence, mean accuracy), ...])."""
rows, ece = [], 0.0
for b in range(n_bins):
lo, hi = b / n_bins, (b + 1) / n_bins
idx = [i for i, c in enumerate(conf) if lo <= c < hi or (b == n_bins - 1 and c == 1.0)]
if not idx:
continue
c_mean = sum(conf[i] for i in idx) / len(idx)
a_mean = sum(ok[i] for i in idx) / len(idx)
ece += len(idx) / len(conf) * abs(a_mean - c_mean)
rows.append((len(idx), round(c_mean, 2), round(a_mean, 2)))
return round(ece, 3), rows
def threshold(conf, ok, t):
"""Answer only if confidence >= t. Returns (right, wrong, silent)."""
answered = [o for c, o in zip(conf, ok) if c >= t]
return sum(answered), len(answered) - sum(answered), len(conf) - len(answered)
conf = [0.97, 0.91, 0.83, 0.62, 0.55, 0.38, 0.31, 0.22, 0.12, 0.08]
ok = [1, 1, 1, 1, 0, 1, 0, 0, 1, 0]
print(bins(conf, ok))
# (0.211, [(2, 0.1, 0.5), (3, 0.3, 0.33), (1, 0.55, 0.0), (1, 0.62, 1.0), (3, 0.9, 1.0)])
print(threshold(conf, ok, 0.0)) # (6, 4, 0)
print(threshold(conf, ok, 0.5)) # (4, 1, 5)
What comes next
Retrieval (lesson 31) attacks the root of the problem: the fact missing from the model’s memory. Evaluating a system on your own cases, not on a demo, is lesson 34. The risks that go beyond quality (privacy, prompt injection, accountability) are in lesson 35.
Decision lens
What this idea means if your job is to decide, not to code.
- Classify each use by what an error costs and how easy it is to check. A brainstorm tolerates errors; a figure for a client, a legal citation, or a medical fact does not. Put human review where an error is costly.
- Do not accept “the model says it is sure” or “I asked whether it was correct” as verification: tone says nothing about truth. Ask for sources that can be checked and, where it matters, check them against the source.
- Ask the vendor: what error rate was measured on MY cases? Can it abstain, and at what threshold? Does it cite verifiable sources? What is its knowledge cutoff? A demo without an error rate is not evidence.
- Accountability is yours: in the Air Canada case (2024), a British Columbia tribunal held the company liable for what its chatbot said. Define an owner, a log of answers, a way to correct them, and an escalation point to a person.
Terms in this lesson
- Language model A model that, given some text (the context), gives a probability to every word or piece that can come next. It writes by adding one piece at a time.
- Autoregression Writing one piece at a time using what has already been written as input: each word produced becomes part of the context for the next.
- Token A piece of text (a word, a word fragment, a symbol, or a basic code) taken from the vocabulary. It is the unit the model reads and generates, and the unit you are billed for.
- Pretraining The first stage of training a language model: over a huge corpus, the model guesses the next piece of text again and again and adjusts its parameters to lower the error. The result is a base model.
- Base model A language model that has only gone through pretraining: it can continue texts, but it is not tuned to follow instructions or converse like an assistant.
- RLHF (reinforcement learning from human feedback) Tunes a model so that its answers earn more points from a reward model trained on human preferences, with a penalty (the KL “leash”) that keeps it close to the starting model.
- RAG (retrieval-augmented generation) A technique that, before generating, looks up in a collection of documents the chunks most similar to the question and includes them in the prompt, so the model answers from those sources without being retrained.
- Grounding Making every claim in the answer rest on a specific, checkable source, cited next to it.
- Tool use A model’s ability to ask for an external function to be run (look up data, calculate, buy) and to use its result. The model only writes the request; the program around it runs it.
- Human in the loop A design in which the system stops before certain actions (irreversible ones, or those over a limit) and waits for a person’s decision: approve, correct, or reject. It costs attention and only protects if the review is real.
- Hallucination A fluent, confident answer from a model that is false or backed by no source. It follows from predicting plausible text, not from checking facts.
- Calibration How closely a system’s confidence matches how often it is actually right: of the answers given at 70% confidence, it should be right about 70% of the time, like a good weather forecast.
- Knowledge cutoff The date after which the training data includes no more text. The model does not know what came later unless it is given as context, and it does not always warn that it does not know.
- Verification Checking an answer against an independent source (a document, a database, an expert) before acting on it; not against the same model. Its rigor should be proportional to the risk.
Full transcript
Sources
- Castel, P. K. (U.S. District Court, Southern District of New York) (2023). Opinion and Order on Sanctions, Mata v. Avianca, Inc., No. 22-cv-1461 (PKC) (S.D.N.Y. June 22, 2023)
- Biderman, S. et al. (2023). Pythia: A Suite for Analyzing Large Language Models Across Training and Scaling
- Gao, L. et al. (2020). The Pile: An 800GB Dataset of Diverse Text for Language Modeling
- Jiménez de Báez, Y., Gutiérrez de Velasco, L. (eds.), El Colegio de México y Fundación para las Letras Mexicanas (2008). Pedro Páramo: diálogos en contrapunto (1955-2005)
- Kalai, A. T., Nachum, O., Vempala, S. S., Zhang, E. (2025). Why Language Models Hallucinate
- Kandpal, N., Deng, H., Roberts, A., Wallace, E., Raffel, C. (2023). Large Language Models Struggle to Learn Long-Tail Knowledge
- Zhang, M., Press, O., Merrill, W., Liu, A., Smith, N. A. (2023). How Language Model Hallucinations Can Snowball
- FIFA (2022). FIFA World Cup Qatar 2022 (final: Argentina 3–3 France, 4–2 on penalties, December 18, 2022)
- IBGE (Instituto Brasileiro de Geografia e Estatística) (2001). Distrito Federal, Brasília: aspectos históricos
- U.S. National Archives (Milestone Documents) (1954). Brown v. Board of Education (1954), 347 U.S. 483
- NobelPrize.org (1903). Marie Curie – Facts (Nobel Prize in Physics 1903)
- NobelPrize.org (1911). Marie Curie – Facts (Nobel Prize in Chemistry 1911)
- O’Toole, G. (Quote Investigator) (2017). Insanity Is Doing the Same Thing Over and Over Again and Expecting Different Results
- LeCun, Y., Bengio, Y., Hinton, G. (Nature 521, 436–444) (2015). Deep learning
- Musée Rodin (1880). The Thinker
- Guo, C., Pleiss, G., Sun, Y., Weinberger, K. Q. (2017). On Calibration of Modern Neural Networks
- OpenAI (2023). GPT-4 Technical Report
- Chow, C. K. (1970). On optimum recognition error and reject tradeoff
- Lin, S., Hilton, J., Evans, O. (2021). TruthfulQA: Measuring How Models Mimic Human Falsehoods
- Farquhar, S., Kossen, J., Kuhn, L., Gal, Y. (2024). Detecting hallucinations in large language models using semantic entropy
- Magesh, V., Surani, F., Dahl, M., Suzgun, M., Manning, C. D., Ho, D. E. (2024). Hallucination-Free? Assessing the Reliability of Leading AI Legal Research Tools
- Civil Resolution Tribunal of British Columbia (2024). Moffatt v. Air Canada, 2024 BCCRT 149
CommentsThis lesson’s public conversation: questions, facts to check, ideas.
Comments live in GitHub Discussions, in the course’s public repository; writing one requires a GitHub account. They load from giscus.app when you open this section. The course reviewers read them, and if a change is accepted, it is applied in both languages. Open the thread on GitHub