Mechanisms of non-factual hallucinations in language models

Lei Yu, Meng Cao, Jackie Chi Kit Cheung, Yue Dong

Abstract

Large Language Models (LLMs) frequently generate non-factual hallucinations, yet the internal mechanisms driving these errors remain poorly understood. This research moves beyond "black-box" detection by employing mechanistic interpretability to locate the specific transformer components responsible for factual failures. The authors identify a two-stage fact-recall pipeline consisting of knowledge enrichment in early-layer MLPs and answer extraction in late-layer attention heads. By distinguishing between failures in these two stages, they propose Mechanistic Hallucination Mitigation (MHM), a targeted fine-tuning approach that significantly reduces hallucinations while preserving existing model knowledge.

Introduction

Despite the rapid advancement of Large Language Models, their tendency to produce "non-factual hallucinations"—confident but incorrect statements—remains a primary barrier to their deployment in high-stakes environments. Traditional research has largely treated LLMs as black boxes, focusing on external indicators such as predictive uncertainty or logical inconsistency to identify errors. While useful for detection, these methods fail to explain the internal causal chain that leads to a hallucination.

This paper adopts a "white-box" perspective, using mechanistic interpretability to trace the flow of information through the transformer architecture. By identifying the specific layers and heads responsible for factual errors, the researchers demonstrate that hallucinations are not a monolithic phenomenon but rather the result of distinct internal pipeline failures.

The Fact-Recall Pipeline

The researchers conceptualize factual generation as a two-step internal process:

  1. Knowledge Enrichment: In the lower layers, Multi-Layer Perceptrons (MLPs) retrieve the semantic attributes of a subject from the model's internal parameters.
  2. Answer Extraction: In the upper layers, attention heads select the relevant attribute from the enriched representation to produce the final token.

To validate this pipeline, the study utilizes two primary interpretability techniques. First, the Logit Lens is used to project intermediate hidden states into the vocabulary space, revealing the tokens the model considers at each layer. Second, Causal Mediation Analysis (Causal Patching) is employed to identify which components are most critical to the final output. By injecting noise into a model's input to induce a hallucination and then "patching" specific internal representations with clean versions, the authors can pinpoint the exact modules that restore factual accuracy.

A Taxonomy of Hallucinations

The investigation reveals two primary "breaking points" in the fact-recall pipeline, leading to a new taxonomy of hallucinations:

1. Knowledge Enrichment Hallucinations

These occur when the model fails to retrieve the necessary information from its internal database (the MLPs) in the early layers. In these instances, the model essentially "doesn't know" the answer. These failures typically manifest as nonsensical or unrelated outputs and are highly correlated with high predictive uncertainty.

2. Answer Extraction Hallucinations

These occur when the correct information is successfully retrieved in the early layers, but the upper-layer attention heads fail to select it. Instead, the model is often "confused" by related but incorrect attributes—for example, providing a person's country of birth when asked for their city of birth. These errors are particularly deceptive because they often involve strong prior associations, leading the model to produce a plausible-sounding but incorrect answer with high confidence.

Mechanistic Hallucination Mitigation (MHM)

Building on these insights, the authors developed Mechanistic Hallucination Mitigation (MHM). Unlike standard fine-tuning, which updates all parameters uniformly, MHM uses a surgical approach:

  • MLP Targeting: The objective encourages early-layer MLPs to more effectively retrieve information related to the correct answer.
  • Attention Targeting: The objective trains upper-layer attention heads to better distinguish the correct attribute from "distractor" attributes.

Experimental Results

The MHM method was evaluated against several benchmarks, including Natural Questions (NQ), ParaRel, and TruthfulQA, using architectures such as Llama-2, Pythia, and GPT-J.

  • Performance: On the Natural Questions dataset, MHM improved the accuracy of Llama-2-7B to 47.6%, significantly outperforming standard Supervised Fine-Tuning (41.8%) and specialized methods like Decoding by Contrasting Layers (DoLa, 27.0%).
  • Specificity: A critical metric in hallucination mitigation is specificity—the ability to fix errors without causing the model to forget facts it already knows. MHM achieved a specificity of over 95%, demonstrating that targeted mechanistic interventions are less likely to cause catastrophic forgetting than broad fine-tuning.
  • Generalization: The discovery of the two-mechanism failure mode held true across all tested architectures, suggesting that the enrichment-extraction pipeline is a fundamental characteristic of how transformers process factual data.

Conclusion and Limitations

By moving from black-box detection to white-box interpretation, this research provides a clearer understanding of why LLMs hallucinate. The identification of the enrichment and extraction stages allows for more precise interventions that improve factual reliability without compromising model performance.

However, the authors note certain limitations. The Logit Lens remains an approximation of internal states, and the study focused primarily on short, cloze-style factual queries. Future work will involve extending these mechanistic insights to long-form generation and complex reasoning tasks, where the internal dynamics of hallucination may be even more intricate.

Summary updated

BibTeX
@inproceedings{yu2024mechanisms,
  author = {Lei Yu and Meng Cao and Jackie Chi Kit Cheung and Yue Dong},
  title = {{Mechanisms of non-factual hallucinations in language models}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  doi = {10.18653/v1/2024.findings-emnlp.466},
}
Figure