Lightweight reranking for language model generations

Siddhartha Jain, Xiaofei Ma, Anoop Deoras, Bing Xiang

TL;DR

Generative Large Language Models (LLMs) often produce a mix of brilliant and broken outputs for the same prompt. This paper introduces a "lightweight" reranking method that identifies the best generation by measuring how much it agrees with other samples via simple n-gram overlap. It achieves state-of-the-art performance on code generation and robust gains in text tasks without the need for expensive auxiliary models or extra inference passes.

What Problem Does This Paper Address?

LLMs are notoriously stochastic; sampling multiple times from the same model can yield vastly different results. To get the best performance, researchers often use "best-of-n" sampling, where they generate $n$ candidates and try to pick the winner.

However, ranking these candidates is hard. Current methods usually fall into three camps:

  1. Execution-based: Running code against unit tests (expensive to set up and risky to sandbox).
  2. Auxiliary Models: Training a second "ranker" model (requires labeled data and extra compute).
  3. Self-Consistency: A popular method for math problems where the model "votes" on the final answer.

The gap lies in open-ended tasks like code generation or summarization. In these cases, there isn't a single "correct" string to vote on, and existing rerankers are often too computationally heavy for production use.

Methods

The authors propose a generalized version of self-consistency that works for open-ended text. Instead of looking for exact matches, they use pairwise similarity as a proxy for agreement on underlying "semantic predicates" (the core facts or logic steps required for a correct answer).

From predicates to pairwise agreement: The conceptual leap from voting on specific properties to measuring general similarity.

They introduce three lightweight scoring variants:

  • Unigram Consistency Score (UCS): Represents each generation as a binary vector of token presence. The similarity between two generations is the inner product of these vectors.
  • Weighted UCS (WUCS): If token probabilities are available, it weights the vector elements by the model's confidence in those tokens.
  • Consensus-WUCS: Combines the similarity score with the sequence's mean log-probability to get the best of both worlds.
Visualization of how UCS and Weighted-UCS vectors are constructed from text and token probabilities.

Crucially, they do not normalize the inner product. This is a deliberate design choice: it penalizes short, repetitive, or "degenerate" sequences that are common failure modes for LLMs, effectively rewarding diversity and length.

Datasets

The method was evaluated across a diverse set of benchmarks:

  • Code Generation: HumanEval, MBPP, and MBPP-sanitized.
  • Autoformalization: MiniF2F (translating natural language math to Isabelle code).
  • Summarization: Xsum (Rouge-2 and Rouge-L metrics).
  • Translation: WMT14 (French-to-English and German-to-English).

The researchers tested these against a suite of models including Codex (davinci-001, 002, Cushman), Llama (13B, 30B), and GPT-J.

Key Insights and Ideas

  • The "Density" of Code: The method works significantly better for code than for natural language. The authors found that unigram overlap is much more informative in code; a missing keyword in a script usually signals a major semantic failure, whereas a missing word in a summary might just be a stylistic choice.
  • Black-Box Friendly: The simplest version (UCS) requires only the generated text. This makes it ideal for use with APIs where internal model weights or token probabilities might be hidden.
  • Resilience to Sample Size: While standard "mean log-prob" ranking often gets worse as you sample more (because it tends to gravitate toward safe but repetitive "boring" text), the consistency-based approach stays stable or improves as the sample size increases.
  • Ranked Pass@k: They extended the method to pick the top $k$ candidates by selecting the highest-ranked item and then penalizing other candidates that are too similar to it, ensuring the "budget" of $k$ attempts covers a diverse range of logic.

Key Results

The lightweight Consensus-WUCS method frequently outperformed much heavier baselines, including the "Coder Reviewer Ranker" which requires an additional inference pass.

  • HumanEval: Codex002 accuracy jumped from 43.5% (random selection) to 56.8% using Consensus-WUCS.
  • MBPP: On the MBPP dataset, Consensus-WUCS achieved 59.4% accuracy, beating the competitive "Medoid" baseline (56.3%).
  • Consistency across tasks: The method showed robust, albeit smaller, gains in summarization and translation, proving that "consistency" is a useful signal even when there isn't a single ground-truth answer.

The tables below (Table 1 in the paper) detail the performance across various models and tasks:

Performance on HumanEval, MBPP-S, and MBPP. Performance on MiniF2F and Xsum. Performance on WMT14 Translation tasks.

Limitations and Future Work

  • Natural Language Gains: The improvements in summarization and translation were "non-trivial though smaller" than in code. The authors suggest this is because natural language has much higher semantic redundancy.
  • Safety and Bias: The authors acknowledge they did not evaluate whether this reranking method increases the likelihood of selecting biased or toxic generations, a critical area for future safety research.
  • Similarity Functions: While n-grams are fast, the authors briefly explored using embeddings (like OpenAI's text-ada-002) for similarity. While promising, it was more computationally expensive and didn't always beat the simpler n-gram approach for code.

Summary updated

BibTeX
@inproceedings{jain2024lightweight,
  author = {Siddhartha Jain and Xiaofei Ma and Anoop Deoras and Bing Xiang},
  title = {{Lightweight reranking for language model generations}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.acl-long.376},
}
Figure