Abstract
Large Language Models (LLMs) often prioritize their internal parametric knowledge over external context, leading to "unfaithful" hallucinations in Retrieval-Augmented Generation (RAG) systems. This paper introduces Context-aware Layer Enhancement (CaLE), a method designed to identify the specific intermediate layers where contextual information is most "usable" and strategically boost them. By amplifying these layers, CaLE ensures that the final model output remains grounded in the provided text, effectively mitigating the phenomenon of information decay in deeper layers.
Introduction
In modern AI workflows, RAG systems are the standard for ensuring accuracy by providing LLMs with external documents. However, a persistent challenge is context-faithfulness: models frequently ignore provided documents if the information conflicts with their internal, potentially outdated training data.
Recent research into the internal mechanics of LLMs reveals that contextual information does not always increase as it moves through a model's layers. Instead, it often peaks in the middle layers and then "decays" or plateaus before reaching the final output. CaLE addresses this by catching the information at its peak and amplifying it before it fades, ensuring the model's final prediction is driven by the context rather than internal bias.
The CaLE Framework
CaLE is a two-step intervention designed to be applied during the inference phase without requiring model retraining.
1. Layer Identification
The first step involves finding the "context-aware layer"—the specific depth where the model has most effectively integrated the provided context. The authors propose two methods for this:
- Supervised Identification: This uses a small validation set to determine which layer's "internal guess" (evaluated via the logit lens) is most accurate.
- Unsupervised Identification: A more flexible approach using KL Divergence. By measuring the difference between a layer's hidden state with context versus its state without context, researchers can identify layers actively processing new information. High divergence typically indicates the "sweet spot" for intervention.
2. Enhancement Strategies
Once the optimal layer $l$ is identified, one of two interventions is applied:
- CaLE-A (Amplification): The hidden state of the target layer is multiplied by a scaling factor ($\alpha$).
- CaLE-R (Residual): The hidden state of the optimal layer is added to several subsequent layers, effectively "reminding" the model of the context as it processes deeper toward the output.
Notably, CaLE is orthogonal to existing techniques; it can be combined with decoding-side strategies like Contrastive Decoding (CD) to further enhance performance.
Experimental Evaluation
The researchers evaluated CaLE across several diverse benchmarks designed to test different aspects of model reasoning and faithfulness:
- CounterFact: Tests "knowledge conflicts" where context contradicts internal weights.
- NQ-Swap: A variation of Natural Questions where correct answers are replaced with random entities to see if the model follows the context despite its internal knowledge.
- SQuAD & StrategyQA: Standard reading comprehension and multi-step reasoning datasets.
Key Insights
- Information Decay: Visualizations of $\mathcal{V}$-usable information confirm that the final layer is rarely the most knowledgeable about the context. In models like Llama-3-8B, the "sweet spot" typically resides between layers 20 and 26.
- KL Divergence as a Proxy: The unsupervised KL divergence metric correlates strongly with supervised accuracy peaks, making CaLE practical for real-world deployment where labeled validation data may be scarce.
- Hidden State Dominance: Intervening on the hidden states (the residual stream) proved far more effective than modifying Attention or MLP components directly, which often introduced noise or amplified internal biases.
Results and Impact
CaLE demonstrated significant improvements in faithfulness across all tested architectures (Llama 2, Llama 3, Mistral, and Gemma). On the CounterFact dataset, Llama2-7B's Exact Match (EM) score improved from 54.32% to 74.98% using CaLE-A.
The method is particularly effective when the model encounters "Unknown" knowledge—facts not present in its training data. In these scenarios, CaLE-A consistently outperformed other intervention baselines like "Early Exit" and neuron reweighting (IRCAN), especially on complex reasoning tasks like StrategyQA.
Limitations and Future Work
While highly effective, CaLE currently operates as a static intervention. Future research may explore dynamic interventions that adjust throughout the generation of long sequences. Additionally, while the current method boosts the entire hidden state, more surgical interventions targeting specific neurons or dimensions related to contextual processing could further reduce noise and improve efficiency. Finally, the amplification factor $\alpha$ currently requires tuning (typically between 4 and 6), suggesting a need for more automated hyperparameter optimization across different model architectures.
Summary updated