Tracing and Manipulating intermediate values in Neural Math Problem Solvers

Yuta Matsumoto, Benjamin Heinzerling, Masashi Yoshikawa, Kentaro Inui

Abstract

How language models process complex input that requires multiple steps of inference is not well understood. Previous research has shown that information about intermediate values of these inputs can be extracted from the activations of the models, but it is unclear where that information is encoded and whether that information is indeed used during inference. We introduce a method for analyzing how a Transformer model processes these inputs by focusing on simple arithmetic problems and their intermediate values. To trace where information about intermediate values is encoded, we measure the correlation between intermediate values and the activations of the model using principal component analysis (PCA). Then, we perform a causal intervention by manipulating model weights. This intervention shows that the weights identified via tracing are not merely correlated with intermediate values, but causally related to model predictions. Our findings show that the model has a locality to certain intermediate values, and this is useful for enhancing the interpretability of the models.

Introduction

Large Language Models (LLMs) demonstrate remarkable proficiency in solving complex mathematical problems. However, the internal mechanisms driving these capabilities remain opaque. A central question in interpretability research is whether these models perform genuine multi-step calculations or rely on sophisticated pattern matching. While "probing" techniques can extract intermediate values from hidden states, they often fail to distinguish between mere correlation and functional necessity. This study addresses this gap by identifying where intermediate values are encoded within a Transformer's latent space and demonstrating their causal role in the model's final output.

Methodology: Tracing and Manipulation

The researchers developed a two-step framework to bridge the gap between correlation and causation in model interpretability.

The two-step framework: Tracing identifies correlations via PCA, and Manipulation verifies causation by intervening in the activation space.

1. Tracing (Correlation)

The first phase involves identifying where intermediate values—such as $b$ in the expression $a - (b - c)$—are stored. By applying Principal Component Analysis (PCA) to the activations of each layer, the authors identified specific "directions" (principal components) that exhibit high numerical correlation with sub-expressions.

2. Manipulation (Causation)

To prove these directions are functionally used by the model, a causal intervention is performed. By manually shifting the model's internal activations along a target PCA direction, the researchers can force the model to "perceive" an intermediate value differently. If the final prediction shifts in a mathematically predictable manner corresponding to this "nudge," it confirms a causal link between that latent direction and the output.

Experimental Setup

The framework was tested using a synthetic dataset of 200,000 arithmetic equations involving addition and subtraction of integers (1–1000). Equations reached complexities of up to five steps (e.g., $(154 - 38) - (290 - 67)$). To prevent simple vocabulary memorization, numbers were tokenized into individual digits, forcing the model to learn numerical relationships. The resulting 6-layer Transformer achieved an $R^2$ score of 0.9988, indicating near-perfect accuracy on the test set.

Results and Discussion

Locality and Layer Depth

A key finding is that intermediate values are not distributed randomly but are localized in specific, identifiable directions. This locality is most pronounced in the earlier layers (Layers 1–3). As shown in the correlation heatmaps, specific principal components often dominate the representation of a particular intermediate value.

Correlation heatmaps across layers showing how different intermediate values (a, b, c, etc.) are localized in specific principal components.

The study observed that while Layer 4 showed high correlation with certain values, manipulating it did not predictably alter the final answer. This suggests a "Shadow Effect," where later layers may hold residual, non-causal traces of values while the actual computation occurs earlier.

Linearity and Causal Impact

The success of linear PCA in identifying these values suggests that Transformers represent numerical magnitude in a surprisingly linear internal latent space. In Layer 3, a specific direction ($p^3_{i,2}$) correlated with intermediate value $b$ at 0.973. Manipulation of this direction for an input like $617 - (555 - 602)$ caused the model's prediction to shift from the correct answer (664) to a range of values (200–1000) that precisely tracked the magnitude of the intervention ($R^2 = 0.687$).

Conclusion

This research provides a robust method for "peeking under the hood" of mathematical solvers. By proving that specific latent directions are causally linked to outputs, it moves beyond simple probing toward a deeper understanding of neural computation. Future work will explore whether these findings generalize to more complex operations like multiplication or non-mathematical logical reasoning, and whether similar causal structures exist in larger-scale models.

Summary updated

BibTeX
@misc{matsumoto2023tracing,
  author = {Yuta Matsumoto and Benjamin Heinzerling and Masashi Yoshikawa and Kentaro Inui},
  title = {{Tracing and Manipulating intermediate values in Neural Math Problem Solvers}},
  year = {2023},
  eprint = {2301.06758},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2301.06758},
}
Figure