Gradient-guided Attention Map Editing: Towards Efficient Contextual Hallucination Mitigation

Yu Wang, Jiaxin Zhang, Xiang Gao, Wendi Cui, Peng Li, Kamalika Das

Abstract

Large Language Models (LLMs) frequently exhibit contextual hallucinations, prioritizing self-generated text over provided input context. We present Guided Attention Map Editing (GAME), an inference-time intervention that surgically adjusts attention maps using gradient-based edit directions. By monitoring "Lookback Ratios" across attention heads, GAME identifies and corrects potential hallucinations. Our method achieves a 10% improvement in non-hallucination rates on summarization tasks while operating 7x faster than state-of-the-art baselines.

Introduction

Even when provided with accurate source information—such as in Retrieval-Augmented Generation (RAG) or summarization—LLMs often suffer from contextual hallucination. This phenomenon occurs when a model prioritizes its own previously generated tokens over the actual input context, leading to outputs that are fluent but factually incorrect.

Existing mitigation strategies often rely on "passive" techniques, such as generating multiple candidate responses and selecting the best one via a classifier. However, these methods are computationally expensive and fail to address the underlying architectural cause: a suboptimal distribution of attention. This paper introduces an "active" intervention that modifies the model's internal mechanics during inference to balance context-awareness and generation fluency.

The GAME Framework

The authors propose Guided Attention Map Editing (GAME), a four-step framework designed to surgically intervene in the attention mechanism.

1. Feature Extraction: The Lookback Ratio

The core feature used by GAME is the Lookback Ratio (LR). For every attention head across all layers, the system calculates the ratio of attention directed toward the input context ($X$) versus the attention directed toward the already generated text ($Y$).

Calculation of the Lookback Ratio (LR) across multiple attention heads and layers to detect hallucination signals.

2. Hallucination Detection and Gradient Guidance

A linear classifier monitors these LR features in real-time. When a high probability of hallucination is detected for a specific "chunk" of text, GAME triggers an intervention. Instead of a uniform adjustment, GAME calculates the gradient of the hallucination score with respect to the attention features. This produces an edit direction ($\Delta$), a signed vector indicating which heads require more context focus and which should maintain their focus on generation to preserve linguistic fluency.

3. Strategic Intervention

The model regenerates the problematic chunk using a modified attention map. This adjustment incorporates a prior bias—specifically a reverse-positional bias ($1/i$)—to counteract the natural decay of attention over long distances. This bias is scaled by the gradient-informed edit direction to ensure precise modification.

Overview of the Decoder architecture and the resulting Attention Map partitioned into context (X) and generated text (Y).

Experimental Evaluation

The researchers evaluated GAME using Llama2-7b and Phi3-mini across several challenging tasks:

  • Summarization: Evaluated on XSum (Extreme Summarization), which requires high levels of abstraction and is prone to hallucination.
  • Open-book QA: Tested on NQ-Open and Trivial QA, where models must extract answers from provided documents.
  • Ground Truth: GPT-4o served as the "gold standard" judge for labeling hallucinations in the training set for the linear classifier.

Key Results

  • Improved Factuality: On the XSum task, GAME increased the non-hallucination rate for Llama2-7b from 49% to 59%.
  • Efficiency Gains: GAME achieved a 7x speedup over previous state-of-the-art baselines, averaging 2.69 seconds per sample compared to 18.93 seconds.
  • Surgical Precision: The use of gradients confirmed that naively forcing all heads to look at context is counterproductive; different heads serve different roles (e.g., maintaining grammar vs. factual grounding).
  • Robustness: The method showed consistent performance gains across different model sizes, from the 2B parameter Phi3 to the 7B parameter Llama2.

Conclusion and Future Work

GAME represents a significant advancement in efficient hallucination mitigation by moving from passive selection to active, gradient-guided editing. While currently reactive—fixing "bad" chunks after detection—future work aims to make the process proactive, preventing hallucinations during the initial token generation. Additionally, the authors suggest that learning the "prior bias" from data, rather than using a heuristic, could further refine the system's precision.

Summary updated

BibTeX
@inproceedings{wang2025gradient,
  author = {Yu Wang and Jiaxin Zhang and Xiang Gao and Wendi Cui and Peng Li and Kamalika Das},
  title = {{Gradient-guided Attention Map Editing: Towards Efficient Contextual Hallucination Mitigation}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2025},
  doi = {10.18653/v1/2025.findings-naacl.458},
}
Figure