Search

Search papers and lessons

Math-Shepherd: Verify and Reinforce LLMs Step-by-step

Peiyi Wang, Lei Li, Zhihong Shao et al. · 2023

Math-Shepherd labels each step of math solutions automatically, using whether the step still reaches the correct answer, and trains a process reward model on those labels.

On this page

  • Colour = topic mix
  • Reinforcement learning
  • Probability
  • Discrete math
  • Calculus
  • Linear algebra
  • Neural network basics
  • ReadReady to readNot yet

TL;DR

Math-Shepherd is a process reward model for math. It gives every step of a model's solution a score, instead of scoring only the final answer, so a mistake can be found at the step where it happens. Its main contribution is how it gets those step labels: no human annotator is needed. For each step, a model finishes the solution many times, and the step counts as good if those finished solutions reach the correct answer. The scores are then used in two ways: to pick the best of many sampled answers, and as the reward signal for step-by-step reinforcement learning. Accuracy on the GSM8K and MATH benchmarks rises with both.

Builds on: Process Reward Model, Proximal Policy Optimization (PPO), Best-of-N Sampling · Leads to: later methods that label reasoning steps automatically (no lesson yet)

Why it mattered

Step-level reward models, the process reward models (PRMs), were known to work well by 2023, but their labels were expensive. Work by Uesato et al. (2022) and Lightman et al. (2023) used human annotators to mark each step of a math solution. Math-Shepherd showed that the same kind of model could be trained with labels produced automatically. In the paper's own experiments, Mistral-7B rose from 77.9% to 84.1% on GSM8K after step-by-step reinforcement learning, and reached 89.1% on GSM8K and 43.5% on MATH when its answers were reranked by the verifier. DeepSeek 67B reached 93.3% on GSM8K and 48.1% on MATH with verification by Math-Shepherd (48.1% uses self-consistency combined with the verifier). The authors call these results unprecedented for open models that use no external tools.

The problem

A reward model scores a candidate answer so the best one can be chosen, or so a generator can be trained. An outcome reward model (ORM) scores the whole solution with one number. Its training labels are cheap: check whether the final answer is right. But a solution with a correct answer and wrong reasoning gets a good label, and a long solution with one bad step gets no information about where the error is.

A process reward model (PRM) scores each step, which gives more precise feedback. The catch is the label. To label each step you need an expert to read the reasoning and judge it, and the paper argues this is costly for multi-step math that needs skilled annotators. The paper notes that earlier process reward models typically relied on such human labels. Math-Shepherd asks whether the labels can come from the data itself.

How it works

The method turns each solved training problem into labelled steps, trains a PRM on them, then uses the PRM in two ways.

