Abstract
While transformer models exhibit strong capabilities on linguistic tasks, their complex architectures make them difficult to interpret. Recent work has aimed to reverse engineer transformer models into human-readable representations called circuits that implement algorithmic functions. We extend this research by analyzing and comparing circuits for similar sequence continuation tasks, which include increasing sequences of Arabic numerals, number words, and months. By applying circuit interpretability analysis, we identify a key sub-circuit in both GPT-2 Small and Llama-2-7B responsible for detecting sequence members and for predicting the next member in a sequence. Our analysis reveals that semantically related sequences rely on shared circuit subgraphs with analogous roles. Additionally, we show that this sub-circuit has effects on various math-related prompts, such as on intervaled circuits, Spanish number word and months continuation, and natural language word problems. Overall, documenting shared computational structures enables better model behavior predictions, identification of errors, and safer editing procedures. This mechanistic understanding of transformers is a critical step towards building more robust, aligned, and interpretable language models.
Introduction
Large Language Models (LLMs) have achieved remarkable success across a wide array of cognitive tasks, yet they largely remain "black boxes" with opaque internal mechanisms. Mechanistic interpretability seeks to address this by reverse-engineering these models into human-readable "circuits"—discrete collections of neurons and attention heads that execute specific algorithmic functions. While previous research has successfully mapped circuits for isolated linguistic tasks, a fundamental question remains: do LLMs employ universal "machinery" to solve logically analogous tasks?
This study investigates whether models like GPT-2 and Llama-2 develop shared, abstract representations for ordinality and progression. By analyzing sequence continuation tasks—ranging from simple Arabic numerals ("1, 2, 3") to more complex month sequences ("Jan, Feb, Mar")—we uncover "shared circuits" that are reused across semantically related domains. These circuits appear to be foundational building blocks for higher-order reasoning, including arithmetic and word problems.
Methodology and Datasets
To dissect the internal logic of these models, we utilized a multi-stage interpretability toolkit. Our approach began with Connectivity Discovery via iterative pruning (knockout methods), where we systematically ablated components to measure their impact on model performance. Components whose removal led to significant performance degradation were identified as critical nodes in the circuit.
We further characterized these components through Functionality Discovery, which included:
- Attention Pattern Analysis: Evaluating Query-Key (QK) matrices to determine which tokens specific heads prioritize.
- Successor Scoring: Measuring the degree to which a component's output directly predicts the correct next token in a sequence.
- Logit Lens: Projecting internal representations back into the vocabulary space to observe the model's intermediate "reasoning" steps.
Our experiments were conducted on both GPT-2 Small (117M parameters) and Llama-2-7B to test for architectural and scale-based universality. We employed several targeted synthetic datasets, including Arabic numerals (1-12), number words ("one" to "twelve"), and months. To test the robustness and broader utility of these circuits, we also evaluated math-related prompts (e.g., intervaled sequences and double-digit addition) and multilingual sequences (Spanish number words and months).
The Ordinality Circuit: Shared Computational Structures
Our analysis revealed that the model does not merely memorize sequences; instead, it employs a specialized "ordinality" sub-circuit to detect set members and predict successors. We identified a clear functional specialization among the heads within this circuit.
As illustrated in Figure 1, the circuit consists of three primary functional stages:
- Detection Heads (e.g., 1.5, 4.4 in GPT-2): These act as "scouts," identifying that a token belongs to a specific sequence type (e.g., a number or a month).
- Previous Token Heads (e.g., 7.11): These heads aggregate the sequence's history and pass this contextual information to the final tokens.
- Successor Components (e.g., 9.1, MLP 9): These components perform the final logical step to predict the next item in the sequence.
A key finding is "circuit entanglement": the circuit for Arabic numerals is largely a subset of the circuit for number words. This suggests that LLMs learn a core "number-ness" abstraction and build upon it for more complex linguistic representations.
Experimental Results
The importance of these shared circuits is underscored by the dramatic performance drops observed during ablation studies. In GPT-2 Small, the ablation of a single key head (Head 0.1) resulted in a 78.74% decrease in accuracy for number word sequences.
As shown in Figure 6, several heads play critical roles across multiple sequence types. For instance, Head 4.4 is particularly vital for month sequences, showing a 73.16% performance drop when ablated.
Furthermore, these circuits are foundational for arithmetic. Ablating the sequence circuit in Llama-2-7B destroyed its ability to perform double-digit addition in 98% of cases, compared to a baseline drop of only ~32% for random ablations. Similarly, ablating the three most important heads in Llama-2-7B reduced accuracy on month-based word problems by 37.21%. These results suggest that the "successor" logic identified in sequence continuation is a convergent feature of transformer training and a prerequisite for mathematical reasoning.
Discussion and Future Directions
While this work provides a mechanistic understanding of sequence processing, several limitations remain. The "months" dataset is inherently small, and the sequences studied are primarily linear. Future research should explore more complex patterns, such as Fibonacci sequences or alternating progressions, to see if similar shared circuits exist. Additionally, our analysis relies on the "linear representation hypothesis," which may simplify the high-dimensional nature of neural representations.
Ultimately, identifying these shared computational structures is a critical step toward "model editing." By understanding the precise logic of these circuits, researchers can potentially fix specific errors or improve model alignment without causing unintended side effects in other functional areas.
Summary updated