Abstract
Large Language Models (LLMs) often encounter "knowledge conflicts" when provided external context contradicts their internal parametric knowledge. While Context-Aware Decoding (CAD) attempts to resolve this by amplifying contextual influence, its static weighting often leads to over-correction in low-conflict scenarios. We present AdaCAD (Adaptive Context-Aware Decoding), a strategy that dynamically adjusts the contrast weight at the token level using Jensen-Shannon Divergence (JSD). AdaCAD effectively balances internal and external knowledge, reducing hallucinations in high-conflict cases while maintaining robustness when context and internal knowledge align. Evaluations across multiple LLMs and benchmarks demonstrate that AdaCAD significantly outperforms existing decoding strategies in both accuracy and factual consistency.
Introduction
Large Language Models (LLMs) rely on two primary knowledge sources: parametric knowledge acquired during pre-training and contextual knowledge provided during inference (e.g., via Retrieval-Augmented Generation). A significant challenge arises when these sources conflict—for instance, when a model trained on 2022 data is presented with a 2024 context document stating that a previously recorded fact has changed.
Standard "greedy" decoding often defaults to internal parametric biases, ignoring relevant context. Conversely, existing interventions like Context-Aware Decoding (CAD) use a static contrast weight ($\alpha$) to amplify contextual signals. However, a fixed weight is problematic: if too high, the model "over-corrects" in low-conflict situations, leading to degenerate or nonsensical output; if too low, it fails to resolve genuine conflicts.
Methodology: Adaptive Context-Aware Decoding (AdaCAD)
AdaCAD addresses the limitations of static weighting by calculating a dynamic weight ($\alpha_t$) for every generated token. The core of this approach is the use of Jensen-Shannon Divergence (JSD) to measure the conflict between the model's output distribution with context and its distribution without context.
- Conflict Measurement: High JSD indicates a strong disagreement between parametric and contextual knowledge, prompting a higher $\alpha_t$ to prioritize the context. Low JSD suggests agreement, leading to a lower $\alpha_t$ to preserve the model's inherent linguistic capabilities and prevent over-correction.
- Decoding Formula: AdaCAD modifies output log-probabilities by adding a Pointwise Mutual Information (PMI) term, scaled by the dynamic $\alpha_t$.
- Warmup Mechanism: To handle long-form generation where initial tokens (e.g., "The") might show artificially low JSD, a warmup parameter ($\lambda$) ensures a minimum contrast weight during the start of the sequence.
Experimental Evaluation
The researchers evaluated AdaCAD across several LLM families, including Llama-2, Llama-3, and Mistral. Benchmarks included:
- Question Answering (QA): Natural Questions (NQ), TriviaQA, PopQA, HotpotQA, and TabMWP.
- Knowledge Conflict Specific: NQ-SWAP (swapped entities) and NQ-SYNTH (context matching parametric knowledge to test for over-correction).
- Summarization: CNN-DM, XSum, and TofuEval (factual consistency).
Key Results
AdaCAD demonstrated superior performance across all tested models and tasks. In Question Answering, it achieved an average absolute gain of 14.21% over the static CAD baseline.
Key findings include:
- Granular Conflict Resolution: By treating conflict as a token-level variable, AdaCAD avoids the "all-or-nothing" approach of static methods, allowing for more nuanced text generation.
- Robustness to Over-Correction: In the NQ-SYNTH "zero-conflict" test, static CAD performance dropped significantly (~24%), whereas AdaCAD remained stable, matching greedy decoding performance. This proves the model "knows when to stay out of the way."
- Improved Factuality: On the TofuEval summarization benchmark, AdaCAD improved the AlignScore by 4.16 points, particularly excelling in summarizing secondary topics where hallucinations are most common.
Limitations and Future Work
Despite its effectiveness, AdaCAD requires access to the model's raw logits, making it incompatible with "black-box" APIs that only provide text output. Additionally, the requirement for two forward passes per token (with and without context) effectively doubles the computational cost during the decoding phase. Future research will explore multilingual applications and methods to reduce this computational overhead.
Summary updated