GSM8K tests grade-school mathematical reasoning with multi-step word problems. Covers dataset structure, answer scoring, and known benchmark limitations.
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Language models have achieved remarkable fluency in generating coherent text, but reasoning about quantities, operations, and multi-step mathematical problems presents a distinct challenge that probes the boundary between pattern matching and real cognition. While a model might produce grammatically perfect prose, can it reliably calculate how many apples remain after a series of transactions, or determine the time required for two workers to complete a task together? These questions expose a basic tension in artificial intelligence: the difference between statistical correlation in language and the structured, logical manipulation of symbols required for mathematical reasoning.
Mathematical word problems demand capabilities that extend far beyond next-token prediction. They require the model to ground abstract numerical concepts in concrete scenarios, maintain state across multiple transformations, and execute precise calculations without drift. Unlike open-ended creative writing where approximate coherence suffices, mathematical problems admit only exact solutions. An answer of 17 when the truth is 18 is a complete failure, regardless of how plausible the reasoning appeared. This binary correctness criterion makes mathematical reasoning an ideal probe for studying the limits of language model cognition.
The Grade School Math 8K (GSM8K) dataset became an important benchmark for answering these questions with rigor and specificity. Unlike simpler arithmetic tests that probe only calculation accuracy, GSM8K requires models to parse natural language descriptions of real-world scenarios, identify needed quantities, formulate appropriate mathematical operations, and execute multi-step reasoning chains to arrive at numerical answers. This benchmark has become a de facto standard for measuring the mathematical reasoning capabilities of large language models, revealing important insights about how scaling, prompting strategies, and training methodologies affect problem-solving performance.
In this chapter, we examine the structure and composition of GSM8K, explore how chain-of-thought prompting transforms model performance on mathematical tasks, analyze the specific accuracy metrics used to evaluate solutions, and discuss the broader implications of this benchmark for assessing reasoning in language models. We trace the evolution from simple pattern matching to explicit step-by-step reasoning, revealing how the field learned to elicit latent capabilities through careful prompt engineering and evaluation methodology. We also examine recent extensions beyond standard prompting, including program-of-thought approaches, tool-augmented inference, and the process supervision paradigm that treats reasoning quality as a first-class signal.
Standard language model training optimizes for predicting the next token given all preceding tokens. This objective is exceptionally well suited for acquiring syntactic fluency, factual associations, and stylistic patterns from large text corpora. However, it creates a specific blind spot: the model has no built-in mechanism for enforcing consistency across long reasoning chains. When generating prose, a small inconsistency in paragraph four rarely invalidates the argument in paragraph two. When solving a math problem, a single arithmetic error in step three propagates to every subsequent step, guaranteeing a wrong final answer.
Consider how humans approach mathematical word problems. A student reads the problem, mentally identifies the needed quantities and their relationships, sketches a solution plan, executes calculations step by step, and checks the result against intuition. Each of these phases is a distinct cognitive operation. For language models trained purely on text prediction, there is no explicit training signal that rewards correct sequential calculation over plausible-sounding but wrong calculation. The model learns that certain numerical patterns follow certain textual patterns, but this correlation-based learning does not enforce the logical constraints that make mathematical reasoning trustworthy.
This gap motivated researchers to build evaluation tools specifically targeting multi-step mathematical reasoning. Early datasets like MAWPS (Math Word Problems) and the AQUA-RAT dataset probed arithmetic and algebraic reasoning but varied in difficulty, linguistic diversity, and annotation quality. GSM8K represented a deliberate effort to create a benchmark with consistent difficulty calibration, high annotation quality, and problem diversity that would remain challenging enough to be informative as models improved.
Karl Cobbe, Vineet Kosaraju, Mohammad Bavarian, Jacob Hilton, Reiichiro Nakano, Christopher Hesse, and John Schulman at OpenAI released GSM8K in 2021. The design philosophy was intentional in several respects.
First, the mathematical content was deliberately constrained to grade school arithmetic. Addition, subtraction, multiplication, and division over natural numbers constitute the entire computational vocabulary. This choice was not a reflection of low ambitions. It was a recognition that linguistic and reasoning complexity could be studied in isolation from mathematical sophistication. A model that cannot reliably perform three-step grade school arithmetic has a basic reasoning limitation regardless of its linguistic capabilities. By anchoring the math at elementary level, the benchmark ensures that any failure is a reasoning failure, not a knowledge failure about advanced mathematical concepts.
Second, the solutions were annotated with detailed natural language explanations rather than just final numeric answers. The researchers had a specific purpose: these annotated solutions would serve as training supervision for teaching models to generate reasoning traces. The careful effort invested in writing high-quality explanations shows an insight that was ahead of its time in 2021 and became central to the field: the quality of training supervision for intermediate reasoning steps matters as much as the availability of final-answer supervision.
Third, the 7,500 training and 1,000 test split was calibrated to give a real signal with a reasonable evaluation budget. The test set contains sufficient problems for statistically real comparisons across methods while remaining tractable to evaluate thoroughly. The training set is large enough for fine-tuning experiments while remaining human-curated at a quality level that makes it a reliable source of reasoning traces.
GSM8K consists of 8,500 high-quality grade school math word problems, split into 7,500 training examples and 1,000 test examples. Each problem requires between two and eight steps to solve, involving basic arithmetic operations (addition, subtraction, multiplication, and division) with natural number solutions. The problems are linguistically diverse, presenting scenarios ranging from retail transactions and travel planning to work rates and age relationships.
The dataset designers deliberately constrained the mathematical complexity to elementary operations while maximizing the reasoning depth required to reach solutions. This design choice isolates reasoning capability from advanced mathematical knowledge. This keeps failures indicate limitations in logical processing rather than gaps in mathematical education. By focusing on natural numbers and basic operations, GSM8K tests whether models can combine simple tools in complex ways, much like observing whether a carpenter can build detailed furniture using only basic hand tools.
The dataset captures several categories of mathematical reasoning that reflect the cognitive demands of early mathematics education. These categories map to distinct mental models that humans develop when learning to translate real-world situations into mathematical formalism.
Multi-step arithmetic problems require sequential operations where the output of one calculation is input to the next. Consider: "John buys 3 packs of gum for $2 each and gives the cashier a $20 bill. How much change does he receive?" This requires calculating the total cost (3 \times \2 = $6 $20 - $6 = $14$). The cognitive load here involves maintaining intermediate results across steps. This keeps the calculation of total expenditure completes before attempting to compute the difference from the initial amount. When models collapse these steps into a single inference step, they lose the verification opportunity that explicit intermediate computation gives.
Rate and proportion problems involve speeds, work rates, or ratios. Consider: "If 5 workers can build a wall in 10 days, how long would 10 workers take?" The solution requires recognizing the inverse relationship between workers and time, understanding that doubling the workforce halves the duration. This tests whether models grasp proportional reasoning or merely memorize formulas. The linguistic packaging of rate problems varies enormously, with speed problems, efficiency problems, and concentration problems all involving the same underlying proportional structure expressed in very different surface forms.
Part-whole relationship problems require decomposition of quantities into components or aggregation of parts into totals. These test whether models can track how subsets relate to larger groups without double-counting or omitting elements. Calculating total expenses across multiple categories, or determining remaining inventory after several allocations, requires maintaining a mental inventory of which quantities have been accounted for. These problems are particularly prone to one specific error: reusing a quantity that was already consumed or redistributed in an earlier step.
Temporal sequencing problems involve time calculations across different periods, requiring models to maintain chronological order and properly aggregate durations. These problems test the ability to handle operations where order matters, such as calculating end times given start times and durations, or determining meeting times given different travel schedules. The non-commutativity of time arithmetic, combined with unit conversions (minutes to hours, days to weeks), creates multiple opportunities for reasoning failure.
Out[3]:
Visualization
Each GSM8K example includes both the problem text and a detailed natural language solution. The solutions are structured to show step-by-step reasoning, with the final answer explicitly indicated after a #### delimiter. This format proves important for both human readability and automated evaluation:
Problem: Janet's ducks lay 16 eggs per day. She eats three for breakfast every morning
and bakes muffins for her friends every day with four. She sells the remainder at the
farmers' market daily for $2 per fresh duck egg. How much in dollars does she make
every day at the farmers' market?
Solution: Janet sells 16 - 3 - 4 = 9 duck eggs a day.
She makes 9 * $2 = $18 every day at the farmers' market.
#### 18
The #### delimiter precedes the final numeric answer, letting automated extraction while the preceding text gives the reasoning chain. This structure serves dual purposes: it allows automated evaluation systems to parse answers unambiguously while giving rich supervision signals for training models to generate coherent reasoning traces. The explicit separation of reasoning from final answer also facilitates error analysis, letting researchers to determine whether models fail due to comprehension errors, arithmetic mistakes, or answer formatting issues.
The annotations were written by human contractors trained specifically for this task. The quality control process involved multiple review rounds to ensure that each solution was numerically correct and pedagogically clear, meaning each intermediate step was explicitly stated with its arithmetic shown. This consistency in annotation style proved important for training: models learning from well-structured, consistently formatted reasoning traces develop stronger capabilities for generating their own structured reasoning.
The 2-to-8 step range in GSM8K creates a real difficulty spectrum within the bounds of elementary mathematics. Two-step problems resemble direct arithmetic exercises where the challenge is primarily parsing the linguistic description. Eight-step problems require maintaining and correctly updating several intermediate quantities while working through multiple layers of problem structure.
This distribution reveals something important about how reasoning errors compound. If a model solves each individual step with 90% accuracy, an independent error model predicts the probability of solving an -step problem correctly as . For a 2-step problem, this gives 81% accuracy. For an 8-step problem, it gives only 43% accuracy. The actual decay is even steeper in practice because errors in early steps corrupt the input to later steps, causing downstream failures that cascade through the reasoning chain. This compounding nature of reasoning errors makes the 8-step problems disproportionately challenging relative to their individual step complexity.
The breakthrough insight that transformed performance on GSM8K was the application of chain-of-thought (CoT) prompting. As we explored in prior chapters covering in-context learning emergence, reasoning capabilities in large language models often require explicit elicitation through prompting strategies that encourage step-by-step decomposition. Without such elicitation, even capable models may default to pattern matching or shortcut heuristics that fail on novel problem instances.
The mechanism behind chain-of-thought prompting parallels human cognitive strategies for complex problem solving. Just as students are taught to show their work to catch errors and maintain logical flow, language models benefit from externalizing intermediate computational steps. This externalization serves multiple functions: it breaks complex problems into manageable subproblems, it creates verification points where the model can check its own reasoning, and it increases the effective context available for solving each subcomponent by making intermediate results explicit rather than relying on implicit internal representations.
Standard few-shot prompting gives examples with direct question-answer pairs, presenting a mapping from problem statements to final solutions without intermediate reasoning:
Q: Roger has 5 tennis balls. He buys 2 more cans of tennis balls. Each can has 3 tennis balls. How many tennis balls does he have now?
A: 11
When models answer this way, they must perform all reasoning internally without externalizing intermediate steps. For complex multi-step problems, this often leads to errors because the model cannot show its work and verify each sub-calculation. The internal computation must simultaneously track the initial quantity, the conversion from cans to individual balls, and the final aggregation, creating ample opportunity for information loss or arithmetic drift. The model's attention mechanism must hold multiple numerical quantities in implicit working memory across many layers, a fragile arrangement that becomes increasingly unreliable as problem complexity grows.
Chain-of-thought prompting instead gives reasoning traces that make the computational path explicit:
Q: Roger has 5 tennis balls. He buys 2 more cans of tennis balls. Each can has 3 tennis balls. How many tennis balls does he have now?
A: Roger started with 5 balls. 2 cans of 3 tennis balls each is 6 tennis balls. 5 + 6 = 11. The answer is 11.
This approach yields large improvements across model scales. Large models (100B+ parameters) see accuracy increases from roughly 20% to over 60% when provided with chain-of-thought exemplars, while smaller models gain less benefit, suggesting that the capacity to generate useful reasoning chains emerges with scale. This scaling pattern indicates that chain-of-thought reasoning is a capability that develops as models acquire sufficient capacity to maintain and manipulate explicit intermediate states, rather than merely a prompting trick. Smaller models may lack the representational capacity to generate coherent reasoning chains while simultaneously solving the underlying mathematical operations.
Out[4]:
Visualization
A further refinement to chain-of-thought evaluation involves sampling multiple reasoning paths rather than relying on a single greedy decode. Self-consistency uses the observation that while individual reasoning chains may contain errors, the correct answer often emerges as the consensus across multiple independent attempts. This approach mirrors the human strategy of solving a problem multiple times to check for consistency.
The method operates through three specific stages:
- Sampling different chain-of-thought reasoning paths from the model using non-zero temperature, encouraging diversity in solution approaches
- Extracting the final answer from each path using the standard parsing methodology
- Selecting the most frequent answer (majority voting) as the final prediction
Formally, let be the answers extracted from independently sampled reasoning chains. The self-consistency prediction is:
where is the indicator function that equals 1 when the -th sample matches candidate answer .
The independence assumption underlying this approach is that different sampling paths will produce uncorrelated errors. While all paths might occasionally err, they are unlikely to err in exactly the same way simultaneously. If the correct answer is 42 and an arithmetic mistake in one chain produces 40, a different error in another chain might produce 44. These wrong answers split the vote, while the correct answer 42 concentrates votes from all chains that executed without error. Empirical results show that self-consistency can boost GSM8K accuracy by an additional 10-20% beyond standard chain-of-thought prompting, though at increased computational cost proportional to .
Out[5]:
Visualization
While few-shot examples help, researchers discovered that simply appending "Let's think step by step" to prompts lets zero-shot chain-of-thought reasoning. This simple phrase triggers models to generate intermediate reasoning steps even without exemplars, closing much of the gap between zero-shot and few-shot performance. The effectiveness of this minimal prompt suggests that models have learned the pattern of step-by-step reasoning from their training data and require only a lightweight retrieval cue to activate this behavior.
The effectiveness of this phrase reveals something important about the training of modern language models. During pre-training and instruction tuning, models encounter large quantities of explanatory text, step-by-step tutorials, and worked mathematical examples. The phrase "Let's think step by step" is a retrieval cue that activates this learned pattern of structured reasoning. It effectively puts the model into an explanation mode where it verbalizes its reasoning process rather than jumping directly to conclusions. This zero-shot capability is particularly useful in production environments where crafting few-shot examples for every problem type is impractical.
A significant extension beyond natural language chain-of-thought is the Program of Thought (PoT) approach, introduced by Chen et al. (2022). Instead of asking models to perform arithmetic in natural language, PoT prompts models to write Python code that computes the answer, then executes the code to obtain the result.
A PoT response to the Janet duck egg problem would look like:
In[6]:
Code
Out[6]:
Console
This approach cleanly separates reasoning (which operations to perform and in what order) from arithmetic execution (obtaining the correct numerical result). The language model handles the reasoning component, which it does well, while a Python interpreter handles the arithmetic, which executes without error. This decomposition consistently outperforms pure chain-of-thought on problems where arithmetic mistakes dominate, particularly problems involving large numbers, percentages, or multi-digit multiplication.
PoT also improves interpretability: the generated code is unambiguous about what computation it performs, unlike natural language where phrases like "multiply that by 3" can be ambiguous about which intermediate result is being multiplied. The code execution trace gives a definitive record of the computational steps, simplifying error diagnosis considerably.
Evaluating solutions to GSM8K problems requires precise answer extraction and comparison. Unlike open-ended generation tasks where BLEU or ROUGE scores might apply, mathematical problems demand exact correctness. There is no partial credit for being close to the right answer; the binary nature of mathematical truth requires binary evaluation criteria.
The evaluation protocol must handle the tension between the richness of natural language generation and the precision required for mathematical verification. Models may produce verbose explanations, include units, or format numbers differently, yet the underlying mathematical claim must be extracted and verified against the ground truth with perfect accuracy.
The primary metric for GSM8K is exact match on the final numeric answer. An answer is considered correct only if it matches the ground truth exactly, with no tolerance for rounding errors or alternative representations. If the correct answer is 18, then "18 dollars," "18.0," or "eighteen" would typically be marked incorrect unless the evaluation script specifically normalizes these variations.
Let denote the number of test problems, let be the ground truth answer for problem , and let be the model's predicted answer after extraction and normalization. The GSM8K accuracy metric is:
where equals 1 when the predicted answer exactly matches the ground truth and 0 otherwise.
This strict criterion shows the binary nature of mathematical truth. A reasoning chain that arrives at "17" instead of "18" for the duck egg problem contains an error somewhere, whether in arithmetic or problem understanding, and fails to solve the problem correctly. While this strictness may seem harsh compared to human grading where partial credit is common, it gives an unambiguous signal for model capability assessment and avoids the subjective judgment calls required for partial credit assignment.
Robust evaluation requires parsing model outputs to extract numeric answers. Models may generate verbose responses including explanations, units, and commentary. The extraction system must handle this complexity to isolate the mathematical claim from its linguistic packaging.
Standard extraction strategies include:
- Regular expression matching for numbers following the
####delimiter (when models are prompted to use this format) - Extracting the final number appearing in the text, based on the heuristic that models typically state their final answer last
- Pattern matching for phrases like "The answer is [number]" or "Therefore, the result is [number]"
The extraction process materially impacts reported accuracy. If a model correctly calculates an answer but expresses it as "18 dollars" while the evaluator expects "18," the model receives no credit despite possessing the correct understanding. This sensitivity necessitates careful normalization routines that strip units, handle decimal representations, and account for common formatting variations while remaining reliable to adversarial cases where numbers in the explanation might be mistaken for the final answer.
Normalization typically applies a standardized pipeline: remove currency symbols, strip units, replace commas in large numbers (e.g., "1,024" becomes "1024"), and convert decimal representations to standard form. The challenge is that overly aggressive normalization can introduce false positives. If a problem asks for the answer in cents and the model answers in dollars, stripping units might make an incorrect answer appear correct.
Beyond final answer correctness, researchers sometimes analyze per-step accuracy by comparing generated reasoning chains against reference solutions. This finer-grained metric identifies where reasoning breaks down and gives diagnostic insight into model limitations.
Four distinct error types characterize reasoning failures on GSM8K:
Conceptual errors stand for misunderstandings of the problem structure itself: adding instead of subtracting, using a multiplication rate where a division is required, or misidentifying which quantities are needed to the solution. These errors occur regardless of arithmetic accuracy; the model understands all the numbers but connects them with the wrong operation.
Arithmetic errors occur when the model correctly identifies the required operations but computes them incorrectly. The model understands that it needs to multiply 9 eggs by $2 per egg, but arrives at $17 instead of $18 due to a calculation mistake. These errors are purely computational rather than conceptual.
Truncation errors involve stopping before reaching the final answer, perhaps after calculating an intermediate value. The model correctly computes that Janet has 9 eggs remaining, but fails to multiply by the price to obtain the final dollar amount.
Hallucination errors involve introducing quantities not present in the problem or inventing calculations without basis in the problem text. A model might fabricate a "processing fee" or introduce a fictional discount that changes the problem structure entirely.
Analyzing error patterns reveals that larger models primarily reduce arithmetic errors while maintaining similar rates of conceptual misunderstanding, suggesting that scale improves execution more than comprehension. This decomposition is important for guiding model improvement: if errors are primarily arithmetic, integrating calculators or improving numerical precision may help; if errors are conceptual, better training on problem understanding or logical reasoning may be required.
Out[7]:
Visualization
Out[8]:
Visualization
An important conceptual distinction that GSM8K helped crystallize is the difference between process supervision and outcome supervision in training reasoning-capable models. This distinction has practical consequences for both training efficiency and the reliability of the resulting system.
In outcome supervision, the training signal rewards or penalizes the model based solely on whether it produced the correct final answer. The intermediate reasoning steps receive no direct feedback. This is the simplest setup to implement: collect problems with known correct answers, run the model, check if it got the right answer, and update accordingly. The model learns to produce correct outputs but has no explicit incentive to generate correct intermediate steps. It might arrive at the right answer through invalid reasoning, or fail at the last step despite correct intermediate work.
Outcome supervision is well aligned with the standard GSM8K evaluation metric, which is purely based on final answer correctness. However, it creates models whose reasoning chains may be unreliable as explanations. A model trained entirely on outcome supervision might learn to generate plausible-sounding but mathematically invalid reasoning chains that happen to terminate at the correct answer.
In process supervision, the training signal evaluates each individual step in the reasoning chain. Steps that advance toward the correct solution receive positive reward; steps that introduce errors receive negative reward. This requires either human annotation of intermediate steps or automated verification of mathematical claims at each step.
OpenAI's research on process-supervised reward models (PRMs) demonstrated that models trained with step-level supervision outperform those trained with only outcome supervision on GSM8K, particularly on harder problems. The PRM800K dataset, released alongside this research, contains 800,000 step-level annotations on GSM8K problems. Each annotation labels individual reasoning steps as correct, incorrect, or neutral. This gives a fine-grained supervision signal.
The intuition behind process supervision's advantage is that it explicitly trains models to maintain correct intermediate state. Rather than letting the model to discover any path to the correct answer, including shortcuts that do not generalize, process supervision enforces that each step must be logically valid. This produces models whose reasoning chains are more reliable as formal arguments, not just generators of correct final answers. The downstream benefit is improved calibration: models trained with process supervision are less likely to generate confidently wrong reasoning chains and are more likely to produce interpretable traces that humans can verify.
The tradeoff is annotation cost. Labeling 800,000 reasoning steps requires substantial human effort, while collecting outcome labels requires only verifying final answers. Researchers have explored automated approaches to process supervision, such as using symbolic verifiers or executing code generated at each step, to scale this supervision signal without proportional annotation cost.
To build concrete intuition for how chain-of-thought evaluation works in practice, let us trace through a complete GSM8K problem step by step.
Problem: "A baker has 120 cookies. She packs them into boxes of 8 and sells each box for $3.50. However, 5 cookies are broken and cannot be sold. How much money does the baker earn?"
Reading the problem, we identify the following needed quantities:
- Total cookies: 120
- Broken cookies: 5
- Cookies per box: 8
- Price per box: $3.50
We also identify the implicit structure: broken cookies must be removed before packing, and only complete boxes can be sold. The question asks for total revenue from box sales.
A well-formed chain-of-thought solution proceeds as follows:
The number of sellable cookies is .
The number of complete boxes is boxes (since 115 divided by 8 is 14 with remainder 3, and partial boxes cannot be sold).
The total revenue is 14 \times \3.50 = $49.00$.
This problem contains several traps that lead to common errors:
The floor division step is the most common failure point. A model that divides 115 by 8 and gets 14.375 might round to 14 or 15 depending on how it handles the non-integer result. Rounding up to 15 is a conceptual error: you cannot sell 15 boxes with only 115 cookies when each box requires 8. This specific trap tests whether the model understands the discrete nature of the packing constraint.
A secondary failure occurs if the model forgets to subtract the broken cookies before dividing. Dividing 120 by 8 gives 15 boxes, yielding a revenue of $52.50. This error shows a truncation of the problem structure, skipping the constraint that broken cookies cannot be sold.
A third failure mode involves arithmetic errors in the final multiplication. Computing requires careful decimal arithmetic, and a model that treats this as must correctly add $42 and $7 to obtain $49. Each sub-computation is a potential error site.
The ground truth answer is 49 (representing $49.00). An evaluation script extracts the final number from the model's response. If the model correctly solves the problem and formats its answer as "The baker earns $49.00," the normalization pipeline strips the dollar sign and decimal to extract "49." The comparison succeeds, and the problem is marked correct.
If the model instead answers "The baker earns $52.50" because it forgot the broken cookie constraint, the extracted answer is "52.50" or "5250" depending on normalization, and the comparison fails. The error is marked as a conceptual error (incorrect problem structure) rather than an arithmetic error.
Let's implement a complete evaluation pipeline for GSM8K. We'll load the dataset, implement chain-of-thought prompting, and calculate accuracy metrics.
In[9]:
Code
In[10]:
Code
Out[11]:
Console
The dataset contains 7,500 training examples and 1,000 test examples, exactly matching the original paper's split. The training set gives a rich pool of human-annotated reasoning chains for constructing few-shot prompts and for fine-tuning experiments. The test set is the standardized evaluation set. This allows real comparisons across different approaches and model configurations.
Let's examine a specific example to understand the format in detail.
In[12]:
Code
Out[13]:
Console
The example shows the detailed reasoning format with the final answer clearly delimited after ####. Each example contains the natural language question and a step-by-step answer where every arithmetic operation is spelled out explicitly before the final result is stated. This level of annotation detail makes GSM8K useful as an evaluation dataset and as a training resource for teaching models to reason explicitly.
We need reliable functions to extract final answers from model outputs and ground truth labels. The extraction logic must handle several variations: the #### delimiter format used in the training data, plain numeric answers at the end of responses, and formatted numbers with commas or decimal points.
In[14]:
Code
Out[15]:
Console
The extraction correctly isolates the numeric answer after the #### delimiter. The regex pattern r"####\s*(-?\d+)" matches the delimiter followed by optional whitespace and a potentially negative integer. The fallback to the last number in the text handles model outputs that do not follow the #### convention, which occurs when models are not explicitly instructed to use this delimiter format.
We'll construct few-shot prompts with chain-of-thought exemplars drawn from the training set. The prompt structure places several solved examples before the target question, giving the model a clear demonstration of the expected reasoning format.
In[16]:
Code
Out[17]:
Console
The prompt now contains three worked examples showing the step-by-step format, followed by the target question. This structure guides the model to generate similar reasoning traces rather than jumping directly to the final answer. Each example in the few-shot set is a stylistic demonstration: the model observes how intermediate arithmetic is spelled out, how quantities are tracked across steps, and how the final answer is delimited.
The selection of few-shot examples matters more than it might initially appear. Examples that are semantically similar to the test question can serve as stronger retrieval cues, helping the model recognize needed problem structures. However, random sampling from the training set typically works well because GSM8K problems share common linguistic patterns regardless of their specific content.
Since we don't have a live large language model API in this environment, we'll simulate the evaluation logic and show the accuracy calculation with a mock function representing model outputs.
In[18]:
Code
Out[19]:
Console
The single-sample evaluation shows our exact-match validation logic in action. By extracting the final numeric answer from both the model's simulated response and the ground truth, then comparing them after normalization, we verify that the evaluation pipeline correctly identifies correct and incorrect predictions. The 70% accuracy of our simulated model shows realistic performance of chain-of-thought prompting on moderately sized language models.
In[20]:
Code
Out[21]:
Console
The evaluation reaches approximately 70% accuracy on this sample, which aligns with expected performance for chain-of-thought prompting on moderately sized language models. This accuracy level indicates that the simulated model correctly solves most arithmetic reasoning problems but still struggles with approximately 30% of cases. In practice, those failures split roughly between arithmetic errors (off-by-one or off-by-small mistakes in multi-digit arithmetic) and problem structure errors (applying the wrong operation despite correct parsing of the problem text).
Out[22]:
Visualization
Out[23]:
Visualization
The visualization shows the exact match evaluation criterion in its starkest form. Even when models generate reasonable reasoning chains, only predictions matching the ground truth exactly count as correct. A predicted answer of 17 when the correct answer is 18 contributes nothing to the accuracy score, which is why error analysis focusing on the magnitude of arithmetic mistakes is important for understanding model limitations beyond the headline accuracy number.
Let's implement self-consistency decoding, where we sample multiple reasoning paths and take the majority vote.
In[24]:
Code
Out[25]:
Console
The output shows self-consistency in action. The agreement count tells us how many of the five sampled reasoning paths converged on the returned answer. High agreement (4 or 5 out of 5) indicates strong confidence in the result, while low agreement (2 or 3 out of 5) signals uncertainty. Some research teams use this agreement score as a proxy for model confidence, flagging low-agreement predictions for human review in high-stakes applications. Self-consistency typically improves accuracy by 5-15% on GSM8K by filtering out sporadic arithmetic errors that occur in individual reasoning chains.
The key parameters for GSM8K evaluation are:
- num_shots: Number of few-shot examples to include in the prompt. More examples give stronger guidance but increase prompt length and computational cost. The typical sweet spot is 4-8 examples, balancing demonstration quality against context window utilization. Above 8 examples, gains become marginal on most problems.
- sample_size: Number of test examples to evaluate. Larger samples yield more reliable accuracy estimates but require more computation time. Evaluating the full 1,000-problem test set is standard for publication-quality comparisons; smaller samples (100-200) suffice for rapid iteration during development.
- num_samples (for self-consistency): Number of reasoning paths to sample and aggregate. Higher values improve accuracy through better consensus but increase computational cost linearly. Diminishing returns typically appear after 5-10 samples, with accuracy improvements falling below 0.5% per additional sample beyond that point.
- temperature: The sampling temperature used when generating diverse reasoning chains for self-consistency. Too low (approaching greedy decoding) produces insufficiently diverse paths that all fail at the same steps; too high produces incoherent chains. Values between 0.5 and 0.8 typically work well for self-consistency on GSM8K.
- random_state: Seed value for reproducibility. Controlling randomness ensures that performance comparisons across different model configurations reflect true capability differences rather than prompt selection variance.
While GSM8K has proven invaluable for benchmarking mathematical reasoning, the dataset and evaluation methodology present several limitations that researchers must consider when interpreting results. Understanding these limitations prevents overestimation of model capabilities and guides the development of more reliable evaluation protocols.
Large language models trained on internet-scale text corpora may encounter GSM8K examples during training. GSM8K was released in 2021, and subsequent large-scale training datasets almost certainly include the benchmark problems or highly similar variations. This contamination means that reported accuracy scores may partially reflect memorization rather than true reasoning capability.
The contamination problem is not unique to GSM8K, but it is particularly acute for this benchmark because the problems are relatively short and linguistically distinctive. A model that has memorized all 7,500 training examples could potentially solve some test problems by recognizing similar structures and retrieving associated solutions rather than reasoning from scratch.
Detecting contamination requires careful analysis of model outputs. If a model generates solutions that exactly match the training set's wording word-for-word, or performs materially better on GSM8K than on freshly created problems of equivalent difficulty, memorization is likely occurring. Recent evaluations increasingly use modified problem phrasings or entirely new test sets to mitigate this issue. Techniques such as paraphrasing problems, changing numerical values while preserving structure, or creating entirely novel problem sets serve as robustness checks against contamination. The GSM8K-Plus dataset, which replaces numbers in test problems with different values while preserving the reasoning structure, gives one such robustness check.
GSM8K problems follow specific linguistic patterns common to grade school math curricula. Models might exploit surface heuristics rather than deep understanding. For instance, specific keywords ("total," "remaining," "combined") often correlate with particular operations. A model might learn that "how many remain" typically signals subtraction without comprehending the scenario.
This limitation parallels challenges observed in studies of emergence versus metrics measurement artifacts, where apparent capability improvements sometimes reflect dataset artifacts rather than real understanding. Adversarial variations of GSM8K problems, where surface cues contradict the required operations, reveal that models often rely heavily on pattern matching rather than reliable reasoning. For example, modifying a problem to state "how many remain" when the operation required is addition can fool models that rely on keyword matching rather than meaning-based matching. These adversarial probes reveal a gap between benchmark performance and real generalization.
GSM8K conflates two distinct capabilities: mathematical reasoning (understanding what operations to perform and in what order) and arithmetic execution (computing the correct numerical result). A model might correctly identify that a problem requires calculating but fail due to multiplication errors.
Recent work separates these components by letting models to use calculators or code interpreters for arithmetic while evaluating only their reasoning chains. This decomposition reveals that current models often possess stronger reasoning capabilities than raw GSM8K scores suggest, with arithmetic errors masking correct problem understanding. The distinction matters for practical applications: a model that understands financial planning but miscalculates interest rates might still give value with a calculator interface, while a model that calculates accurately but misunderstands the planning scenario is fundamentally broken.
The tool-augmented approach, where models invoke a Python interpreter for numerical computations within a chain-of-thought framework, consistently outperforms purely linguistic chain-of-thought by eliminating arithmetic as a failure mode. This result suggests that improving GSM8K performance through scale may have diminishing returns compared to architectural interventions that connect language model reasoning with precise computational tools.
The grade school scope of GSM8K evaluates only elementary arithmetic and basic problem-solving. Success on this benchmark does not imply capability in algebra, geometry, calculus, or advanced mathematical reasoning. Models achieving 90%+ accuracy on GSM8K may still fail completely on high school mathematics competitions or undergraduate-level proofs.
This limitation motivates the development of more challenging benchmarks. The MATH dataset (Hendrycks et al., 2021) includes 12,500 competition-level problems across seven mathematical topics: algebra, counting and probability, geometry, intermediate algebra, number theory, prealgebra, and precalculus. State-of-the-art models that reach near-perfect scores on GSM8K typically reach only 50-70% on MATH, illustrating the enormous difficulty gap between grade school arithmetic and competition mathematics.
The progression from GSM8K to these harder datasets mirrors the pattern of benchmark saturation we see across NLP evaluation. As models master grade school mathematics, the field must continually increase the difficulty of evaluation tasks to measure the frontier of capability. The benchmark development cycle, where a new dataset challenges state-of-the-art models, subsequent research closes the gap, and the community moves to harder challenges, is a healthy mechanism for driving progress but requires sustained effort in benchmark construction and curation.
GSM8K evaluates only the final numeric answer, which gives limited insight into the quality of the reasoning chain leading to that answer. A model might reach the correct answer through invalid reasoning by compensating one error with another, or through correct reasoning that would not generalize to slightly different problems. The exact match metric cannot distinguish reliable understanding from lucky coincidence.
This limitation is why the development of process reward models and step-level evaluation is an important research direction. Evaluating the quality of individual reasoning steps, rather than just the final answer, gives a more faithful picture of model capabilities and is better aligned with the educational goal of teaching models to reason correctly rather than just to answer correctly.
Despite its limitations, GSM8K has strongly influenced language model research and development. The benchmark established multi-step reasoning as a necessary evaluation axis alongside traditional NLP tasks such as sentiment analysis, translation, and question answering.
The release of GSM8K with detailed solutions enabled researchers to fine-tune models specifically for mathematical reasoning. By training on the step-by-step solutions rather than just final answers, models learn to generate coherent reasoning chains. This approach, process supervision, improves both accuracy and interpretability by explicitly rewarding intermediate correctness rather than only final answer correctness.
The success of this methodology has led to the creation of larger synthetic reasoning datasets, where capable models generate step-by-step solutions to millions of newly created problems, bootstrapping training data for smaller specialized models. This data generation pipeline creates a positive feedback loop: capable models generate training data for even more capable models, specifically targeting reasoning capabilities that generalize beyond mathematics. The quality of synthetically generated reasoning traces varies substantially with the capability of the generating model, creating a dependency chain where access to stronger generators accelerates development of stronger students.
Open-source projects like Orca and WizardLM used this synthetic data generation approach to train small models (7B-13B parameters) that punch well above their weight class on reasoning benchmarks by training on reasoning traces generated by much larger models. The success of these projects shows that the knowledge encoded in large model outputs can be distilled into much smaller and more deployable models when reasoning traces give rich intermediate supervision.
GSM8K results demonstrated that chain-of-thought reasoning behaves like an emergent capability of sufficiently large models, rather than merely a prompting trick. This insight shifted research focus toward scaling laws for reasoning, investigating how model size, training compute, and data composition affect the ability to generate useful intermediate steps.
The benchmark also validated the importance of instruction tuning for reasoning. Models specifically trained to follow instructions and generate explanatory text show materially better chain-of-thought performance than base models of equivalent size, suggesting that training objectives and data curation matter as much as scale for reasoning capabilities. This finding influenced the development of specialized instruction tuning datasets that emphasize reasoning and explanation, such as the OpenHermes and MetaMathQA datasets that supplement general instruction following with problem-solving demonstrations.
Modern frontier models from OpenAI, Anthropic, Google, and Meta reach accuracy above 90% on GSM8K, with some reported results approaching 97-99%. At this level, the benchmark gives little differentiation among top systems. A difference of 1-2% in accuracy on a 1,000-problem test set corresponds to only 10-20 additional problems solved correctly, which may not reflect real differences in practical reasoning capability.
This saturation problem drove the development of more challenging mathematical benchmarks. MATH, AIME (American Invitational Mathematics Examination) problems, and the FrontierMath dataset (containing research-level problems that even expert mathematicians find challenging) stand for successive escalations of difficulty designed to remain informative as models continue improving. GSM8K remains a useful lower bar: failure on GSM8K definitively indicates weak mathematical reasoning, but success tells us little about performance on harder problems.
Improvements on GSM8K correlate with improved performance on tasks requiring structured thinking, including code generation, logical analysis, and complex planning. The skills required to decompose a word problem into steps and execute them sequentially transfer to other domains requiring systematic reasoning.
This generalization validates GSM8K as a proxy for broader cognitive capabilities, even if the specific mathematical content is elementary. The ability to break a complex goal into subgoals, execute them sequentially, and verify intermediate results constitutes a basic cognitive skill applicable across software engineering, scientific analysis, and strategic planning. We'll explore this connection further in upcoming chapters covering code generation benchmarks, where similar step-by-step reasoning proves needed for writing correct programs that decompose complex tasks into clearly reasoned implementation steps.
GSM8K established itself as a foundational benchmark for evaluating mathematical reasoning in language models by requiring multi-step problem-solving rather than simple pattern matching. The dataset's 8,500 grade school word problems test the ability to parse natural language scenarios, identify needed quantities, and execute sequential calculations to arrive at numeric answers.
Key insights from this chapter include:
- Chain-of-thought prompting substantially improves GSM8K performance by eliciting step-by-step reasoning, with larger models showing greater benefits from this approach. This technique turns latent reasoning capabilities into observable, verifiable computation traces.
- Self-consistency decoding further boosts accuracy by aggregating multiple reasoning attempts through majority voting, filtering out sporadic arithmetic errors that occur in individual reasoning chains.
- Program of Thought approaches, which delegate arithmetic to a code interpreter, separate reasoning capability from arithmetic execution and consistently outperform purely linguistic chain-of-thought by eliminating a major error source.
- Process supervision, which gives step-level training signals rather than only final-answer signals, produces more reliable and interpretable reasoning chains than outcome supervision alone.
- Exact match evaluation gives a strict binary correctness criterion that aligns well with the mathematical truth requirement, though answer extraction must handle formatting variations carefully.
- Limitations including benchmark contamination, surface pattern exploitation, arithmetic-reasoning conflation, and limited mathematical scope require careful interpretation of results and motivate evaluation on harder benchmarks.
GSM8K showed that language models can perform structured, multi-step reasoning when properly prompted and trained, and made reasoning ability a standard evaluation dimension alongside fluency and knowledge retrieval. As modern frontier models approach saturation on this benchmark, the field now uses harder mathematical datasets while keeps GSM8K as a lower bound for basic reasoning capability. The benchmark remains useful because it measures current capabilities and gives the research community a clean, well-annotated environment for developing and validating the prompting strategies, training methodologies, and evaluation protocols that now underpin the entire field of language model reasoning research.
Ready to test your understanding? Take this quick quiz to reinforce what you've learned about GSM8K and mathematical reasoning evaluation.
Comments
Nothing yet. Say the first thing.
Sign in to join the conversation.