Abstract
Large Language Models (LLMs) frequently exhibit "Context Faithfulness Hallucinations," where they prioritize internal pre-training biases over provided reference text in Retrieval-Augmented Generation (RAG) tasks. This paper introduces Dynamic Attention-Guided Context Decoding (DAGCD), a lightweight, single-pass decoding strategy. By leveraging internal attention signals and token-level uncertainty, DAGCD dynamically adjusts output probabilities to ensure models remain faithful to the retrieved context. Experimental results demonstrate significant accuracy improvements, particularly in adversarial scenarios where internal knowledge conflicts with provided evidence.
Introduction
In Retrieval-Augmented Generation (RAG) systems, external documents are provided to LLMs to ensure factual accuracy and ground responses in specific data. However, LLMs often display a "stubbornness" known as context faithfulness hallucination. Even when the correct answer is present within the prompt, the model may generate a response based on its pre-training data or hallucinate a plausible but incorrect answer.
Existing solutions to this problem often involve multiple decoding passes, which are computationally expensive and slow, or lack interpretability. The authors of this study identified that when a model is prone to hallucinate, its internal uncertainty (entropy) typically spikes. Furthermore, while the correct "gold" token may not be the top-ranked choice in these instances, it is almost always present within the top 10 candidates. DAGCD aims to "nudge" the model toward these context-grounded tokens in real-time without the overhead of multi-pass decoding.
The DAGCD Framework
DAGCD operates during a single decoding pass through three integrated steps:
1. Context Utilization Detection
The researchers observed that specific Transformer attention heads are specialized in "looking" at the context. By training a simple Logistic Regression (LR) classifier on these "attention ratios," the system identifies which tokens in the context are being utilized by the model at any given moment. This detector is remarkably efficient, requiring as few as 100 training samples to achieve an AUC of over 0.96.
2. Utilization Distribution Construction
Using signals from the most informative attention heads, the framework constructs a "utilization score" for every token in the vocabulary that appears in the provided context. This score represents the likelihood that a specific token is the intended grounded output.
3. Dynamic Probability Adjustment
The final output probability is adjusted using a dynamic formula:
$$P' = P + \alpha H_{norm}(P) \cdot U_{top}$$
In this equation, $H_{norm}(P)$ represents the normalized entropy (uncertainty). When the model is highly uncertain, the system provides a larger "boost" to tokens identified as contextually relevant ($U_{top}$). The parameter $\alpha$ serves as a scaling factor to control the strength of the intervention. Because this occurs in a single pass, DAGCD maintains the theoretical time complexity of standard greedy decoding.
Experimental Setup
The framework was evaluated using the MrQA repository across a diverse set of open-book Question-Answering (QA) benchmarks:
- Multi-Hop Reasoning: HotpotQA.
- Long-Form Retrieval: TriviaQA and SearchQA.
- Single-Paragraph Extraction: SQuAD and NewsQA.
- Document-Level QA: Natural Questions (NQ).
- Adversarial Scenarios: NQ-Swap, a dataset specifically designed to test if a model can prioritize provided (potentially counter-intuitive) context over its internal knowledge.
Key Results and Insights
DAGCD demonstrated substantial improvements across LLaMA-2 and Mistral model families. On Mistral-7B, the method improved Exact Match (EM) scores by an average of 17.67% across all datasets.
Robustness in Knowledge Conflict
The most striking results appeared in the NQ-Swap adversarial task. Mistral-7B saw a 74.52% EM improvement, proving that DAGCD effectively forces the model to trust the provided text over its internal "memory."
The Role of Uncertainty and Attention
The study yielded several critical insights into LLM behavior:
- Uncertainty as a Compass: There is a strong negative correlation between token-level entropy and faithfulness. High uncertainty is a reliable indicator that a model is about to ignore its context.
- Proximity of Truth: In 66% of cases where the model failed, the correct token was already in the top 10 of the probability distribution, just not at the top.
- Specialized Attention: Only a small subset (5-10%) of attention heads are "context specialists." Focusing on these specific heads allows for high accuracy with minimal data.
Conclusion and Future Work
DAGCD provides a computationally efficient path toward more reliable RAG systems. Unlike Contrastive Active Decoding (CAD), which requires multiple passes, DAGCD is viable for production environments.
However, limitations remain. The scaling factor $\alpha$ currently requires empirical calibration (typically $\alpha=2$ for base models and $\alpha=4$ for chat-tuned models). Future work will focus on automating this adjustment. Additionally, the authors note that extremely noisy or misleading contexts may still challenge the classifier, and further research is needed to apply this attention-guided approach to open-ended creative writing and complex dialogue tasks.
Summary updated