Higher Embedding Dimension Creates a Stronger World Model for a Simple Sorting Task

Brady Bhalla, Honglu Fan, Nancy Chen, Tony Yue Yu · DOI

Abstract

This study explores the intersection of reinforcement learning and mechanistic interpretability by examining how a Transformer's internal logic evolves with increased capacity. Using a minimalist single-head decoder-only architecture tasked with sorting sequences via adjacent swaps, we find that while minimal embedding dimensions suffice for high accuracy, larger dimensions foster a cleaner, more robust "world model." We identify a specific "sorting circuit" where the model encodes global token order into attention weights and selects swaps based on the largest gaps. Our results suggest that overprovisioning model capacity can lead to more interpretable and consistent internal mechanisms.

Introduction

The "world model" hypothesis suggests that neural networks do not merely memorize patterns but build structured internal representations of their environment's rules. Mechanistic interpretability aims to decode these "black boxes" by identifying specific internal algorithms. This paper investigates whether Transformers build such models for simple algorithmic tasks and how model capacity—specifically the embedding dimension—influences the fidelity of these internal structures.

Methodology

The researchers employed a "minimalist" Transformer: a single-head, decoder-only model without multi-layer perceptrons (MLPs), isolating the role of the attention mechanism.

Training and Task

Models were trained using Proximal Policy Optimization (PPO) on a sorting task where the "state" is a permutation of numbers and the "action" is an adjacent swap. The embedding dimension was varied from 2 to 128. The study utilized synthetic datasets of all permutations for sequence lengths 6 (720 states) and 8 (40,320 states), training 475 agents to ensure statistical robustness.

Evaluation Metrics

Three primary metrics were used to evaluate the models:

  1. Sorting Accuracy: The fraction of correct swaps made.
  2. Global Order Encoding: A measure of how well the attention matrix aligns with the true numerical order.
  3. Difference-based Swap Rule: A measure of how often the model's chosen swap corresponds to the largest "gap" in its internal ordering.

The Emergence of the "Sorting Circuit"

A key insight is that Accuracy ≠ Understanding. While a model with an embedding dimension as low as 6 can achieve near-perfect accuracy, its internal logic is often messy. As the dimension increases toward 30, a consistent "sorting circuit" emerges. The model learns to map tokens to values between 0 and 1 in its attention weights and identifies the "most out of order" segment by finding the largest difference between adjacent values.

Overprovisioning—giving the model more dimensions than strictly necessary—makes the model's internal logic more predictable and robust. Larger models avoid the "local greedy trap," where low-capacity models fix local errors but fail to recognize global inversions.

Key Results

The study found a distinct performance plateau where accuracy saturates early. For length 6 sequences, nearly all agents achieved 100% accuracy once the embedding dimension exceeded 16.

Sorting accuracy saturates at low embedding dimensions, particularly for length 6 sequences.

Despite the early plateau in accuracy, the fidelity of the internal representation continued to improve until the embedding dimension reached approximately 30. In these high-capacity models, the hypothesized "largest gap" rule explained behavior with high precision.

Mechanism alignment (Top 1 and Top 2 predictions) improves and stabilizes as embedding dimension increases, supporting the emergence of a consistent sorting circuit.

The chosen swap matched the top-1 predicted gap approximately 76-77% of the time and the top-2 gaps over 90% of the time in high-accuracy models.

Conclusion

While limited by the simplicity of the architecture and task, this research provides evidence that higher model capacity facilitates the development of coherent internal world models. Future work could explore more complex architectures, non-adjacent swap tasks, and larger sequence scales to determine if these "ordering circuits" are a universal feature of algorithmic learning in Transformers.

Summary updated

BibTeX
@inproceedings{bhalla2025higher,
  author = {Brady Bhalla and Honglu Fan and Nancy Chen and Tony Yue YU},
  title = {{Higher Embedding Dimension Creates a Stronger World Model for a Simple Sorting Task}},
  booktitle = {LAW @ NeurIPS},
  year = {2025},
  url = {https://openreview.net/forum?id=vdM2AKWUjq},
}
Figure