EXPLAINER

Best-of-N Sampling

techniquefreshness: evolvingsources not yet verified

Best-of-N draws several candidate answers and returns the one a scorer — a reward model, verifier or test — rates highest.

Short answer: Best-of-N = generate N candidates, score them, return the best. Its quality is capped by the scorer: a good verifier gives large gains, a weak one can pick fluent but wrong answers.

What is it?

Generate several answers, grade each one, keep the top-scoring answer. The grader might be unit tests (for code), a calculator, or a trained reward model.

It only works as well as the grader. A good checker makes it very effective; a poor one rewards answers that merely look good.

Also known as: best of n, best-of-n, BoN, rejection sampling, generate and rerank, sample and rank, N-best reranking, verifier reranking.

Technical definition

Best-of-N (rejection sampling at inference) selects argmax of a scoring function over N samples. Scorers include executable checks, outcome reward models (Outcome Reward Model (ORM)), process reward models (Process Reward Model (PRM)) and LLM judges (LLM-as-a-Judge). Over-optimising against an imperfect learned scorer can degrade true quality as N grows (reward-model over-optimisation, see Reward Hacking and Over-Optimization). It is also used offline to build training data (rejection-sampling fine-tuning).

Entity type: technique · Freshness class: evolving.

When should I use it?

Use when an automatic checker exists or can be trained, and the task is worth N times the inference cost.

Implementation patterns

  • Code: generate N programs, run tests, return the first or best passing candidate.
  • Math: score with a verifier or a calculator-backed checker.
  • Writing: rank with a rubric-based judge, with a human spot-check.
  • Training data: keep only the best samples for supervised fine-tuning.

Technologies and frameworks

Commonly associated: unit tests / executors, reward models, LLM-as-judge, vLLM n-sampling. Names are examples of what exists, not recommendations, and projects change quickly.

Practical guide

  1. Define a scorer you trust on a labelled set.
  2. Generate N diverse candidates.
  3. Select top-scoring; log scores.
  4. Plot accuracy vs N on held-out cases and stop where the curve flattens.
  5. Spot-check selected answers by hand (How to Evaluate AI Systems and Outputs).

Common failure modes

  • Scorer bias: the scorer prefers length, confident tone or its own style.
  • Over-optimisation: very large N against a learned scorer selects its blind spots.
  • No diversity: low temperature yields near-duplicates.
  • Cost grows linearly with N with no measured gain.

Troubleshooting

  • Chosen answer looks good but is wrong — Use an objective check (tests, retrieval evidence) in place of or alongside the learned scorer.
  • Quality plateaus or falls at large N — Reduce N; retrain or replace the scorer.
  • Samples nearly identical — Increase temperature/top-p diversity.

Contrasted with

Questions this page answers

  • What is best-of-N sampling?
  • How do I choose the best LLM output automatically?
  • Does best-of-N help with code generation?
  • What is the risk of best-of-N with a reward model?

Typical goals: pick the best of several model answers; use tests or verifiers to choose outputs; avoid reward over-optimisation.

Sources and verification

Status: not independently verified. This entry was authored on 2026-10-06 from general technical knowledge, without live checking of the sources below. Treat every source as a lead to confirm (identifier, title, authorship, current version) before publication or citation.

Freshness class: evolving — Established techniques whose best practice shifts as research and tooling move. Re-review every 6 months.

Canonical sources (unverified leads):

  • Cobbe et al., Training Verifiers to Solve Math Word Problems (2021) — arXiv:2110.14168
  • Gao et al., Scaling Laws for Reward Model Overoptimization (2022) — arXiv:2210.10760
Learning path: Reasoning models and test-time compute (step 6 of 11)