Contents

Foundation Model Engineering

Manuscript updated (UTC) · Chapter source on GitHub · Cite this chapter (RIS)

On this page

18.3 Hallucination Detection

A fluent answer can be false, and a repeated answer can be consistently false. Hallucination detection therefore needs an explicit target: unsupported claims, contradiction of supplied evidence, incorrect world knowledge, or stochastic confabulation. These overlap but are not interchangeable. The detector must be evaluated against the failure that the application actually needs to catch.

1. Separate Faithfulness, Truth, and Uncertainty

A summary can faithfully repeat a false source. Conversely, an externally true statement can be unsupported by the documents the application promises to use. Evaluate source faithfulness and external factuality separately, with an explicit reference date and source-quality policy. In fiction or brainstorming, distinguish invented content requested by the user from a false factual assertion; novelty alone is not a hallucination label.

Next-token training rewards predictive likelihood, not a direct truth objective. That does not make self-attention “greedy”: attention is a representation mechanism, while greedy decoding is one choice of inference algorithm. Errors can originate in data, stale knowledge, ambiguous questions, retrieval, reasoning, or decoding. Neither stochastic sampling nor a separate verifier removes them by construction.

2. Token Entropy Is an Uncertainty Signal

For prompt xx, preceding tokens y<ty_{<t}, vocabulary VV, and next-token distribution ptp_t, predictive entropy is:

Ht=−∑v∈Vpt(v∣x,y<t)log⁡pt(v∣x,y<t).H_t=-\sum_{v\in V}p_t(v\mid x,y_{<t})\log p_t(v\mid x,y_{<t}).

Using natural logarithms gives units of nats. Specify whether probabilities come from raw model logits or the distribution after temperature, top-k/top-p, and constraints. For finite logits, compute log-softmax in FP32 and then sum −plog⁡p-p\log p; handle masked zero probabilities with the convention 0log⁡0=00\log0=0. Mask padding and align positions with the tokens actually being predicted. Logit access and full-vocabulary reductions have costs even when no additional model call is needed.

A sharp distribution can repeat a memorized falsehood. A broad one may express several equally valid words. Thus token entropy is not a calibrated factual-error probability. Evaluate it by domain, answer length, language, and decoding setting before choosing a review threshold.

3. Entropy over Meanings

Semantic entropy groups outputs by meaning rather than literal strings [1]. The Nature study targets confabulations, a subset of errors with unstable meanings across samples; it does not claim to detect every false belief [2]. SelfCheckGPT uses sampled consistency as a black-box signal, with evidence from its tested generation and annotation setup [3].

For an illustrative frequency estimator, draw NN answers, assign them to semantic clusters, and let p^(c)=nc/N\hat p(c)=n_c/N for cluster count ncn_c:

H^freq=−∑cp^(c)log⁡p^(c).\hat H_{\mathrm{freq}}=-\sum_c\hat p(c)\log\hat p(c).

This discrete sample-frequency estimator differs from estimators using sequence probabilities. Declare sampling temperature, seeds, sample count, normalization, and clustering method. Equivalence is question-dependent: names, negation, dates, numbers, and partial answers can make an NLI clustering model merge or split incorrectly. Mutual entailment is a useful operational test, not a perfect semantic oracle.

Semantic diversity and truth are different

Question: What is the capital of France?

Authored fixed responses and manual clusters for teaching; no NLI model or sampling runs here. The frequency estimator differs from estimators using sequence probabilities.

The interactive example has three authored responses and manual clusters. Compare consistent and correct with consistent but wrong: both have entropy zero. Three equally frequent meanings have log⁡3≈1.099\log 3\approx1.099 nats. Entropy measures dispersion, not truth. A detector based only on repeat variation can miss a shared misconception.

4. Evidence Verification Is a Separate Layer

For a grounded answer, decompose it into checkable claims and link each to source spans. Distinguish supported, contradicted, and insufficient-evidence outcomes. A neutral entailment result is not proof that a claim is false, and entailment from a low-quality document is not external truth.

