AI Wiki中文/EN

Verifiable rewards: the checker defines what gets rewarded

可验证奖励

Build a bounded arithmetic verifier and expose a value-only reward shortcut.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

The string “24” passes one checker and fails the actual puzzle

A task asks for an arithmetic expression using 1, 3, 4 and 6 exactly once to make 24. A checker that only evaluates the final value accepts 24 and 6*4. Neither uses the required cards. A policy rewarded by that checker has no reason to infer the missing requirement on its own.

Verifiable rewards derive a training signal from an executable check, such as exact answers, program tests or proof checking. What is verified depends on the specification and implementation. A deterministic reward can be reproducible while still incomplete.

DeepSeek-R1’s authors, section 2.2.2, describe rule-based accuracy and format rewards for R1-Zero. The full R1 pipeline also uses preference rewards for general data, as section 2.3.4 states; the R1-Zero description should not be generalized to every stage of R1. Lightman and colleagues, section 2.5, illustrate a related limitation: correct final answers can accompany incorrect reasoning.

Checking card usage changes which shortcuts receive rewards.
Checking card usage changes which shortcuts receive rewards.

Separate the specification from the reward value

For our four-card task, a complete acceptance condition within the declared expression language is:

V(e)=Vsyntax(e)∧Vcards(e)∧Vvalue(e).V(e)=V_{\mathrm{syntax}}(e)\land V_{\mathrm{cards}}(e)\land V_{\mathrm{value}}(e).

The syntax permits integer leaves and binary addition, subtraction, multiplication and division. The card check compares the multiset of leaves with (1,3,4,6). The value check uses exact rational arithmetic and rejects division by zero. A different task might permit other operations, but then its specification and checker must change together.

A value-only checker verifies less:

Vweak(e)=1{value⁡(e)=24},V(e)=1⟹Vweak(e)=1.V_{\mathrm{weak}}(e)=\mathbf1\{\operatorname{value}(e)=24\},\qquad V(e)=1\Longrightarrow V_{\mathrm{weak}}(e)=1.

The reverse implication fails. The expression 24 is a direct counterexample. This is a specification gap, not a floating-point bug or a failure of the optimizer.

In general, a reward can combine task and format checks:

r(e)=αVtask(e)+γVformat(e).r(e)=\alpha V_{\mathrm{task}}(e)+\gamma V_{\mathrm{format}}(e).

The weights must be declared; this formula is an illustrative design, not an assertion about unpublished coefficients in the cited system. If a format bonus can outweigh task failure, the total score may prefer well-formatted wrong answers. Our experiment instead uses one binary acceptance reward and no format bonus.

Let pip_i be a policy over a fixed candidate set, qi>0q_i>0 a reference and rir_i the checker rewards. We optimize:

J(p)=∑ipiri−βDKL(p∥q),β>0.J(p)=\sum_i p_i r_i-\beta D_{\mathrm{KL}}(p\Vert q),\qquad \beta>0.

The reference is uniform in the program. The candidate set is explicitly authored, so the policy learns selection probabilities rather than generating new expressions. The exact optimum is:

pi∗=qieri/β∑jqjerj/β.p_i^*=\frac{q_i e^{r_i/\beta}}{\sum_jq_j e^{r_j/\beta}}.

With logits zz and p=softmax⁡(z)p=\operatorname{softmax}(z), define ai=ri−βlog⁡(pi/qi)a_i=r_i-\beta\log(p_i/q_i). An exact finite-expectation gradient is:

∂J∂zi=pi(ai−∑jpjaj).\frac{\partial J}{\partial z_i}=p_i\left(a_i-\sum_jp_ja_j\right).

The program actually performs gradient ascent and reports its remaining difference from the oracle. It is not PPO or GRPO training. Those algorithms address other sampling and optimization details; the distinction between reward specification and optimizer remains.

The R1 paper’s section 2.2.1 describes group-relative reward normalization. A small helper illustrates that operation with an explicit zero-variance convention:

