Self-consistency & best-of-N

In one sentence

Sample several reasoning paths at temperature > 0 and keep the answer most of them agree on, or let a verifier pick the best. Buys accuracy and a confidence signal for N× the tokens.

Analogy: Five accountants do the same tax return independently. If four reach the same total, trust it; if all five disagree, the case is hard, so escalate it.

N independent paths at temperature > 0, one vote on the final answer; the agreement rate doubles as a confidence score.

How it works

  • Sample at temperature ~0.7 so the paths differ, then vote only on the parsed final answers.
  • It works because wrong chains fail in many different ways, while correct chains converge on one answer.
  • With best-of-N, a verifier picks instead; a deterministic one (unit tests, SQL execution) beats any vote.
  • The agreement rate is a cheap confidence score: route low-agreement cases to a human.
  • Samples run in parallel, so latency grows far less than cost; production usually keeps N ≈ 3–10.

Check yourself

Answer to mark it learned; your answers aren't scored.

You wrap a claims calculator in self-consistency with N=7. Cost rose 7×, accuracy didn't move, and the logs show the 7 reasoning paths are word-for-word identical on every request. Most likely cause?

Go deeper

Full explanation

Self-consistency (Wang et al., 2022) replaces greedy decoding with a vote:

  1. Prompt with Chain-of-thought (CoT) and sample N completions at temperature ~0.7, so the reasoning paths actually differ.
  2. Parse each final answer (a number, a label, an option).
  3. Return the majority answer.

It works because wrong chains go wrong in many different ways, while correct chains tend to converge on the same answer. With PaLM 540B it added +17.9 points on GSM8K over single-path CoT. Returns diminish quickly; the paper used 40 samples.

Best-of-N swaps the vote for a verifier: generate N candidates and keep the highest-scoring one. The verifier can be unit tests (code), SQL execution, a schema check, a reward model or an LLM-as-a-judge. A deterministic verifier beats any vote; a weak judge just picks its favorite style.

Universal self-consistency (Chen et al., 2023) covers free text, where answers can't be exact-matched: the model sees all N candidates and picks the one most consistent with the others.

Two bonuses: the agreement rate is a cheap confidence score (route low-agreement cases to a human), and samples run in parallel, so latency grows far less than cost.

Code Majority vote over N sampled reasoning paths
pythonMajority vote over N sampled reasoning paths
import re
from collections import Counter
from openai import OpenAI

client = OpenAI()
MODEL = "gpt-4.1-mini"  # must accept temperature and n; some reasoning models do not

def final_answer(text: str) -> str | None:
    m = re.search(r"ANSWER:\s*\$?(-?[\d,]*\.?\d+)", text)
    return m.group(1).replace(",", "") if m else None   # normalize before voting

def solve(question: str, n: int = 7) -> tuple[str | None, float]:
    resp = client.chat.completions.create(
        model=MODEL,
        temperature=0.7,   # diversity is the point; T=0 gives N copies
        n=n,               # N independent reasoning paths in one call
        messages=[{"role": "user", "content":
                   f"{question}\nThink step by step, then end with 'ANSWER: <number>'."}],
    )
    votes = Counter(a for c in resp.choices if (a := final_answer(c.message.content)))
    if not votes:
        return None, 0.0
    best, count = votes.most_common(1)[0]
    return best, count / n   # agreement doubles as a confidence score

answer, agreement = solve(claim_question)
if agreement < 5 / 7:
    send_to_human_review(answer)   # low consensus: likely wrong or ambiguous
Real example

A claims bot computes reimbursement amounts from policy text. On a 500-claim golden set, single-sample CoT matches the adjuster's figure ~81% of the time. Sampling 7 paths at T=0.7 and voting lifts that to ~89%, at 7× the output tokens. The bigger win is routing: claims where fewer than 5 of 7 paths agree are ~15% of traffic but hold most of the remaining errors, so they go to a human and the auto-approved rest gets far more accurate.

Trade-offs +4 · −3

+ You gain

  • Large gains on tasks with a checkable final answer: math, extraction, classification, SQL.
  • No training and no new model: a thin wrapper around any chat API.
  • Agreement rate is a free confidence signal for routing and abstention.
  • Paths are independent and run in parallel: cost rises N×, latency much less.

− You pay

  • N× tokens per request; at volume it can cost more than simply using a stronger model.
  • Voting needs comparable answers; free text needs a judge or USC, which are weaker selectors.
  • Can't fix systematic errors: if the model is confidently wrong, all N paths agree on it.

Use it when

Low-volume, high-stakes decisions with a discrete answer (calculations, labels, extracted fields, offline data labeling), or when a cheap verifier such as tests or SQL execution exists for best-of-N.

Avoid it when

High-volume chat, long free-form generation, tight latency or cost budgets. Always compare against a stronger or reasoning model at the same spend first.

Numbers to know 4
  • Wang et al.: +17.9 points on GSM8K for PaLM 540B (40 sampled CoT paths vs greedy CoT).
  • OpenAI o1 on AIME 2024: 74% with one sample, 83% with consensus over 64, 93% reranking 1,000 samples with a learned scorer.
  • Cobbe et al.: a trained verifier on GSM8K gave roughly the boost of a 30× larger model.
  • In production, N ≈ 3–10 is the usual range; benchmarks report 32–64+, with diminishing returns.
Common pitfalls 4
  • Sampling at temperature 0: you get N copies of the same path and pay N× for nothing.
  • Voting on raw text: "42", "$42.00" and "forty-two" split the vote. Normalize before counting.
  • Using an unvalidated LLM judge as the best-of-N verifier: it rewards length and style, not correctness.
  • Not benchmarking the alternative: a stronger model at the same token budget often wins.
Interview questions 3

Answer out loud first, then reveal.

When is self-consistency worth N times the cost?Show answer

When three things hold: the task has a discrete, comparable answer, so votes mean something; errors are expensive relative to tokens, like financial calculations or labels that feed training; and volume is low enough that N× doesn't dominate the bill. I always benchmark it against the cheaper alternative at equal spend, because one call to a stronger or reasoning model often beats seven calls to a small one. And I sample adaptively: draw 3, stop if they agree, draw more only on disagreement.

How do you apply it when the output is free text, like a summary?Show answer

Exact-match voting breaks, so I have three options. Extract structured fields from each candidate and vote per field; that's my preference when the output contains checkable facts. Or universal self-consistency: show the model all N candidates and ask which agrees most with the others. Or best-of-N with a judge or reward model scoring each candidate. The last two are only as good as the selector, so I validate the judge against human labels first and watch its known biases toward length and position.

Does self-consistency still matter with reasoning models?Show answer

Less, but yes. Reasoning models internalize much of the exploration, so each extra sample adds less while costing more. OpenAI's own o1 numbers still show the effect: 74% on AIME with one sample, 83% with consensus over 64. In production I rarely pay 64×. I use the agreement of 3–5 samples as a confidence signal for routing, and spend on best-of-N where a cheap deterministic verifier exists, like running the test suite on generated code.