Interpreting the Latent Structure of Operator Precedence in Language Models
Dharunish Yugeswardeenoo, Harshil Nukala, Ved Shah, Cole Blondin, Sean O Brien, Vasu Sharma, Kevin Zhu
TL;DR
This work probes how operator precedence and intermediate arithmetic steps are represented inside a contemporary LLM (LLaMA three point two to three billion parameters) using a comprehensive interpretability toolkit. It combines logit lens, linear probes, attention/MLP ablations, partial embedding swaps, and UMAP to trace hidden computations and the encoding of precedence across a synthetic three-operand, two-operator dataset. The results show that intermediate computations reside in the residual stream, especially after MLP blocks, and that operator precedence is linearly encoded in operator embeddings after attention, with targeted embedding perturbations able to shift arithmetic outcomes. These findings advance mechanistic interpretability of arithmetic reasoning in LLMs and point to precise intervention strategies for diagnosing and improving reliability in reasoning tasks.
Abstract
Large Language Models (LLMs) have demonstrated impressive reasoning capabilities but continue to struggle with arithmetic tasks. Prior works largely focus on outputs or prompting strategies, leaving the open question of the internal structure through which models do arithmetic computation. In this work, we investigate whether LLMs encode operator precedence in their internal representations via the open-source instruction-tuned LLaMA 3.2-3B model. We constructed a dataset of arithmetic expressions with three operands and two operators, varying the order and placement of parentheses. Using this dataset, we trace whether intermediate results appear in the residual stream of the instruction-tuned LLaMA 3.2-3B model. We apply interpretability techniques such as logit lens, linear classification probes, and UMAP geometric visualization. Our results show that intermediate computations are present in the residual stream, particularly after MLP blocks. We also find that the model linearly encodes precedence in each operator's embeddings post attention layer. We introduce partial embedding swap, a technique that modifies operator precedence by exchanging high-impact embedding dimensions between operators.