Ai={(ri−r‾)/sr,sr>0,0,sr=0.A_i=\begin{cases}(r_i-\overline r)/s_r,&s_r>0,\\0,&s_r=0.\end{cases}

Here srs_r is the population standard deviation of the finite group. The zero branch is our teaching choice, not a claim about the source implementation. For equal rewards, there is no within-group ranking signal. The helper is reported separately and is not used by the policy optimizer above.

Use a bounded interpreter, not code execution

The complete Python/NumPy program parses expressions into an AST and recursively interprets only the allowed arithmetic nodes. It does not call Python eval or run candidate code. Limits on text length, AST nodes, depth, integer leaves and rational bit length keep the accepted input language bounded.

"""Original bounded arithmetic verifier and exact-expectation policy training; no generated code execution."""
import ast,json
from collections import Counter
from fractions import Fraction
import numpy as np


def evaluate(expression):
    if not isinstance(expression,str) or len(expression)>120:raise ValueError("Expression too long or not text")
    try:tree=ast.parse(expression,mode='eval')
    except (SyntaxError,RecursionError):raise ValueError("Invalid expression") from None
    if sum(1 for _ in ast.walk(tree))>64:raise ValueError("Expression too large")
    leaves=[]
    def visit(n,depth=0):
        if depth>12:raise ValueError("Expression too deep")
        if isinstance(n,ast.Constant) and type(n.value) is int and abs(n.value)<=100:
            leaves.append(n.value);return Fraction(n.value)
        if not isinstance(n,ast.BinOp) or not isinstance(n.op,(ast.Add,ast.Sub,ast.Mult,ast.Div)):
            raise ValueError("Only integer leaves and four binary arithmetic operations allowed")
        a,b=visit(n.left,depth+1),visit(n.right,depth+1)
        if isinstance(n.op,ast.Add):v=a+b
        elif isinstance(n.op,ast.Sub):v=a-b
        elif isinstance(n.op,ast.Mult):v=a*b
        else:
            if not b:raise ValueError("Division by zero")
            v=a/b
        if max(v.numerator.bit_length(),v.denominator.bit_length())>512:raise ValueError("Arithmetic size limit")
        return v
    value=visit(tree.body)
    return value,Counter(leaves)


def verify(expression,cards=(1,3,4,6),target=24,strict=True):
    try:value,used=evaluate(expression)
    except ValueError:return False
    return value==target and (not strict or used==Counter(cards))


def standardized(rewards):
    r=np.asarray(rewards,dtype=float)
    if r.ndim!=1 or not len(r) or not np.isfinite(r).all():raise ValueError("Finite reward vector required")
    std=float(r.std())
    return np.zeros_like(r) if std==0 else (r-r.mean())/std


def objective_grad(logits,rewards,beta=.2):
    if (logits.ndim!=1 or logits.shape!=rewards.shape or not len(logits)
        or not np.isfinite(logits).all() or not np.isfinite(rewards).all()
        or not np.isfinite(beta) or beta<=0):raise ValueError("Invalid policy objective")
    logp=logits-np.logaddexp.reduce(logits);p=np.exp(logp)
    adjusted=rewards-beta*(logp+np.log(len(p)))
    objective=float(p@adjusted)
    return objective,p*(adjusted-objective)


def train(rewards,steps=3000):
    z=np.zeros(len(rewards));trace=[]
    for k in range(steps+1):
        objective,g=objective_grad(z,rewards)
        if k%300==0:trace.append([k,objective])
        if k<steps:z+=.4*g
    return np.exp(z-np.logaddexp.reduce(z)),trace


def demo():
    expressions=['6/(1-3/4)','24','6*4','(6+4)*(3-1)','6/(3-3)']
    weak=np.array([verify(e,strict=False) for e in expressions],dtype=float)
    strict=np.array([verify(e) for e in expressions],dtype=float)
    runs=[]
    for name,rewards in [('value_only',weak),('card_usage_and_value',strict)]:
        p,trace=train(rewards);oracle=np.exp((rewards-rewards.max())/.2);oracle/=oracle.sum()
        runs.append(dict(name=name,rewards=rewards.tolist(),policy=p.tolist(),
            valid_probability=float(p@strict),oracle_error=float(np.max(abs(p-oracle))),trace=trace))
    return dict(expressions=expressions,runs=runs,group_advantages=standardized([1,0,0,1]).tolist(),
        all_equal_advantages=standardized([0,0,0,0]).tolist(),
        scope='Bounded AST interpreter, synthetic candidate set and exact policy gradient; no eval, model sampling, PPO or GRPO training.')


if __name__=='__main__':print(json.dumps(demo(),indent=2))

The candidate set contains one valid solution, two value-only shortcuts, one wrong result and one division by zero. Weak rewards are (1,1,1,0,0); strict rewards are (1,0,0,0,0).

After 3,000 updates at β=0.2\beta=0.2, the weak-reward policy assigns the valid expression probability about 0.33129851. The strict-reward policy assigns it about 0.97374794. The reported maximum errors from their respective exact optima are about 0.000816294 and 0.00000760402, so neither run is mislabeled as exactly converged.

The three weakly rewarded candidates remain equally probable because their rewards and initial logits are symmetric. The weak checker cannot distinguish their task validity. Changing the optimization algorithm without changing the reward would not supply the missing card-usage condition.

For an expression with LL AST nodes, interpretation uses O(L)O(L) node visits, with additional exact-integer arithmetic costs. The fixed-candidate gradient costs O(K)O(K) per update for KK expressions. Running arbitrary programs against tests would require a different execution and isolation design; this arithmetic interpreter does not provide that facility.

Passing the check proves only the checked condition

An exact-answer check may miss reasoning errors or alternate valid answer representations. Program tests may miss untested inputs. A parser can accept unintended syntax or reject valid solutions. Bounds improve predictability but narrow the supported task language. Each condition belongs in the checker contract and its tests.

Rule-based rewards also depend on task data: a wrong expected answer produces a wrong reward even if evaluation is exact. A policy can exploit repeated examples or accidental parser conventions. Separate holdout tasks and adversarial checker tests address different failure modes.

R1-Zero’s rule rewards are a reported training design, not proof that every capability can be assessed with rules. The full R1 system’s other reward sources further show that “verifiable” is not a replacement for all forms of supervision. Our five-expression experiment establishes its finite mechanism only; it does not reproduce large-scale reasoning emergence or a benchmark result.

Try to satisfy the score without satisfying the task

  1. Why does the weak verifier accept 6*4 while the strict verifier rejects it?

Answer: Its exact value is 24, but its leaf multiset omits 1 and 3. The strict verifier requires both value and exact card usage.

  1. Is 6/(1-3/4)+0 valid for the declared task?

Answer: No. It evaluates to 24 but introduces an extra zero card. The value-only check accepts it; the multiset condition rejects it.

  1. For group rewards (1,0,0,1), what normalized advantages does the helper produce? What about all-zero rewards?

Answer: The first group has mean 0.5 and standard deviation 0.5, producing (1,-1,-1,1). The all-zero group uses the explicit zero-variance branch and returns zeros.

  1. Would an optimizer with no numerical error fix the value-only checker?

Answer: No. Its exact optimum would still reward the shortcuts equally with the valid expression. Optimization accuracy and specification completeness are separate requirements.

Read the reward definition separately from the headline result

DeepSeek-R1 sections 2.2.1–2.2.3 specify the R1-Zero optimization overview, rule rewards and formatting; section 2.3.4 describes additional reward sources in R1. Lightman’s sections 2.5–2.6 separate outcome checking from step supervision. Reproducing a result requires the task, data, checker, parser and optimizer together, with their actual limitations.

Make a prediction, then check

Does reaching24 prove a four-card arithmetic expression obeys the task?

Choose one answer

Learning objectives

  • Separate task validity, parser rules, format rewards and optimizer behavior.
  • Reproduce the finite example and state its experimental limits.

Prerequisites & connections

Explore related knowledge →

References

  1. DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning — v1
    DeepSeek-AI · 2025
  2. Let’s Verify Step by Step — v1
    Hunter Lightman; Vineet Kosaraju; Yura Burda; Harri Edwards; Bowen Baker; Teddy Lee; Jan Leike; John Schulman; Ilya Sutskever; Karl Cobbe · 2023

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-20 · Single AI author. Viewed PDF5/6/11 sections2.1,2.2.1–2.2.3,2.3.4: R1-Zero versus R1, GRPO group normalization, rule-based accuracy/format rewards, and general-data preference rewards in full R1. No model training or benchmark replicated. Read sections2/2.1 text, viewed PDF4/5/6 sections2.3–2.6: fixed generator, positive/negative/neutral labels, first-error censoring, final-answer false positives and product PRM score. No human dataset or GPT-4 reproduction. Seven paired equations and four explained exercises. Bounded non-executing AST interpreter checks exact value and card multiset. Weak shortcuts, all-logit gradients, finite-step oracle gaps and zero group variance checked. Finite policy example does not implement GRPO/PPO.

  • Bounded non-executing AST interpreter checks exact value and card multiset. Weak shortcuts, all-logit gradients, finite-step oracle gaps and zero group variance checked. Finite policy example does not implement GRPO/PPO.
  • Four computed SVG variants per topic;11 numeric/geometry tests and36 responsive cases passed. Twelve selected final captures directly viewed. Full article acceptance recorded separately.

Source locations checked:

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.