Abstract
Large Language Models (LLMs) perform well on reasoning benchmarks but often fail when inputs alter slightly, raising concerns about the extent to which their success relies on memorization. This issue is especially acute in Chain-of-Thought (CoT) reasoning, where spurious memorized patterns can trigger intermediate errors that cascade into incorrect final answers. We introduce STIM, a novel framework for Source-aware Token-level Identification of Memorization, which attributes each token in a reasoning chain to one of multiple memorization sources—local, mid-range, or long-range—based on their statistical co-occurrence with the token in the pretraining corpus. Our token-level analysis across tasks and distributional settings reveals that models rely more on memorization in complex or long-tail cases, and that local memorization is often the dominant driver of errors, leading to up to 67% of wrong tokens. We also show that memorization scores from STIM can be effective in predicting the wrong tokens in the wrong reasoning step. STIM offers a powerful tool for diagnosing and improving model reasoning and can generalize to other structured step-wise generation tasks.
Introduction
While Large Language Models (LLMs) demonstrate impressive capabilities on reasoning benchmarks, they remain notoriously brittle. Minor perturbations to a prompt—such as changing numerical bases or using less common entities—can lead to catastrophic failures. This suggests that LLMs often rely on memorized patterns rather than robust logical principles.
In the context of Chain-of-Thought (CoT) reasoning, this reliance is particularly problematic. CoT is a sequential process where each step depends on the previous one. A single "memorized" token that is statistically likely in the training data but logically incorrect for the specific problem can trigger a cascading failure. Previous research has largely focused on sequence-level memorization, which fails to pinpoint why or where a specific reasoning step breaks down.
The STIM Framework
To address this, the researchers propose STIM (Source-aware Token-level Identification of Memorization). STIM decomposes the influence on each generated token into three distinct sources:
- Local Context ($STIM_{loc}$): Influence from immediately preceding tokens (e.g., the tendency for "3 * 3" to be followed by "9" regardless of global context).
- Mid-Range Context ($STIM_{mid}$): Influence from earlier parts of the model’s own generated reasoning chain.
- Long-Range Context ($STIM_{long}$): Influence from salient tokens in the original input prompt.
STIM utilizes Infinigram, an engine for rapid n-gram frequency lookups across massive pretraining corpora (e.g., the Dolma dataset). By comparing the model's output probabilities with statistical frequencies in its training data, STIM quantifies whether a token was likely retrieved from memory or derived through reasoning.
Experimental Setup
The study evaluated models on four reasoning tasks: Applied Math (GSM8K-based), Formula Calculation, Counting, and Capitalization. To test the limits of memorization, the authors introduced Long-tail Transformations. For instance, standard math problems were converted into base-2 or featured large prime-number multiples, ensuring the model could not rely on common patterns seen during pretraining.
Key Insights
The Memorization Reversal
The analysis reveals a "Memorization Reversal" effect. In "base" scenarios (common problems), memorization often aids the model in reaching the correct answer. However, in "long-tail" scenarios, this same reliance becomes a liability. The model attempts to force-fit memorized heuristics onto unfamiliar problems where they no longer apply.
Local Context as the Error Engine
Local memorization—the tendency to follow a short sequence of words with their most frequent training-data successor—is the primary driver of reasoning failures. The study found that local memorization accounts for up to 67% of erroneous tokens. As tasks increase in complexity, models exhibit a significantly higher reliance on these brittle local patterns.
Results
STIM scores are highly predictive of model failure. Using Precision@k, the authors showed that tokens with the highest STIM scores are frequently the exact points where a reasoning step deviates from logic. For example, when moving from base to long-tail distributions in Applied Math, the accuracy of the OLMo-2 model plummeted from 82.0% to 25.6%. STIM analysis confirmed that this drop was directly correlated with the model's inability to abandon local memorized heuristics in favor of global reasoning.
Conclusion and Future Work
STIM provides a diagnostic lens into the "black box" of LLM reasoning. While CoT improves performance, it also increases the "surface area" for memorization to interfere. Future work could involve using STIM scores during training or fine-tuning to penalize over-reliance on local memorization, potentially encouraging the development of more robust, generalizable reasoning pathways.
Summary updated