TL;DR
Even when a tiny transformer has enough capacity to achieve near-perfect task accuracy, expanding its embedding dimension dramatically improves the quality, consistency, and interpretability of its internal representations. By training minimal transformer agents via reinforcement learning (RL) on a toy sorting task, the authors show that models learn a clean, two-step algorithmic "world model" whose internal fidelity continues to sharpen well after performance saturates.
What Problem Does This Paper Address?
Mechanistic interpretability aims to reverse-engineer the computational circuits learned by neural networks. A central question is the "world model" hypothesis: do models merely learn statistical heuristics, or do they construct structured internal representations of their environment's state and causal rules?
While larger models generally perform better on downstream tasks, it remains unclear how model capacity—specifically embedding dimensionality—shapes the emergence and fidelity of these internal representations when task performance is already near 100%. To study this in a fully controlled setting, the authors frame adjacent-swap sorting (bubble sort) as an RL task, isolating whether and how self-attention mechanisms internalize an algorithmic procedure.
Methods
- Architecture: A stripped-down, single-layer, single-head decoder-only transformer with causal self-attention and learned positional/token embeddings (no multilayer perceptron), followed by linear actor and critic heads.
- Task & RL Formulation: Given an unsorted sequence of arbitrary tokens representing numbers $1$ to $\ell$, the agent selects an index $i \in \{1, \dots, \ell-1\}$ to swap adjacent elements $(i, i+1)$. Rewards are sparse: $+1$ if the move results in a sorted sequence, and $-0.001$ per step otherwise.
- Training: Agents were trained with Proximal Policy Optimization (PPO) over 1M, 2M, or 10M timesteps across 475 random seeds, testing sequence lengths $\ell \in \{6, 8\}$ and embedding dimensions $d_k \in [2, 128]$.
- Mechanistic Evaluation Metrics:
- Sorting Accuracy: Proportion of optimal/correct adjacent swaps chosen across all initial permutations.
- Global Order Encoding: The normalized proportion of non-inversions between the true token rank and the weights in the final row of the attention matrix ($W_\ell$).
- Difference-Based Swap Alignment: How often the agent's chosen swap corresponds to the largest adjacent drop/difference in the attention weight values.
Datasets
The authors evaluate models on the complete state space of finite permutations:
- Length 6: $6! = 720$ possible states.
- Length 8: $8! = 40,320$ possible states.
- The environment was implemented as an OpenAI Gym task where tokens have no predefined numeric value; the agent must discover ordering relationships purely from reward feedback.
Key Insights and Ideas
- The Emergent Two-Step Circuit: High-performing agents consistently converge to the same internal algorithm:
- Global Order Mapping: The final row of the attention matrix maps tokens monotonically by numerical value (e.g., lower token values receive lower attention weights).
- Max-Difference Decision Rule: The value and linear projection compute differences between consecutive attention weights, and the policy executes the swap at the location of the largest inversion gap.
- Representation Quality Continues to Grow Past Accuracy Saturation: Accuracy saturates at minimal embedding sizes ($d_k \approx 6$ for length 6, and $>16$ for length 8). However, internal alignment metrics (global order fidelity and swap alignment) keep rising until $d_k \approx 30$.
- Overprovisioning Width Enhances Interpretability: Increasing the embedding dimension doesn't just provide redundant capacity; it suppresses failure modes like the "local greedy trap" (fixing a localized swap that worsens the global inversion count) and produces cleaner, more predictable latent geometry.
Key Results
- Task Success: For sequence length 6, $99.2\%$ of agents achieved $100\%$ accuracy once embedding dimension exceeded 16. For length 8, $37.4\%$ reached perfect accuracy (averaging $90.7\%$ accuracy after 10M iterations).
- Internal Ordering Fidelity: For length 6, the non-inversion score in the attention weights starts near chance ($57\%$) at small embedding sizes and scales to $87\%$ around dimension 30 (an average of only $\sim 2$ inversions across all inputs). For length 8, it reaches $78\%$.
- Decision Alignment: Among high-accuracy agents, the chosen swap matched the largest attention gap (Top 1) in $76.2\%$ (length 6) and $76.8\%$ (length 8) of moves, rising to $94.0\%$ and $92.5\%$ for Top 2.
- Cross-Metric Correlation: The fidelity of the internal ordering and the swap-prediction alignment were strongly correlated ($r^2 = 0.56$).
Limitations and Future Work
- Narrow Architectural Scope: Experiments were restricted to single-head, 1-layer causal transformers without MLPs. Multi-head attention, deeper layers, and non-causal attention remain unexplored.
- Scalability of the State Space: The combinatorial explosion of sorting ($n!$) restricted experiments primarily to lengths 6 and 8.
- Strict Adjacency Constraints: Only adjacent transpositions were allowed. Future work could relax this to arbitrary swaps (to see if merge sort or quicksort heuristics emerge), introduce noisy or partially observed tokens, or analyze multi-head specialization.
Summary updated