Abstract
How do Transformer models solve multi-step arithmetic problems? While Large Language Models (LLMs) demonstrate impressive mathematical capabilities, the internal mechanisms driving these outputs remain largely opaque. This study investigates whether Transformers encode and utilize intermediate mathematical values during computation. By applying Principal Component Analysis (PCA) to internal activations, the researchers identify specific "directions" in the activation space that correlate with intermediate variables. Causal interventions—shifting activations along these identified axes—reveal that the model's final predictions change in accordance with mathematical logic, proving that these internal representations are functionally significant for the model's reasoning process.
Introduction
The "black box" nature of neural networks often obscures the reasoning process behind their outputs. In the context of mathematics, it is unclear whether a model simply memorizes input-output mappings or performs a structured sequence of internal calculations. Previous research has utilized "probes" to identify features within hidden layers, but correlation does not imply causation; a feature might be present without being used for the final decision. This paper addresses this gap by tracing intermediate values to specific activation directions and performing causal manipulations to verify their utility.
Methodology: Tracing and Manipulation
The researchers employed a two-stage framework to analyze a 6-layer Transformer trained on synthetic arithmetic problems.
- Tracing (Correlation): The authors collected internal activations across thousands of problem instances. PCA was applied to these activations at each layer to identify primary directions of variation. They then calculated the correlation between these PCA-derived weights and the ground-truth intermediate values (e.g., the value of $b$ in the expression $a - (b - c)$).
- Manipulation (Causation): To establish a causal link, the researchers performed interventions by manually "nudging" activations along the most-correlated PCA directions. If the model's final output shifted in a predictable manner consistent with the mathematical change of that intermediate value, it confirmed that the model relies on these internal "variables."
Experimental Setup
The study utilized a synthetic dataset of 200,000 equations involving addition and subtraction of integers (1–1,000). Problems required up to five steps of inference. To prevent the model from treating numbers as monolithic tokens, digits were tokenized individually (e.g., "123" as 1, ##2, ##3), forcing the network to learn numerical logic and positional value rather than memorizing whole-number patterns.
Key Insights
Locality and Layer-wise Processing
Intermediate values are not distributed randomly across the network. Instead, they are encoded in specific, identifiable directions. The analysis revealed that most of the "heavy lifting" regarding intermediate calculations occurs in the earlier layers. By Layer 3 of the 6-layer model, representations of intermediate variables are highly refined and strongly correlated with ground-truth values.
Correlation vs. Utility
An important finding was that high correlation does not always equate to high utility. Some PCA directions were strongly correlated with a value but had minimal impact on the final output when manipulated. This suggests the presence of redundant information or "read-only" representations that the model maintains but does not strictly require for the final calculation step.
Results
The trained Transformer achieved near-perfect accuracy with an $R^2$ score of 0.9988 on the test set. In the manipulation experiments, the researchers successfully "steered" the model's output. For example, in the equation $a - (b - c)$, sliding the activation along the axis corresponding to variable $b$ allowed them to force the model to output a wide range of values (e.g., from 200 to 1,000) starting from an original prediction of 664. The high fidelity of these manipulations ($R^2 = 0.687$) provides strong evidence for the causal role of these internal directions.
Conclusion and Future Work
This research demonstrates that Transformers solve arithmetic problems by constructing internal, localized representations of intermediate values. While limited to linear PCA directions and simple arithmetic, the methodology provides a blueprint for "debugging" and understanding the reasoning chains in larger, more complex models. Future work may explore non-linear representations and more sophisticated symbolic logic tasks to see if these "mental math" structures scale with model size and task complexity.
Summary updated