Introduction
In-Context Learning (ICL) is a defining capability of modern Large Language Models (LLMs), allowing them to solve tasks by observing a few examples in the prompt. However, the internal mechanisms that enable this—particularly for multi-step reasoning like arithmetic—remain a "black box." This paper investigates the mechanistic circuitry of ICL using three-operand arithmetic problems (e.g., $1+3+4=8$), revealing that models prioritize structural formatting and specific "anchor" tokens over mathematical correctness.
Methodology
The researchers analyzed four open-weight models—Pythia-12B, Llama-3.1-8B, MPT-7B, and OPT-6.7B—using a unified mechanistic interpretability pipeline. This included Activation Patching to identify causal activations, Information-Flow Analysis to map data movement, Automated Circuit Discovery to isolate relevant sub-networks, and the Logit Lens to inspect intermediate layer predictions. The study utilized two custom benchmarks, Arithmetic-20 and Arithmetic-1000, designed to ensure operands are single tokens for simplified analysis.
The Result Token as a Computational Anchor
A primary finding is the critical role of the in-context example (ICE) result token. In a problem like $1+3+4=8$, the "8" serves as a structural anchor. Activation patching reveals that information from this token is processed in the very early layers (1-2) and maintained until the model reaches the final "equals" sign of the target task.
As shown in the patching analysis, the model's performance is highly sensitive to the residual stream at the ICE result token and the final task's equal sign. This suggests the model uses the example result to "lock in" the expected output format before performing the actual calculation.
Mapping Information Flow and Circuits
Information-flow analysis further clarifies how the model routes data. In Llama-3.1-8B, a clear "highway" exists where information from the ICE result token is injected into the final task's logic. The researchers found a 56% overlap between the general task-solving circuit and the circuit dedicated specifically to processing the ICE result token, confirming that the example result is a primary driver of the model's internal logic.
Beyond specific tokens, the researchers identified that the "essence" of the arithmetic task can be distilled into a single Function Vector. By adding this vector to the model's internal activations, zero-shot performance can be boosted to near one-shot levels without providing a textual example.
Prioritizing Format over Factual Correctness
The study highlights a surprising reliance on surface-level patterns. Providing an arithmetically incorrect example (e.g., $1+1+1=5$) was found to be more helpful than an example with the wrong format (e.g., using words instead of numerals). Furthermore, replacing numbers with random symbols (e.g., "alpha + house + x = 8") only slightly degraded performance, whereas changing the result to a non-numeric symbol caused accuracy to collapse. This suggests that LLMs use ICEs primarily to identify the template of the answer rather than to learn the underlying mathematical logic.
Conclusion
This mechanistic analysis reveals that ICL in arithmetic is driven by structural anchors and specific information-routing circuits. The model's preference for format over factual accuracy suggests that ICL functions more as a pattern-matching mechanism than a reasoning engine in these contexts. Future research will explore if these findings hold for more complex Chain-of-Thought reasoning and even larger-scale models.
Summary updated