Abstract
Recent decoding methods improve the factuality of large language models (LLMs) by refining how the next token is selected during generation. These methods typically operate at the token level, leveraging internal representations to suppress superficial patterns. Nevertheless, LLMs remain prone to hallucinations, especially over longer contexts. In this paper, we propose Active Layer-Contrastive Decoding (ActLCD), a novel decoding strategy that actively decides when to apply contrasting layers during generation. By casting decoding as a sequential decision-making problem, ActLCD employs a reinforcement learning policy guided by a reward-aware classifier to optimize factuality beyond the token level. Our experiments demonstrate that ActLCD surpasses state-of-the-art methods across five benchmarks, showcasing its effectiveness in mitigating hallucinations in diverse generation scenarios.
Introduction
Large Language Models (LLMs) are increasingly capable, yet they frequently "hallucinate"—generating fluent text that is factually incorrect. Research suggests this occurs because models often prioritize superficial linguistic patterns found in shallower layers over the factual knowledge embedded in deeper layers.
Existing solutions like DoLa (Decoding by Contrasting Layers) attempt to fix this by contrasting deep and shallow layer outputs for every token. However, this static approach has significant drawbacks: it can lead to "overthinking" on simple tokens (degrading performance) and lacks the sequential awareness needed to prevent early factual errors from cascading into a complete breakdown of logic across a long generation.
Methodology: Active Layer-Contrastive Decoding (ActLCD)
To overcome the limitations of static methods, we propose ActLCD, which treats the decoding process as a Markov Decision Process (MDP). Instead of applying layer-contrasting blindly, the model learns a policy to decide, token-by-token, whether to use standard greedy decoding or to activate layer-contrasting interventions.
The framework utilizes a reinforcement learning (RL) policy guided by internal model signals, such as embeddings and logits from various layers. The training involves two stages: Behavior Cloning (BC) to imitate correct activation patterns, followed by Batch-Constrained Q-learning (BCQ) to maximize cumulative rewards. This ensures the model stays "on track" throughout long-form generation by penalizing both missed activations and unnecessary interventions.
Experimental Setup
We evaluated ActLCD across five diverse benchmarks to test various dimensions of factuality:
- TruthfulQA: Short-answer questions targeting human misconceptions.
- LongFact: A benchmark for long-form, fact-seeking responses.
- StrategyQA & GSM8k: Multi-hop reasoning and grade-school math word problems.
- Software Package Hallucination: A domain-specific test where models recommend Python or JavaScript packages, testing their ability to avoid naming non-existent libraries.
Key Results and Performance
ActLCD consistently outperformed Greedy decoding, DoLa, and SLED across all tested models, including Llama-3.1, Mistral, and GLM.
Quantitative highlights include:
- Factuality Gains: On TruthfulQA, ActLCD achieved a maximum gain of +19.81% in the composite "Truth*Info" metric.
- Reasoning Improvements: Accuracy on GSM8k increased by up to +7.21% and StrategyQA by +7.51%.
- Domain Specificity: In the software package benchmark, ActLCD reduced the hallucination rate by up to 6.5% for Python and 5.6% for JavaScript compared to standard greedy decoding.
Discussion and Insights
The success of ActLCD stems from its dynamic nature. By learning that layer-contrasting is a "heavy-duty" tool, the model avoids using it for filler words or context repetition where standard decoding suffices. Furthermore, the paper demonstrates that an LLM’s internal hidden states contain sufficient signal for an auxiliary policy network to accurately predict when a hallucination is imminent. Crucially, ActLCD remains computationally efficient, adding only 3% to 5% to decoding latency compared to static methods like DoLa.
Conclusion
ActLCD demonstrates that dynamic, sequential intervention is key to reducing hallucinations in LLMs. While the method is limited by the base model's inherent knowledge—it cannot surface facts the model never learned—it significantly improves the reliability of the knowledge that is present. Future work will explore more granular control over specific layer selections at different stages of generation.
Summary updated