Self-consistency draws many answers and votes. Self-refinement keeps one draft and asks the model to improve it. The loop needs a score, otherwise “improve” is just another sample and you have no reason to keep the new draft instead of the old one.

Two scores are developed here. A rule score is a heuristic on the text. A log-probability score reads the model’s own token probabilities. Neither score is the verifier from Module 3. They are available when you do not want to call the grader inside the loop, and the log-probability score is the same quantity Module 6 will differentiate.

A revision loop

draft score revise keep
Figure 5.1. Each revision is a new completion. The score decides which draft survives.

Figure 5.1 runs for a fixed number of rounds, usually a handful. The prompt for a revision contains the original question, the current draft, and an instruction to correct it and box the answer again. The model does not see a gradient. It sees text.

Keep every draft, not only the last one. The last round is not reliably the best. Return the draft with the highest score, and record the score trajectory. A trajectory that never rises means the revision prompt is not giving the model anything to push against.

A rule score

Definition 5.1 (Rule score).

A rule score is a scalar computed from the decoded string by a fixed function, with no call to the model and no call to the grader. It may reward the presence of a boxed answer and penalize length. It does not test correctness.

Definition 5.1 exists so the idea of “rank two completions” is concrete before probabilities show up. It is a weak ranker. Two correct solutions can receive different scores because one is shorter. Two incorrect solutions can outrank a correct one. Use it as a baseline, then compare it to the log-probability score on the same pairs.

A minimal version:

def rule_score(text: str) -> float:
    score = 1.0 if last_boxed(text) is not None else 0.0
    score -= 0.001 * len(text)
    return score

The length penalty is a tie-break, not a model of quality. The coefficient should be too small to overturn the presence of a box.

From logits to a sequence score

At step the model emits logits . The token probability and its log are

The second form is the numerically stable one. Subtract the max logit before the exp-sum, and do not compute the softmax and then take a log.

Definition 5.2 (Length-normalized log probability).

The confidence score of a completion is the mean token log probability

Definition 5.2 is a property of the generated tokens under the current model. It is not a probability that the answer is correct. A model can be nearly certain and wrong. What the score does measure is how peaked the model was along this particular string.

The mean, rather than the sum, is the right reduction for ranking. The sum equals , which grows more negative as grows, so a longer answer loses even when every token was likely. Ranking by the sum is a length penalty in disguise. Ranking by the mean compares per-token confidence. Module 6 will switch back to the sum, for a different reason: there the sum is the log-likelihood inside a policy gradient, and dividing by would rescale the learning signal by length.

In practice, compute with a teacher-forced forward pass on the prompt plus the completion, and average only over the completion positions. Including the prompt tokens measures how unsurprising the question was, which is not the question you asked.

Using the score inside the loop

At round :

  1. Decode the current draft and record .
  2. Build a revision prompt that quotes the draft.
  3. Sample a new completion. Greedy revision tends to echo the draft. A moderate temperature gives the model a chance to change the answer.
  4. Score the new completion. If it is higher, replace the incumbent.

Stop early when the boxed answer has been stable for two rounds and the score gain is below a small threshold. Otherwise you pay for tokens that restate the same solution.

The same score breaks ties in self-consistency. If two distinct answers each receive votes, prefer the one whose winning completion has the higher .

What this does not do

The loop does not know whether the boxed value matches the reference. Plugging the verifier in as the score turns the procedure into a search with an external oracle: generate, grade, keep the correct one if any sample hit it. That is a strong inference-time method, and it is closer to best-of- than to self-refinement. It also spends the verifier, which at training time is the reward. Keeping the score internal in this module makes the later distinction clear. A log probability can select among drafts. Only the verifier can tell you the draft is right.

Exercises: Homework 5.

Code