liveBook · Manning

Verifier

As explained in Build a DeepSeek Model (From Scratch)

A deterministic checker is a procedure that evaluates an output against fixed criteria and produces the same result for the same input.

A verifier is a deterministic checker that evaluates an output against fixed criteria and returns the same result for the same input. In reinforcement learning with verifiable rewards (RLVR), it replaces a learned reward model when correctness is mechanically checkable, especially for mathematics, code, and symbolic tasks. section 7.5 section 7.5.2

Design a useful verifier around four practical requirements:

  • Parse outputs reliably by enforcing a structured final-answer region, such as “Final answer:”, rather than guessing among multiple candidate answers. section 7.10.1 section 7.14
  • Reward real correctness while tolerating harmless formatting differences; production mathematics may require symbolic equivalence, unit normalization, decimal tolerance, and structured extraction. section 7.5.1
  • Check the artifact that matters: execute code against tests or a compiler, validate symbolic results against formal rules, or compare a mathematical answer with a known result. section 7.5
  • Audit for reward hacking because incomplete tests, brittle extraction, or checking only the final number can produce misleading training signals. section 7.14 section 7.5.1

Minimal answer verifier

A toy math verifier extracts the last integer or decimal with a regular expression, returns zero when no number is found, and returns one only when the extracted value exactly matches the gold answer. This demonstrates RLVR but should be strengthened before production use. section 7.8.1

Listing 7.2 A minimal verifier for answer-only math prompts
import re
def extract_final_number(text: str) -> str | None:
    """Return the last integer or decimal number found in a completion."""
    matches = re.findall(r"-?\d+(?:\.\d+)?", text)
    return matches[-1] if matches else None
def verify_math_answer(completion: str, gold: str) -> float:
    """A toy RLVR reward for answer-only math tasks."""
    predicted = extract_final_number(completion)
    if predicted is None:
        return 0.0
    return 1.0 if predicted == str(gold) else 0.0

Inspect the compact Python implementation of final-number extraction and binary reward assignment. section 7.8.1

How Build a DeepSeek Model (From Scratch) covers it

How deep it goes
Builds a toy extractor-and-comparator, then extends design to formatting, equivalence, tolerance, parsing, and reward-hacking risks.
Examples
Uses final-number extraction, unit tests, compilers, symbolic rules, structured answers, and reasoning/final-answer formatting.
What it assumes
Assumes reinforcement-learning context but teaches deterministic reward checking and output parsing from a simple implementation.
What you can do after
Build it from scratch for simple answer-only tasks and evaluate when stronger parsing or preference signals are required.
How it connects
Connects RLVR with reward models, format rewards, reinforcement learning, supervised fine-tuning, and reward hacking.

Also explained in

Compare how 9 books explain verifier →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a DeepSeek Model (From Scratch). The section links point to the parts of the book it draws on.