DoLa: Decoding by Contrasting Layers Improves Factuality in Large Language Models

Yung-Sung Chuang, Yujia Xie, Hongyin Luo, Yoon Kim, James R. Glass, Pengcheng He

TL;DR

DoLa (Decoding by Contrasting Layers) is a simple, "zero-shot" decoding strategy that significantly reduces hallucinations in Large Language Models (LLMs). By contrasting the predictions of a model's final layers against its earlier layers during inference, DoLa amplifies factual knowledge and filters out superficial linguistic patterns. This approach improves truthfulness on benchmarks like TruthfulQA by up to 17% without requiring any extra training or external data.

The Hallucination Problem

Despite their impressive capabilities, LLMs are notorious "hallucinators." They often generate text that is grammatically perfect but factually incorrect. This happens largely because the standard training objective—predicting the next word—encourages the model to learn superficial linguistic patterns rather than deep factual grounding.

Previous attempts to fix this usually involve Retrieval-Augmented Generation (searching the web) or fine-tuning (re-training the model on better data). Both are computationally expensive and complex. The authors of DoLa asked a different question: Is the factual truth already inside the model, just buried under layers of plausible-sounding noise?

Methods: Contrastive Decoding Across Layers

The core idea of DoLa is Contrastive Decoding. Usually, when an LLM predicts the next token, it only looks at the output of its very last layer. However, research shows that different layers of a transformer encode different types of information: lower layers handle syntax and grammar, while higher layers tend to inject semantic and factual knowledge.

DoLa contrasts the output of the final layer with earlier layers to amplify factual tokens like "Olympia".

DoLa works through a three-step process for every single word generated:

  1. Candidate Selection: The model looks at its final layer (the "mature" layer) and a set of earlier layers (the "premature" layers).
  2. Dynamic Layer Selection: For each token, the algorithm calculates the Jensen-Shannon Divergence (JSD) between the mature layer and the premature layers. It identifies the early layer that is most different from the final layer. This sudden change in probability distribution usually signals where the model is injecting factual knowledge.
  3. Logit Subtraction: The model subtracts the log-probabilities (logits) of the premature layer from the mature layer. This amplifies the signal that only the higher layers possess, canceling out the generic linguistic guesses of the earlier layers.

To ensure the model doesn't pick nonsensical words, the authors use an Adaptive Plausibility Constraint (APC), which restricts the final choice to tokens that the mature layer already considered reasonably likely.

Key Insights: Factuality is a "Late-Stage" Evolution

A major discovery in this work is how LLMs process different types of words. For "easy" tokens (like "the" or "is"), the model's prediction solidifies in the middle layers. However, for "hard" factual tokens (like names or dates), the probability distribution keeps shifting significantly until the very last layers.

Heatmap showing Jensen-Shannon Divergence across layers. Factual tokens exhibit high divergence in later layers.

Unlike previous contrastive methods that required a separate, smaller "amateur" model to contrast against, DoLa proves that an LLM can serve as its own amateur. Its earlier layers provide the "plausible but dumb" baseline needed to highlight the "factual and smart" output of the later layers. Furthermore, because DoLa only requires one extra projection during the forward pass, it adds very little latency (only 1-8% slower than standard decoding), making it a practical drop-in replacement.

Evaluation and Results

The researchers evaluated DoLa across a diverse range of tasks using the LLaMA family of models (7B to 65B parameters), including TruthfulQA, FACTOR, StrategyQA, GSM8K, and Vicuna QA.

  • Massive Truthfulness Gains: On TruthfulQA, DoLa improved LLaMA-65B's performance by over 12% and LLaMA-7B's by 17% in absolute points.
  • Outperforming the Competition: DoLa consistently beat other state-of-the-art methods like Inference Time Intervention (ITI) and standard Contrastive Decoding (CD).
  • Reasoning Boost: Even on math and logic tasks (GSM8K), DoLa provided a small but consistent accuracy boost, suggesting that "thinking more clearly" about facts also helps with logical steps.
  • GPT-4 Approved: In open-ended chatbot evaluations, GPT-4 rated DoLa-generated responses as significantly more informative and factual than the baseline.

Limitations and Future Work

While powerful, DoLa has its boundaries. First, it can only surface facts the model actually learned during pre-training; if the model never saw the fact, DoLa cannot magically retrieve it. Second, the paper focuses almost entirely on truthfulness, leaving it unclear how DoLa affects other alignment traits like helpfulness or safety. Finally, experiments on very small models (like GPT-2 335M) showed that DoLa doesn't help much, suggesting a model needs to reach a certain critical mass of parameters before it localizes factual knowledge in a way that DoLa can exploit.

Future work could combine DoLa with external search (Retrieval-Augmented Generation) to create a model that is both internally consistent and externally grounded.

Summary updated

BibTeX
@inproceedings{chuang2024dola,
  author = {Yung-Sung Chuang and Yujia Xie and Hongyin Luo and Yoon Kim and James R. Glass and Pengcheng He},
  title = {{DoLa: Decoding by Contrasting Layers Improves Factuality in Large Language Models}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=Th6NyL07na},
}
Figure