A generator/verifier split can provide different evidence and failure signals, but their errors may be correlated through data, model lineage, or shared context. A smaller critic is not automatically an objective judge. Test numeric and temporal comparisons, multilingual paraphrases, citations that exist but do not support the claim, stale documents, and prompt injection in retrieved text. Use deterministic calculations or external records for facts that can be checked that way.

As of 2026-10-25, recent typed-decision preprints expose complementary limits: type-valid answers can follow misleading option names, and related predicates can produce incoherent probabilities [4] [5]. These are bounded studies of their tested revisions. A typed support/contradiction/unknown verifier still needs semantic, calibration, and coherence evaluation; see Section 16.7.

5. Choose a Detector for the Failure and Budget

SignalWhat it measuresMain limitation
Token entropyUncertainty over tokens under a defined distributionConfuses wording variation with uncertainty; confident falsehoods remain
Sample consistency / semantic entropyVariation in answer meaningMultiple generation and clustering calls; shared false beliefs remain
Evidence entailmentSupport from specified source spansCritic errors, missing context, and source quality
External verificationAgreement with a database, calculation, or executable testCoverage, freshness, permissions, and verifier correctness

Create human-adjudicated claim-level labels on isolated release data. Report precision/recall for each failure class, calibration where probabilities are used, and risk–coverage curves for abstention. Include supported answers falsely rejected, unsupported answers incorrectly released, critical-domain slices, and counts with uncertainty. Tune thresholds on a separate set; there is no universal entailment threshold of 0.90.

Measure total latency, tokens, retries, source-fetch errors, review cost, and answer quality after rewriting. Repeatedly asking the generator to fix a rejected claim can amplify a shared error or run indefinitely: cap attempts and escalate or abstain when evidence remains insufficient. Preserve detector/rubric/source versions, source spans, decision traces, and a known-good route. Canary changes, define critical-slice rollback gates, and rehearse switching back without restoring deleted or unauthorized evidence.

Detection supplies evidence for a release decision; it does not certify truth. The next section on scalable oversight asks how to obtain stronger supervision when the evaluator itself can be wrong.

Quizzes

Quiz 1: Why can a faithful summary still be false? It can accurately repeat an incorrect source. Faithfulness to supplied evidence and external factuality are distinct evaluation targets.

Quiz 2: What does zero semantic entropy establish? The sampled answers occupy one meaning cluster under the chosen estimator. They may still share the same false belief.

Quiz 3: Why is a neutral NLI judgment not a contradiction? The provided evidence may simply be insufficient. Treat support, contradiction, and unknown separately instead of forcing a binary truth decision.

Quiz 4: Why can a separate verifier share the generator’s errors? Shared training data, lineage, context, or misconceptions can correlate errors. Evaluate the combined system with independent evidence and adjudicated cases.

Quiz 5: How should a release threshold be chosen? Fit it on separate validation data using error costs, calibration, risk–coverage, and review capacity, then test untouched release slices with uncertainty. No fixed confidence value certifies truth.

References

  1. Kuhn, L., Gal, Y., & Farquhar, S. (2023). Semantic Uncertainty: Linguistic Invariances for Uncertainty Estimation in Natural Language Generation. ICLR paper.
  2. Farquhar, S., Kossen, J., Kuhn, L., & Gal, Y. (2024). Detecting hallucinations in large language models using semantic entropy. Nature 630, 625–630. Open-access paper.
  3. Manakul, P., Liusie, A., & Gales, M. J. F. (2023). SelfCheckGPT: Zero-Resource Black-Box Hallucination Detection for Generative Large Language Models. Paper.
  4. Sun, Y., et al. (2026). Type-Safe Is Not Error-Free: Typed Decision Models Follow the Option Name, Not the Definition Bound to It. October 8 preprint revision.
  5. Li, K., et al. (2026). Beyond Calibration: Do a Typed-Decision Model’s Probabilities Obey the Probability Axioms? September 27 preprint.