Mechanistic Understanding and Mitigation of Language Model Non-Factual Hallucinations

Lei Yu, Meng Cao, Jackie C. K. Cheung, Yue Dong

Abstract

Large Language Models (LLMs) frequently generate confident but factually incorrect statements, a phenomenon known as hallucination. This paper moves beyond black-box detection to identify the internal mechanistic failures causing these errors. We identify two distinct failure modes: knowledge enrichment failures in early MLP layers and answer extraction failures in later attention heads. Based on these insights, we introduce Mechanistic Hallucination Mitigation (MHM), a surgical fine-tuning approach that reduces hallucinations while preserving the model's broader factual integrity.

Introduction

Despite their success, LLMs remain prone to hallucinations. Most existing research treats this as a black-box problem, using external signals like predictive uncertainty to detect errors. However, these methods often provide contradictory signals and fail to explain the underlying cause. This study employs mechanistic interpretability to localize the specific internal components—MLPs and attention heads—that deviate from normal function during a hallucination.

Mechanistic Localization of Hallucinations

To trace the flow of information, the authors utilize two primary techniques across Llama-2, Pythia, and GPT-J:

  1. Logit Lens: Projecting intermediate hidden states into the vocabulary space to observe the model's internal "thought process" at each layer.
  2. Causal Mediation Analysis: Identifying influential components by "patching" states from a truthful run into a hallucinating run to see which components can correct the error.
Localization of failure modes across layers and components for Llama, Pythia, and GPT-J.

Analysis reveals that factual recall is a two-stage pipeline: lower-layer MLPs enrich the subject with attributes, and upper-layer attention heads extract the specific attribute required by the query. Hallucinations occur when this pipeline breaks at either stage. Causal tracing confirms that fixing lower-layer MLPs addresses enrichment errors, while fixing upper-layer attention heads addresses extraction errors.

Two Distinct Failure Modes

The research identifies two primary internal "failure modes" that lead to non-factual outputs:

  • Knowledge Enrichment Hallucination (The "Clueless" Model): In this mode, the model fails to retrieve the necessary fact in the early MLP layers, often due to the obscurity of the subject. This is characterized by high predictive uncertainty.
  • Answer Extraction Hallucination (The "Confused" Model): Here, the MLPs successfully retrieve the correct fact, but the upper-layer attention heads fail to select it, often distracted by attributes with stronger prior associations.
Schematic representation of (a) Knowledge enrichment and (b) Answer extraction hallucinations.

Mechanistic Hallucination Mitigation (MHM)

Leveraging these localizations, the authors propose Mechanistic Hallucination Mitigation (MHM). Unlike standard Supervised Fine-Tuning (SFT), MHM uses a surgical objective:

  • It increases the probability of the true answer in intermediate MLP outputs of middle layers.
  • It suppresses the hallucinated answer in attention head outputs of the same layers.

Key Results

Evaluated on benchmarks like Natural Questions (NQ) and TruthfulQA, MHM demonstrated superior performance:

  • Accuracy: On NQ, MHM achieved 47.6% accuracy for Llama-2-7B, significantly outperforming standard SFT (41.8%) and DoLa (27.0%).
  • Specificity: MHM preserved over 95% of the model's existing correct knowledge, avoiding the "catastrophic forgetting" often seen in other model-editing methods like MEND.
  • Consistency: These mechanisms were consistent across different model families, suggesting a fundamental property of the Transformer architecture.

Conclusion and Future Work

This work demonstrates that hallucinations are not monolithic but result from specific architectural failures. While the current study focuses on simple factual queries, future work will explore whether these mechanisms apply to complex, multi-step reasoning. Additionally, these insights could lead to real-time monitoring systems that alert users when the internal enrichment/extraction pipeline shows signs of failure.

Summary updated

BibTeX
@inproceedings{yu2024mechanistic,
  author = {Lei Yu and Meng Cao and Jackie C. K. Cheung and Yue Dong},
  title = {{Mechanistic Understanding and Mitigation of Language Model Non-Factual Hallucinations}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  doi = {10.18653/v1/2024.findings-emnlp.466},
}
Figure