Best-of-N sampling
Generating several answers to the same prompt and keeping the best one, chosen by a test, a score or another model acting as judge.
Best-of-n is generating several answers to the same prompt and keeping the best one, chosen by a test, a score or another model acting as judge. Model output varies between runs, so asking N times and choosing raises quality without changing the model.
The choice can be code (does it compile, does the JSON validate), a scoring function or an LLM judge. A related method, self-consistency (Wang et al., 2022), samples several reasoning paths and keeps the most common final answer, with no judge at all. Best-of-n costs N times the tokens and adds the judge’s cost, so it fits work where quality matters more than speed, such as published text or generated code. The selector caps the gain: a judge that cannot tell good from bad picks at random, however many candidates it gets.
Best-of-n runs candidates side by side and picks once. An evaluator-optimizer loop works in sequence: the judge’s feedback goes back to the generator for a better next attempt. Adversarial review adds a second model that attacks the chosen answer. Your evals tell you whether extra candidates still beat one careful run.
Sources
Related terms
- LLM as judge: Using a model with a rubric to grade another model’s output.
- Evals: A repeatable test set that scores an AI feature, so changes can be measured instead of guessed.
- Tokens: The pieces of text models read and write, and the unit you pay for.
- Evaluator-optimizer (maker-checker): One model drafts, another checks the draft against stated criteria and returns feedback, in a loop until it passes or a round limit stops it.
- Adversarial review (cross-model review): Asking a second AI model, or a fresh agent, to find what is wrong with a change before a person reviews it, instead of asking the author to check itself.
