- Key idea
- Latent variables, marginalisation, majority voting as the mode of a marginal, EM and the evidence lower bound
- Real world
- A doctor never observes a disease directly, only symptoms. Reasoning about the hidden cause, and averaging over the possible causes, gives a better prediction of what happens next than any single guess about the cause.
- In an LLM
- A reasoning model writes a long chain of thought , then a final answer . Only is graded. The probability of an answer is a sum over every chain of thought that could lead to it, and different chains reaching the same answer reinforce each other.
Latent variables
A latent variable is something that shapes what you see but isn't itself observed. Models with latent variables describe the observed thing through a hidden one :
Summing out the hidden variable is marginalisation. It's the law of total probability, with ranging over every possibility.
For reasoning models, is the question, the chain of thought, and the final answer. The sum over ranges over every possible reasoning text, so it can never be computed. But it can be sampled.
A cough could be a cold (70%), flu (25%) or pneumonia (5%). The chance of needing a hospital is 1%, 5% and 60% respectively. Marginalising:
The rare cause contributes most of the risk.
Asked for , a model might multiply directly, split it as , or compute . Each path has its own probability and each can slip. The probability of the final answer "408" is the sum over all the paths that end there.
Majority voting estimates the marginal
Self-consistency samples many chains of thought, throws away the reasoning, and returns the most common final answer. In probability terms: it estimates the marginal by counting, and returns its mode. Many different, individually unlikely chains that agree on one answer add up.
That's also its limit. If the most likely answer is wrong, voting converges to the wrong answer with more and more confidence. By contrast, pass@n ("did any sample get it right?") keeps rising with more samples, but needs a verifier to pick out the right one.
Try it
Ask 100 people to guess the number of sweets in a jar and take the most common guess. Usually better than a typical individual, as long as the crowd isn't biased the same way. If most people anchor on the same wrong number, asking more people only makes the vote more confident in it.
Brown et al. (2024) found that on coding and maths tasks, the fraction of problems solved by at least one of samples kept rising, roughly log-linearly, all the way to 10,000 samples. Majority voting and reward-model selection plateaued after a few hundred. The bottleneck is picking the right sample, not generating it.
Training a latent-variable model
To train by maximum likelihood on question–answer pairs, you'd maximise , the log of a sum over all chains of thought. Its gradient is
an average over the posterior : chains of thought, weighted by how likely they are given that they reach the right answer. By Bayes, that posterior is proportional to .
You can sample from it by rejection: generate chains, keep the ones that reach the correct answer. Then fine-tune on what you kept. That's exactly STaR and rejection-sampling fine-tuning, which turn out to be an approximate version of the classic expectation–maximisation (EM) algorithm:
- E-step: infer the hidden variable (sample chains that reach the right answer).
- M-step: train the model on them as if they had been observed.
And RL with a correct/incorrect reward is closely related: is itself, so the policy gradient for that reward is the gradient of the marginal likelihood, scaled by .
Where this shows up
- Self-consistency and majority voting at test time: Does RL teach new skills?.
- STaR, rejection-sampling fine-tuning, expert iteration: distillation.
- RLVR: the reward is "the latent reasoning produced the right answer": RLVR.
- Sampling the posterior over chains with MCMC (TRICE) or a learned sampler (GFlowNets): MCMC.
Marginal likelihood and its gradient
The identity follows from and Bayes' rule.
The evidence lower bound
For any distribution over chains of thought, Jensen's inequality gives
This is the ELBO. It's tight when equals the posterior. EM alternates between making close to the posterior (E-step) and maximising the bound in (M-step). The same bound, with a noise-adding process as the latent variable, is the training loss of diffusion models.
Self-consistency
As , , the mode of the marginal.
Papers
- Self-Consistency Improves Chain of Thought Reasoning in Language Models (Wang et al., 2022)
- Large Language Monkeys: Scaling Inference Compute with Repeated Sampling (Brown et al., 2024)
- STaR: Bootstrapping Reasoning With Reasoning (Zelikman et al., 2022)
- Training Chain-of-Thought via Latent-Variable Inference (Phan, Hoffman et al., 2023): TRICE, MCMC-EM for chains of thought
- Amortizing Intractable Inference in Large Language Models (Hu et al., 2023): GFlowNets to sample the posterior over reasoning
- Inference-Aware Fine-Tuning for Best-of-N Sampling in Large Language Models (Chow et al., 2024): training the model for the selection rule it will be used with