flowchart LR
  A[Problem with golden answer] --> B[Solution split into steps]
  B --> C[Completer writes N continuations of one step]
  C --> D[Check each continuation's final answer]
  D --> E[Step label from HE or SE]
  E --> F[Train the PRM]
  F --> G[Rerank sampled answers]
  F --> H[Step-by-step PPO]

Here is one tiny instance traced through, with made-up numbers (the paper uses far larger sets).

  1. Start with a problem whose golden answer is 10, and a solution whose first step is "Start with 4 coins." The step is good if the rest of the solution can still reach 10. Check: the golden answer is known, so a label is possible.
  2. Hand that step to a completer. The completer is a language model that writes the rest of the solution from this point. In the paper it writes N = 8 continuations, each ending in an answer. Suppose 3 of the 8 end at 10. Check: there are 8 answers, 3 of them equal the golden answer.
  3. Turn those answers into a label. In the hard estimation (HE) version, the step is labelled 1 if at least one continuation reaches 10. Here the label is 1. In the soft estimation (SE) version, the label is the fraction that reaches 10, which is 3 out of 8. Check: HE gives 1 and SE gives 0.375.
  4. Repeat for every step of every solution. The paper samples 15 solutions per problem from its generators, removes duplicates, and ends up with about 170k labelled solutions for GSM8K and 270k for MATH. Check: each solution now carries one label per step.
  5. Train the PRM as a classifier. Each step gets a score between 0 and 1 that predicts its label. The paper uses HE for its main runs, since it fits a standard language-modelling setup with two special tokens for "has potential" and "no potential". Check: the PRM can be trained with ordinary cross-entropy.
  6. Use the PRM to rank candidates, as in best-of-N selection. Sample 256 solutions, score each, and give each solution the minimum score over its steps. The best minimum wins. Check: a solution with one step scored 0.2 loses to one whose lowest step is 0.6.
  7. Use the PRM as a reward in reinforcement learning. The paper's step-by-step PPO gives a reward at the end of each step, rather than one reward at the end of the whole answer. Check: the same answer gets several reward signals instead of one.

The math

Definition: Process reward model (as used here)
A function that takes a problem p and a solution s split into steps s_1 to s_K, and returns one score r_{s_i} between 0 and 1 for every step. A solution's score is the lowest of its step scores.

Step 1 in symbols: the outcome reward model

An ORM gives one score r_s to a whole solution s. Its label y_s is 1 if the final answer is correct and 0 otherwise. The paper trains it with cross-entropy:

LORM=yslog⁡rs+(1−ys)log⁡(1−rs)\mathcal{L}_{ORM}=y_{s}\log r_{s}+(1-y_{s})\log(1-r_{s})

Here r_s is the sigmoid score. The expression is a binary cross-entropy written with the sign flipped: it is largest when the score r_s is high for a label of 1 and low for a label of 0, so training maximises it, or equivalently minimises its negative.

Step 2 in symbols: the step label

Let a* be the golden answer, and let a_1 to a_N be the final answers of the N continuations of step s_i. The two estimators are:

ysiHE={1if some aj=a∗0otherwisey_{s_{i}}^{HE}=\begin{cases}1 & \text{if some } a_{j}=a^{*}\\ 0 & \text{otherwise}\end{cases} ysiSE=1N∑j=1NI(aj=a∗)y_{s_{i}}^{SE}=\frac{1}{N}\sum_{j=1}^{N}\mathbb{I}(a_{j}=a^{*})

HE asks whether the step can reach the answer at all. SE asks how often it does.

Step 3 in symbols: the process loss

Each step of a solution gets its own term, and the terms are summed over the K steps:

LPRM=∑i=1K[ysilog⁡rsi+(1−ysi)log⁡(1−rsi)]\mathcal{L}_{PRM}=\sum_{i=1}^{K}\left[y_{s_{i}}\log r_{s_{i}}+(1-y_{s_{i}})\log(1-r_{s_{i}})\right]

This is Step 1's loss applied once per step.

Step 4 in symbols: a solution scored by its weakest step

The paper follows an earlier convention and takes the minimum step score:

score(s)=min⁡i=1,…,Krsi\text{score}(s)=\min_{i=1,\ldots,K} r_{s_{i}}

Step 5 in symbols: combining votes and scores

With N candidate solutions, each with a final answer a_i and a reward-model score RM(p, S_i), the self-consistency plus reward-model choice is:

asc+rm=arg max⁡a∑i=1NI(ai=a)⋅RM(p,Si)a_{sc+rm}=\operatorname{arg\,max}_{a}\sum_{i=1}^{N}\mathbb{I}(a_{i}=a)\cdot RM(p,S_{i})

Each answer gets the sum of the scores of the solutions that reach it, and the answer with the largest sum wins.

Results

Verification (Table 1, 256 candidates per problem, GSM8K full test set and MATH500):

  • LLaMA2-70B: self-consistency 88.0 on GSM8K and 39.4 on MATH500, ORM 91.8 and 40.4, Math-Shepherd 93.2 and 44.5.
  • LLemma-34B: self-consistency 82.6 and 44.2, ORM 90.0 and 43.7, Math-Shepherd 90.9 and 46.0.
  • DeepSeek-67B: Math-Shepherd alone reaches 93.3 on GSM8K, and self-consistency plus Math-Shepherd reaches 48.1 on MATH500.

Reinforcement learning (Table 2, greedy decoding, with KL penalty 0.04 in PPO):

  • LLaMA2-7B: base 66.6 on GSM8K and 19.2 on MATH; step-by-step PPO with Math-Shepherd gives 73.2 and 21.6.
  • Mistral-7B: base 77.9 and 28.6; ORM-based PPO gives 81.8 and 31.3; step-by-step PPO gives 84.1 and 33.0.

Combining both (Table 3, Mistral-7B): step-by-step PPO followed by self-consistency plus Math-Shepherd reaches 89.1 on GSM8K and 43.5 on MATH500.

Label quality: on 160 steps the authors labelled by hand, HE labels from LLaMA2-70B as completer reach 86% accuracy at N = 4. In Table 4, the NLI-based method from Li et al. reaches 61.3 and 75.6 accuracy, the rule-based method 75.0, and Math-Shepherd with LLaMA2-13B and N = 4 reaches 85.0. These use different setups, so they are not a clean head-to-head.

Limits the paper itself states or shows:

  • Evaluation is on math word problems (GSM8K) and one MATH subset (MATH500), plus one out-of-distribution exam of 33 questions where the PRM beat the ORM by 9 points out of 100.
  • Label accuracy falls as N grows beyond 4, which the authors attribute to false positives.
  • Labels carry noise by design: a flawed step can still reach the right answer by luck, and a correct step can be labelled 0 when the completer slips. The paper argues the signal is still useful.
  • The quality of the completer matters: a completer trained on weaker data produced noticeably worse labels.
  • The gains from reinforcement learning are modest on greedy decoding, and the paper leaves iterative reinforcement learning for future work.

Reading guide

Check yourself

QuestionIn one sentence, what does an ORM score and what does a PRM score?Show answer
An ORM gives one score to a whole solution, based on whether its final answer is right. A PRM gives a score to each step of the solution, so it can point to where the reasoning goes wrong.
QuestionA step has 16 continuations, and 12 of them reach the golden answer. What is the SE label, and what is the HE label?Show answer
SE is 12 divided by 16, which is 0.75. HE is 1, because at least one continuation reaches the golden answer.
QuestionWhy does the paper score a solution by its minimum step score, not its average?Show answer
A solution is only as reliable as its weakest step. One clearly wrong step makes the whole chain doubtful, and a minimum keeps that signal. An average would let several good steps hide one bad one.
QuestionTwo solutions have step scores 0.9, 0.9, 0.1, 0.9 and 0.6, 0.6, 0.6, 0.6. Which one does the minimum rule choose, and why?Show answer
The second, with minimum 0.6. The first has minimum 0.1 because of its one low step, so the rule prefers the consistently moderate solution.

Sources

Read the full paper

Peiyi Wang, Lei Li, Zhihong Shao et al., 2023. arXiv:2312.08935