Preprint
Large Language Models

Contextual Hallucinations Mitigation in LLMs

Yung-Sung Chuang, Linlu Qiu, Cheng-Yu Hsieh, Ranjay Krishna, Yoon Kim, James Glass
July 9, 2024Conference on Empirical Methods in Natural Language Processing153 citations

153

Citations

25

Influential Citations

Conference on Empirical Methods in Natural Language Processing

Venue

2024

Year

Abstract

When asked to summarize articles or answer questions given a passage, large language models (LLMs) can hallucinate details and respond with unsubstantiated answers that are inaccurate with respect to the input context. This paper describes a simple approach for detecting such **contextual hallucinations**. We hypothesize that contextual hallucinations are related to the extent to which an LLM attends to information in the provided context versus its own generations. Based on this intuition, we propose a simple hallucination detection model whose input features are given by the ratio of attention weights on the context versus newly generated tokens (for each attention head). We find that a linear classifier based on these _lookback ratio_ features is as effective as a richer detector that utilizes the entire hidden states of an LLM or a text-based entailment model. The lookback ratio-based detector—**Lookback Lens**—is found to transfer across tasks and even models, allowing a detector that is trained on a 7B model to be applied (without retraining) to a larger 13B model. We further apply this detector to mitigate contextual hallucinations, and find that a simple classifier-guided decoding approach is able to reduce the amount of hallucination, for example by 9.6% in the XSum summarization task.

Analysis

Why This Paper Matters

Hallucination in large language models remains a critical barrier to their deployment in high-stakes applications. This paper addresses the specific problem of contextual hallucinations—where the model generates information not supported by the provided input. The authors propose a remarkably simple yet effective detector, Lookback Lens, based on the ratio of attention weights on the context versus generated tokens. This approach is interpretable, computationally lightweight, and transfers across tasks and model sizes, making it highly practical for real-world use.

The significance lies in the insight that attention patterns themselves encode a signal about whether the model is relying on the context or drifting into unsupported generation. By distilling this into a single scalar feature per head, the method achieves performance comparable to much more complex detectors that use full hidden states or entailment models. This opens the door to lightweight, on-the-fly hallucination detection without requiring additional large models or extensive fine-tuning.

Technical Contributions

  • Lookback Ratio Feature: For each attention head, the ratio of attention weights on the input context to those on newly generated tokens. This simple feature captures the model's reliance on context.
  • Linear Classifier: A logistic regression model trained on these features across all heads achieves strong detection performance, rivaling richer detectors.
  • Cross-Task and Cross-Model Transfer: The detector trained on a 7B model (e.g., Llama-2-7B) works on a 13B model without retraining, demonstrating robustness and generality.
  • Classifier-Guided Decoding: During generation, the detector's output is used to adjust token probabilities, reducing hallucination rates. On XSum summarization, this reduces hallucination by 9.6%.

Results

  • The Lookback Lens detector achieves comparable or better AUC than detectors using full hidden states or entailment models across multiple summarization and QA datasets.
  • Transfer from 7B to 13B model shows minimal performance drop, indicating the feature is model-agnostic.
  • Classifier-guided decoding reduces hallucination by 9.6% on XSum, with only a small impact on generation quality (e.g., ROUGE scores).

Significance

This work provides a practical, interpretable tool for improving LLM reliability. The simplicity of the approach means it can be easily integrated into existing pipelines without heavy computational overhead. The cross-model transfer property suggests that the attention-based signal is a fundamental property of LLMs, not an artifact of a specific architecture. This could lead to more robust hallucination mitigation strategies and deeper understanding of how LLMs process context versus generate freely.