Contrastive Decoding Improves Reasoning in Large Language Models

Sean O'Brien, Mike Lewis · Submission to ICLR 2024 · Rejected

TL;DR

Contrastive Decoding (CD)—which searches for tokens that maximize the difference in likelihood between a strong “expert” model and a weak “amateur” model—significantly improves reasoning accuracy over standard greedy decoding without any fine-tuning. By penalizing simplistic heuristics and rote prompt-copying, LLaMA-65B paired with a 1.5B amateur outperforms much larger models like PaLM-540B, LLaMA 2, and GPT-3.5 on GSM8K and HellaSwag, adding just ~3% computational overhead.

What Problem Does This Paper Address?

Language generation typically relies on a split strategy: open-ended generation uses stochastic truncated sampling (e.g., top-$p$/nucleus) to prevent generic or repetitive text, whereas reasoning tasks rely on greedy decoding to avoid catastrophic sampling mistakes in logical deduction.

This paper investigates whether Contrastive Decoding (CD)—originally introduced by Li et al. (2022) to boost perceived fluency in open-ended generation—can also solve complex reasoning tasks. The authors address whether contrasting an expert model against an amateur model can suppress common reasoning traps and hallucinations during Chain-of-Thought (CoT) generation.

Methods

The authors streamline the original CD formulation directly into logit space, mirroring a DExperts-style objective:

  1. $\alpha$-Masking (Plausibility Filter): Restricts the candidate token set $V_{\text{valid}}$ to tokens where the expert logit $s_e^{(j)}$ is reasonably close to the expert's top choice: $$V_{\text{valid}} = \{j \in V \mid s_e^{(j)} \ge \log \alpha + \max_{k \in V} s_e^{(k)}\}$$ (Default setting: $\alpha = 0.1$)

  2. Amateur Logit Subtraction: Computes the contrastive score by penalizing amateur logits $s_a^{(i)}$ weighted by hyperparameter $\beta$: $$s_{\text{CD}}^{(i)} = \begin{cases} (1 + \beta)s_e^{(i)} - \beta s_a^{(i)} & i \in V_{\text{valid}} \\ -\infty & i \notin V_{\text{valid}} \end{cases}$$ (Default setting: $\beta = 0.5$)

  3. Setup: The primary configuration evaluates an untuned LLaMA-65B as the expert and a smaller 1.5B LLaMA model (trained on identical data) as the amateur. The method is training-free and can be implemented in three lines of PyTorch.

Datasets

  • Math Word Problems (CoT generation): GSM8K, SVAMP, ASDiv, AQuA, and the competition-level MATH dataset.
  • Commonsense Reasoning (Free-form & CoT): CommonsenseQA (CSQA) and StrategyQA.
  • Multiple-Choice Zero-Shot Cloze: HellaSwag, ARC (Easy & Challenge), BoolQ, PIQA, SIQA, WinoGrande, and MMLU.
  • Factual Retrieval & Arithmetic Baselines: TriviaQA, OpenBookQA, and a synthetic 1,000-example multi-digit arithmetic dataset.

Key Insights and Ideas

  • Better Logic, Not Better Calculator: Manual error analysis reveals CD does not improve raw arithmetic ability (in fact, accuracy on pure multi-digit arithmetic slightly drops). Instead, CD drastically reduces missing intermediate reasoning steps and prevents semantic misunderstandings.
  • Reduced Prompt Copying: Token overlap analysis shows CD significantly reduces surface-level n-gram copying from the prompt during CoT. It discourages the model from merely regurgitating input text when it should be deriving new steps.
  • Amateur Sizing is Critical: The amateur must represent "shallow" behaviors without being competent enough to penalize correct expert reasoning. While a 1.5B amateur yields strong gains, a fully-trained 7B amateur hurts performance.
  • Partially-Trained Amateurs Work Well: An early checkpoint of a 7B model (trained on only 10% to 23% of tokens) serves as an effective amateur, illustrating that CD acts like a first-order optimization step amplifying skills acquired late in training.
  • Requires Chain-of-Thought: CD provides negligible benefits without CoT prompts. The expert requires the reasoning "scaffolding" to establish an exploitable capability margin over the amateur.

Key Results

  • GSM8K Math Reasoning: LLaMA-65B with CD ($\beta = 0.25$) achieves 57.7%, up from 51.0% with greedy decoding—surpassing LLaMA 2 (56.8%), PaLM-540B (56.5%), and GPT-3.5 (57.1%). When combined with self-consistency (maj@20), performance increases from 68.0% to 74.0%.
  • HellaSwag Ranking: Using length-normalized contrastive scoring, LLaMA-65B scores 88.0% (vs. 84.2% greedy), outperforming PaLM 2-Large (86.8%), GPT-3.5 (85.5%), and LLaMA 2 (85.3%).
  • FLOP Efficiency: Because the amateur is only 1.5B parameters, CD incurs an estimated compute overhead of only +3.25% FLOPs per generated token, providing a substantially cheaper performance gain than sampling-based self-consistency.

Limitations and Future Work

  • Factual Knowledge Degradation: CD slightly degrades performance on pure factual recall benchmarks where CoT is not used (OpenBookQA drops by 2.4%; TriviaQA drops by 2.1%).
  • Hard Task Boundaries: CD cannot compensate on benchmarks far beyond the model's fundamental competency, showing no significant improvement on the challenging MATH benchmark.
  • Commonsense Inconsistencies: On CommonsenseQA, CD slightly degrades single-path performance on smaller expert models, only stabilizing when applied to the 65B model or combined with self-consistency.
  • Scope: Experiments primarily focused on untuned LLaMA-1 models; evaluating CD on heavily instruction-tuned and RLHF-aligned models remains open for future research.

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},
}

Loading related content...

Figure