Contrastive Decoding Improves Reasoning in Large Language Models

Sean O'Brien, Mike Lewis

Abstract

We demonstrate that Contrastive Decoding -- a simple, computationally light, and training-free text generation method proposed by Li et al 2022 -- achieves large out-of-the-box improvements over greedy decoding on a variety of reasoning tasks. Originally shown to improve the perceived quality of long-form text generation, Contrastive Decoding searches for strings that maximize a weighted difference in likelihood between strong and weak models. We show that Contrastive Decoding leads LLaMA-65B to outperform LLaMA 2, GPT-3.5 and PaLM 2-L on the HellaSwag commonsense reasoning benchmark, and to outperform LLaMA 2, GPT-3.5 and PaLM-540B on the GSM8K math word reasoning benchmark, in addition to improvements on a collection of other tasks. Analysis suggests that Contrastive Decoding improves over existing methods by preventing some abstract reasoning errors, as well as by avoiding simpler modes such as copying sections of the input during chain-of-thought. Overall, Contrastive Decoding outperforms nucleus sampling for long-form generation and greedy decoding for reasoning tasks, making it a powerful general purpose method for generating text from language models.

Introduction

Large Language Models (LLMs) typically rely on two distinct decoding strategies: sampling for creative generation and greedy decoding for reasoning tasks. However, even state-of-the-art models often fail in logical reasoning by falling into "easy" traps, such as verbatim copying of prompts or skipping logical steps. These failures suggest that the most probable tokens in a model's distribution are often generic or repetitive rather than logically sound. This paper explores Contrastive Decoding (CD) as a training-free solution to steer models toward more sophisticated reasoning behaviors.

Methodology

Contrastive Decoding (CD) operates by contrasting a strong "expert" model (e.g., LLaMA-65B) against a smaller "amateur" model (e.g., LLaMA-1.5B). The core objective is to select tokens that the expert prefers significantly more than the amateur.

The Contrastive Decoding mechanism subtracts amateur logits from expert logits to highlight sophisticated reasoning patterns and suppress generic or repetitive outputs.

The method utilizes a weighted difference in log-likelihoods in logit space, making it computationally efficient. To ensure coherence, $\alpha$-masking is applied, restricting the search to tokens that meet a minimum probability threshold in the expert's distribution. This prevents the selection of nonsensical tokens that the amateur simply happens to assign low probability.

Experimental Results

The researchers evaluated CD across diverse benchmarks, including arithmetic reasoning (GSM8K, MATH), commonsense reasoning (HellaSwag, StrategyQA), and general knowledge (MMLU, ARC).

LLaMA-65B with Contrastive Decoding achieves superior accuracy on the HellaSwag benchmark compared to LLaMA 2, ChatGPT, and PaLM-2 L.

Key findings include:

  • Benchmark Performance: LLaMA-65B with CD achieved a score of 57.7 on GSM8K, surpassing LLaMA 2 (56.8) and GPT-3.5 (57.1). On HellaSwag, it reached 88.0, outperforming PaLM 2-Large.
  • Logical vs. Arithmetic Gains: Error analysis revealed that while CD might slightly increase raw calculation errors, it significantly reduces logical errors, such as skipping steps, leading to higher overall success rates.
  • Efficiency: CD is highly efficient, adding only approximately 3.25% more FLOPs compared to a single forward pass, unlike more expensive methods like Self-Consistency.

Discussion and Conclusion

Contrastive Decoding effectively uses the amateur model as a foil to "mute" surface-level behaviors like copying, forcing the expert to rely on higher-level reasoning. The choice of amateur is critical; a 1.5B model serves as a better foil for a 65B expert than a 7B model, as a stronger amateur may cancel out the expert's unique intelligence.

While CD shows slight degradation in pure factual recall, its ability to reduce surface-level copying and improve logical flow makes it a powerful general-purpose method for LLM generation, particularly when paired with Chain-of-Thought prompting.

Summary updated

Abstract

We demonstrate that Contrastive Decoding -- a simple, computationally light, and training-free text generation method proposed by Li et al 2022 -- achieves large out-of-the-box improvements over greedy decoding on a variety of reasoning tasks. Originally shown to improve the perceived quality of long-form text generation, Contrastive Decoding searches for strings that maximize a weighted difference in likelihood between strong and weak models. We show that Contrastive Decoding leads LLaMA-65B to outperform LLaMA 2, GPT-3.5 and PaLM 2-L on the HellaSwag commonsense reasoning benchmark, and to outperform LLaMA 2, GPT-3.5 and PaLM-540B on the GSM8K math word reasoning benchmark, in addition to improvements on a collection of other tasks. Analysis suggests that Contrastive Decoding improves over existing methods by preventing some abstract reasoning errors, as well as by avoiding simpler modes such as copying sections of the input during chain-of-thought. Overall, Contrastive Decoding outperforms nucleus sampling for long-form generation and greedy decoding for reasoning tasks, making it a powerful general purpose method for generating text from language models.
BibTeX
@misc{obrien2023contrastive,
  author = {Sean O'Brien and Mike Lewis},
  title = {{Contrastive Decoding Improves Reasoning in Large Language Models}},
  year = {2023},
  eprint = {2309.09117},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2309.09117},
}
Figure