Inferensys

Glossary

DoLa (Decoding by Contrasting Layers)

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.
Stylish WeWork-like workspace with hot desks and document wall, professional searching through enterprise knowledge base on a mounted ultrawide display, warm industrial pendants overhead.
HALLUCINATION MITIGATION

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.

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.

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.

DECODING BY CONTRASTING LAYERS

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.

01

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.

02

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.

03

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.
04

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.
05

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.
06

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.
HALLUCINATION REDUCTION COMPARISON

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.

FeatureDoLaContrastive DecodingFactual-Nucleus SamplingContext 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

100% increase (running two models)

15-30% increase over standard nucleus sampling

Reduces latency (shorter prompts process faster)

DECODING STRATEGIES

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.

Prasad Kumkar

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.