DoLa (Decoding by Contrasting Layers) is a training-free decoding strategy that reduces factual hallucinations in large language models by contrasting the logit outputs of a later, mature transformer layer against an earlier, premature layer. By computing the log-probability difference between these two internal representations, DoLa amplifies the model's latent factual knowledge while suppressing the linguistic shortcuts and statistical biases that dominate shallow layer predictions.
Glossary
DoLa (Decoding by Contrasting Layers)

What is DoLa (Decoding by Contrasting Layers)?
A decoding strategy that contrasts logit outputs from a later, mature transformer layer against an earlier, premature layer to surface factual knowledge and reduce hallucinations without an external model.
The method operates by selecting a dynamic premature layer for each token prediction, chosen based on divergence from the mature layer's output distribution. This contrastive signal is then subtracted from the final logits before sampling, effectively steering generation toward tokens that the model's deeper, more knowledgeable layers prefer. Unlike external retrieval-augmented generation or multi-model ensembles, DoLa requires no additional models, training, or external data, making it a computationally efficient inference-time intervention for improving factual accuracy.
Key Features of DoLa
DoLa is a novel decoding strategy that contrasts logit outputs from different transformer layers to surface factual knowledge and reduce hallucinations without requiring external retrieval or model fine-tuning.
Layer Contrast Mechanism
DoLa operates by computing the logit difference between a later, mature transformer layer and an earlier, premature layer. The core insight is that factual knowledge tends to emerge in later layers, while earlier layers contain more generic linguistic patterns. By subtracting the early-layer logits from the late-layer logits, DoLa amplifies the signal for factually grounded tokens and suppresses hallucinatory ones. This contrastive approach requires no external model, no fine-tuning, and no additional training data.
Dynamic Premature Layer Selection
Rather than using a fixed early layer for all tokens, DoLa employs dynamic premature layer selection. For each decoding step, it evaluates multiple candidate premature layers and selects the one that maximizes the Jensen-Shannon divergence from the mature layer's output distribution. This adaptive approach ensures the contrast is most effective when the model is uncertain or prone to hallucination, while minimizing interference during straightforward, factual token predictions.
Hallucination Reduction Without Retrieval
Unlike Retrieval-Augmented Generation (RAG) which relies on external knowledge bases, DoLa reduces hallucinations purely through internal model mechanics. It exploits the hierarchical nature of transformer representations:
- Early layers: Encode surface-level syntax and common patterns
- Later layers: Encode deeper semantic and factual knowledge By contrasting these, DoLa surfaces latent factual knowledge already present in the model's parameters but often suppressed during standard decoding. This makes it complementary to RAG, not competitive.
Factual Knowledge Surfacing
DoLa is particularly effective at surfacing rare or long-tail factual knowledge that standard greedy decoding or nucleus sampling might miss. The contrastive signal amplifies tokens associated with specific entities, dates, and verifiable facts. Research shows DoLa significantly improves performance on:
- TruthfulQA: Benchmark for truthful responses to adversarial questions
- FACTOR: Factual correctness evaluation
- StrategyQA: Multi-hop reasoning requiring implicit facts This makes it valuable for applications requiring high factual precision without latency overhead.
Integration with Standard Decoding
DoLa functions as a drop-in replacement for standard decoding strategies. It can be combined with:
- Greedy decoding: Simple contrastive amplification
- Nucleus sampling: Contrast before top-p filtering
- Beam search: Apply contrastive scoring to beam candidates The method adds minimal computational overhead since it reuses intermediate layer outputs already computed during the forward pass. No additional model calls or architectural changes are required, making it practical for production deployment.
Contrastive Decoding Family
DoLa belongs to the broader family of contrastive decoding methods that improve generation quality through distributional comparison:
- Standard Contrastive Decoding: Contrasts an expert model against an amateur model
- DoLa: Contrasts layers within a single model (no external amateur needed)
- Context-aware Decoding: Contrasts with and without context DoLa's key advantage is self-containment—it requires only one model and leverages its internal representations, eliminating the need to train or maintain a separate amateur model while achieving comparable hallucination reduction.
DoLa vs. Other Decoding Strategies
Comparing DoLa (Decoding by Contrasting Layers) against other decoding strategies used to improve factual accuracy and reduce hallucinations in large language model outputs without external knowledge retrieval.
| Feature | DoLa | Contrastive Decoding | Factual-Nucleus Sampling | Context Distillation |
|---|---|---|---|---|
Core Mechanism | Contrasts logits between later mature layers and earlier premature layers within a single model | Contrasts logits between a strong expert model and a weaker amateur model | Samples tokens from the intersection of nucleus sampling and a factual knowledge distribution | Compresses a complex prompt or context into soft prompt vectors that elicit the same behavior |
External Model Required | ||||
Additional Compute Overhead | Minimal (extra forward pass through selected layers) | High (requires running two separate models simultaneously) | Moderate (requires maintaining and sampling from a separate factual distribution) | Low at inference (one-time compression cost upfront) |
Primary Target | Surfacing latent factual knowledge already present in the model | Amplifying desirable behaviors by suppressing amateur model tendencies | Balancing fluency with factual correctness during token sampling | Reducing prompt length and latency while preserving behavior |
Hallucination Reduction Approach | Amplifies signals from mature layers that encode more factual knowledge | Penalizes tokens that the amateur model finds likely, assuming they are less desirable | Restricts the sampling space to tokens with high probability in both the fluency and factual distributions | Preserves the original prompt's intent in a compressed form to avoid information loss |
Requires Retraining or Fine-Tuning | ||||
Granularity of Control | Layer-level (selects which transformer layers to contrast) | Model-level (selects the expert and amateur model pair) | Token-level (applies a constraint at each sampling step) | Prompt-level (compresses the entire instruction context) |
Typical Latency Impact | < 10% increase over standard decoding |
| 15-30% increase over standard nucleus sampling | Reduces latency (shorter prompts process faster) |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Frequently Asked Questions
Explore the mechanics and applications of DoLa, a novel decoding strategy that contrasts internal model layers to surface factual knowledge and reduce hallucinations.
DoLa (Decoding by Contrasting Layers) is a decoding strategy that contrasts the logit outputs from a later, mature transformer layer against an earlier, premature layer to surface factual knowledge and reduce hallucinations without an external model. It works by exploiting the observation that factual knowledge in large language models tends to localize in specific middle-to-late layers. During generation, DoLa dynamically selects a 'premature' layer and subtracts its logit distribution from that of the final layer. This contrastive operation amplifies the signal from the mature, knowledge-rich layers while suppressing the linguistic shortcuts and statistical biases of earlier layers. The result is a next-token probability distribution that favors factually grounded tokens over plausible-sounding but incorrect ones. Unlike Contrastive Decoding, which requires a separate amateur model, DoLa is entirely self-contained, using the model's own internal hierarchy as the contrasting pair.
Related Terms
Explore the core mechanisms and related concepts that underpin DoLa's approach to surfacing factual knowledge by contrasting internal model representations.
Contrastive Decoding
The foundational family of techniques that DoLa belongs to. It searches for tokens that maximize the probability difference between a strong expert model and a weaker amateur model. By penalizing the amateur's predictions, the expert's more desirable behaviors—like factuality—are amplified. DoLa uniquely creates this expert/amateur pair from different layers within a single model.
Factual Knowledge Localization
The research finding that factual associations are not uniformly distributed across a transformer's layers but are often localized in specific middle-to-late layers. DoLa exploits this by contrasting a mature layer where facts are represented against an immature layer where they are not, effectively amplifying the signal from the factual knowledge neurons.
Hallucination Entropy
A measurement of the uncertainty in a model's token predictions that correlates with the generation of non-factual content. DoLa serves as a direct mitigation technique by reducing this entropy. By subtracting the 'hallucinatory' logit distribution of an early layer from a later layer's distribution, the method sharpens the model's focus on the most factually grounded tokens.
Logit Manipulation
The core mathematical operation in DoLa. Instead of using the final output logits directly, DoLa computes the logit difference between a mature layer and a premature layer. This manipulated logit vector is then used for sampling. This is a form of controlled generation that requires no external tools, fine-tuning, or prompt engineering, operating purely at the inference level.
Dynamic Premature Layer Selection
A key innovation of DoLa that distinguishes it from static contrastive methods. The specific premature layer used for contrasting is not fixed; it is dynamically selected for each token prediction based on which early layer's output distribution is maximally different from the mature layer's. This adaptive mechanism ensures the contrast is always performed against the most relevant 'amateur' representation.
Source Grounding vs. Internal Contrast
A critical distinction in factuality techniques. Source grounding anchors generation to provided external documents to prevent hallucination. DoLa, by contrast, is an internal contrast method that requires no external knowledge base. It surfaces factual knowledge already encoded within the model's own parameters during pre-training, making it a complementary approach to RAG.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us