Language models, retrieval, prompting, and language adaptation · Reasoning, decoding, and discrete diffusion language · LNG072 · Algorithm
Self-consistency decoding
Samples multiple reasoning trajectories and aggregates their final answers, often by majority vote. It can improve answer reliability when different valid reasoning paths converge, at the cost of additional generations.
In CodeSplash
A CodeSplash feature runs part of this entry inside the app; some variants aren't offered. There's no Set up button; open it where the label says. It uses the AI model you set up in Settings › AI, and the project's AI privacy settings decide what it may send.
Do it in CodeSplash Run it on your own data in the app: Label with AI (a text column's menu in the data grid) and Predict › Models › LLM classifier…, Votes per text, with the AI model you set up in Settings › AI: a local model (Ollama or LM Studio) answers each text up to 15 times at temperature 0.7, the most common label wins and its share of the votes is the confidence. Votes are over labels, not over free-form reasoning paths with an answer parser, and hosted models refuse votes (they aren't sent a sampling temperature).
- Availability
- Partly runs in CodeSplash (AI)
- Code example
- Component demo, not a trained model
- Who ran it
- CodeSplash's own run
- CodeSplash's run
- The reference's example ran here in one language.
- The reference's record
- Python: The chapter's authors report running it; there is no record for this entry alone. R: Reviewed but not run: R wasn't available to the reference's authors.
Purpose
Samples multiple reasoning trajectories and aggregates their final answers, often by majority vote. It can improve answer reliability when different valid reasoning paths converge, at the cost of additional generations.
Question / objective
Can aggregating multiple sampled reasoning paths reduce errors relative to one sample?
Architecture / computational structure
A fixed generator supplies sampled trajectories and a deterministic parser/voter aggregates answers. No new learned parameters are required; sample count, temperature, normalization, and tie-breaking are hyperparameters.
Assumptions
Samples are often correlated and can repeat the same misconception.
Formula / computational definition
Draw z_1:M from a reasoning-generating policy, extract answers a_m, and choose argmax_a sum_m 1[a_m=a]. This is a sample-based aggregation over latent reasoning paths, not a hypothesis test.
Parameters and notation
Learned parameters: identified in the architecture subsection. Hyperparameters, design and inference choices: Sample count, temperature, answer-normalization/parser, tie-breaking rule, generation budget, and optionally confidence-weighted aggregation.
Fitting, fine-tuning, and adaptation
Keep model weights frozen and tune aggregation settings on validation problems. If fitting a weighted voter, use a separate labeled development set and report that added learned component. Compare equal-budget baselines and audit correlated errors; optional model fine-tuning is distinct from self-consistency.
How to use and calibrate
Compare accuracy versus total generated tokens, sample count, and temperature; report failure correlation and deterministic single-sample baselines. Use development data for settings and an independent test set for the final estimate. Report uncertainty across examples or seeds when the evaluation design supports it; model scores and self-assessments are not automatically calibrated probabilities of correctness.
Example application
Aggregate multiple generated solutions to a reasoning problem with an exact answer parser.
Interpretation / pitfalls
Watch out
Majority agreement is not a calibrated probability of truth; extraction errors and semantically equivalent answer formats distort voting. The code below isolates one stated component; successful execution does not validate model quality or reproduce the cited experiment.
Python and R code examples
Full implementation route: Generate multiple responses through a supported model interface, then aggregate with Python Counter or native R table. The example implements voting exactly for toy extracted answers; it does not claim that voting itself verifies factual correctness.
Example scope: Self-consistency majority voting on parsed toy answers, with deterministic lexical tie-breaking.
Dependencies: Python 3 standard library; base R; shared setup above. No model downloads or external services.
Validation: Python component executed in the combined example script; R counterpart supplied but not runtime-tested here. All numbers are synthetic.
Python and R
The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.
Component demo, not a trained model — Self-consistency majority voting on parsed toy answers, with deterministic lexical tie-breaking.
Shared setup for this chapter
import math
def softmax(xs):
m = max(xs)
es = [math.exp(x-m) for x in xs]
return [e/sum(es) for e in es]
def dot(a, b):
return sum(x*y for x, y in zip(a, b))
def matvec(matrix, vector):
return [dot(row, vector) for row in matrix]
def meanvec(rows):
return [sum(row[j] for row in rows)/len(rows) for j in range(len(rows[0]))]
def sigmoid(x):
return 1/(1+math.exp(-x))
def nll(probabilities):
return -sum(math.log(p) for p in probabilities)
answers = ["42","41","42","42","41"]
counts = {a:answers.count(a) for a in set(answers)}
selected = sorted(counts,key=lambda a:(-counts[a],a))[0]
print(counts,selected)
Component demo, not a trained model — Self-consistency majority voting on parsed toy answers, with deterministic lexical tie-breaking.
Shared setup for this chapter
softmax <- function(x) {
shifted <- exp(x-max(x))
shifted/sum(shifted)
}
answers <- c("42","41","42","42","41")
counts <- table(answers)
selected <- names(counts)[order(-as.numeric(counts),names(counts))][1]
print(list(counts=counts,selected=selected))
Sources
- Source 1arxiv.org
From the CodeSplash reference, entry LNG072.