NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Contrastive Decoding: Open-ended Text Generation as Optimization

Xiang Lisa Li, Ari Holtzman, Daniel Fried, Percy Liang, Jason Eisner, Tatsunori Hashimoto, Luke Zettlemoyer, Mike Lewis

Abstract

Generating long, coherent, and creative text from Large Language Models (LLMs) remains a challenge due to the "decoding paradox," where models either become repetitive (greedy search) or incoherent (stochastic sampling). We present Contrastive Decoding (CD), a training-free, search-based decoding strategy that maximizes the difference in log-probabilities between a large "expert" model and a small "amateur" model. By subtracting the amateur's signal, CD effectively suppresses common failure modes like repetition and incoherence. Our evaluations show that CD significantly outperforms standard sampling methods like Nucleus or Top-k in both human preference and distributional metrics.

Introduction

The "decoding paradox" in LLMs highlights a fundamental trade-off. Maximum probability methods, such as greedy or beam search, often lead to repetitive and "boring" sequences. Conversely, sampling-based methods like Nucleus (Top-p) or Top-k introduce necessary stochasticity but suffer from compounding "unlucky" samples, leading to topic drift and loss of coherence over long sequences. Contrastive Decoding addresses this by framing text generation as an optimization problem that leverages the relative strengths of models at different scales.

Methods

Contrastive Decoding treats text generation as a search for tokens that maximize a contrastive objective.

The Contrastive Objective

The core mechanism involves searching for tokens that maximize the difference between an expert and an amateur model:

$$\text{Score} = \log p_{\text{expert}}(x) - \log p_{\text{amateur}}(x)$$

Typically, the "expert" is a large model (e.g., OPT-13B), and the "amateur" is a significantly smaller version from the same family (e.g., OPT-125M). The intuition is that smaller models exhibit the same "bad habits" as larger ones—such as repetition and logical lapses—but more acutely. By subtracting the amateur's log-probabilities, the expert's unique strengths, such as factual knowledge and long-term coherence, are amplified.

Figure 1: Contrastive Decoding (CD) mechanism. By subtracting the log-probabilities of an amateur model from an expert model, CD highlights the expert's unique knowledge while suppressing common failure modes.

Adaptive Plausibility Constraint

To ensure linguistic plausibility, an adaptive constraint ($V_{\text{head}}$) is applied. The search only considers tokens with a probability of at least $\alpha$ (typically 0.1) relative to the expert's most likely token. This prevents the selection of nonsense tokens that the amateur might strongly dislike but are also improbable for the expert.

Key Insights

  • Small Models as Caricatures: Small models are not merely less capable; they act as "caricatures" of larger models, failing in predictable ways. CD uses the amateur as a negative constraint to steer the expert away from these pitfalls.
  • The Scale Gap: Performance improves as the size gap between the expert and amateur increases. A very small amateur is more effective at highlighting the expert's high-level knowledge than a medium-sized one.
  • Pragmatic Communication: CD can be viewed through Gricean Maxims, where the expert acts as a speaker attempting to be informative to a listener (the amateur) by avoiding what is already predictable.

Experimental Results

We evaluated CD across three domains: Wikinews, WikiText-103, and BookCorpus (Stories). CD was compared against strong baselines, including Nucleus sampling ($p=0.95$), Top-k sampling ($k=50$), Typical decoding, and Contrastive Search.

Table 1: Quantitative results on Wikinews, Wikitext, and Story datasets. CD consistently achieves high MAUVE and coherence scores compared to standard sampling methods.

Performance Metrics

  • Coherence: Human evaluations preferred CD 2.6x more than Nucleus sampling and 6.4x more than Typical decoding for coherence.
  • Distributional Fit: CD consistently achieved higher MAUVE scores, indicating that its generated text more closely matches the distribution of human-written text.
  • Diversity without Drift: CD maintains high lexical diversity and avoids the repetition traps of greedy search while remaining strictly on-topic, unlike sampling methods that often drift into unrelated subjects.

Conclusion and Future Work

Contrastive Decoding offers a "plug-and-play" inference-time optimization that requires no additional training or fine-tuning. While highly effective for open-ended generation, future work may explore its application in task-oriented generation (e.g., summarization) and the use of specialized "anti-experts" to suppress specific behaviors like toxicity.

Summary updated

BibTeX
@inproceedings{li2023contrastive,
  author = {Xiang Lisa Li and Ari Holtzman and Daniel Fried and Percy Liang and Jason Eisner and Tatsunori Hashimoto and Luke Zettlemoyer and Mike Lewis},
  title = {{Contrastive Decoding: Open-ended Text Generation as Optimization}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2023},
  doi = {10.18653/v1/2023.acl-long.687},
}
Figure