Transformers Linearly Represent Constrained-based World Models in Sudoku

Roman Kniazev, Nathanaël FijalkowNeurIPS 2026

TL;DR

When you train a transformer on Sudoku solving traces, it doesn't visualize the board as 81 individual squares like a human might. Instead, it spontaneously organizes its internal "world model" around the game’s underlying rules—tracking which numbers live in each row, column, and box. This tells us that if we only look for obvious, surface-level facts inside neural networks, we might completely underestimate how deeply they understand a problem.

What Problem Does This Paper Address?

Imagine teaching an AI to play board games purely by feeding it transcripts of moves—never once showing it an actual grid. Previous mechanistic interpretability studies on games like Othello and chess revealed something remarkable: transformers spontaneously build linear "world models" inside their activations, dedicating specific directions in vector space to track the contents of every single square on the board.

In board games, tracking individual cells makes total sense. But what happens in a combinatorial constraint-satisfaction problem like Sudoku? In Sudoku, knowing what's in a single cell matters far less than knowing what's missing from its row, column, and $3\times3$ box (its 27 overlapping "substructures"). Kniazev and Fijalkow ask a sharp question: when a transformer learns Sudoku, does its internal geometry mirror the visual surface of the board (81 cells), or does it mirror the abstract algebra of the rules (27 constraint groups)?

Methods

Following prior work on teaching transformers trial-and-error reasoning, the authors train a standard 8-layer, 8-head causal transformer on step-by-step Sudoku solving traces that include logical deductions and backtracking guesses.

To reverse-engineer what the trained model is thinking right after reading a puzzle's initial clues, they apply standard mechanistic interpretability tools in a new domain:

  • Linear Probing: Training simple logistic regression classifiers on the model's internal activations (the residual stream) to see what concepts can be cleanly read out as straight lines in activation space.
  • Activation Patching (Causal Intervention): Mathematically overwriting those linear directions to trick the model into thinking a digit is already present in a row, column, and box, testing if the model actually uses this representation to make decisions.
  • Circuit Analysis (Logit Lens & Direct Logit Attribution): Projecting intermediate layer outputs and individual attention heads/MLP neurons directly into vocabulary space to watch how candidate digits are promoted or suppressed step-by-step.

Datasets

The authors use the existing sudoku-3m dataset, training on 2.7 million puzzles and evaluating on a held-out test set of 150,000 puzzles. To generate the training sequences, they run a randomized Norvig-style solver over the puzzles, converting board placements and backtracking steps ([push], [pop]) into sequences of up to 250 tokens. Probes are trained and tested on subsets of a few thousand held-out puzzles (e.g., 5,120 for training, 1,280 for evaluation).

Key Insights and Ideas

  • Constraints beat surface facts: If you probe the model to ask "What digit is in Row 3, Column 4?", the linear probes struggle. Why? Because knowing which digits exist in Row 3, Column 4, and Box 2 is all you need to play legally—and that constraint summary doesn't uniquely reveal every filled cell! The network optimizes for rule-relevant state, not pixel-perfect memory.
  • A sharp phase transition: The model doesn't build its world model gradually. Cross-layer probe transfers show the substructure representation is absent in layers 1–3, snaps sharply into crystal-clear focus at layer 4, and stays geometrically stable through layer 7 across the entire solving trace. Cross-layer phase transition of the substructure world model
  • Attention heads act as local referees: Mid-layer attention heads physically specialize in specific rows, columns, boxes, bands, or stacks. When a head sees a digit in its assigned territory, it directly pushes down the probability of placing that digit anywhere else in that region while gently boosting absent digits.
  • The two-stage "Naked Single" circuit: When an empty cell has only one legal digit left (a naked single), how does the model pull the trigger? Mid-layers quietly rank the right digit #1 for that cell, and then a tiny, sparse set of dedicated "detector" neurons in the very last MLP layer fires exclusively on single-candidate cells—massively boosting all digits for that cell at once so the softmax locks onto the leader.
Cross-layer phase transition of the substructure world model

Key Results

The trained transformer solves 97.5% of held-out grids completely (98.4% per-cell accuracy). Inside its activations:

  • Substructure vs. Cell Probing: At layers 4–6, binary linear probes asking "Is digit $d$ in substructure $S$?" hit 1.00 (100%) exact-match accuracy, and empty-cell candidate probes also hit 1.00 (as linear combinations of substructures). Meanwhile, probes for exact filled-cell contents peak at just 0.572.
  • Causal Proof: Patching substructure directions to falsely indicate a digit is already taken causes the clean top-1 placement score to plummet by ~25 logits at layer 5, flipping the model's top choice in 95.3–99.7% of cases. Probe exact-match accuracy vs. causal logit drop across layers
  • Monosemantic Gatekeepers: Before the final MLP block, the correct digit in a unique naked single is already ranked first 98.77% of the time. Scanning the 3,456 neurons in the final MLP isolates 91 dedicated neurons covering all 81 cells (71 cells get one neuron; 10 get two). Firing adds an average uniform +3.00 logit boost to that cell's tokens; ablating a cell's neuron drops its target placement probability by 0.585 while leaving other naked singles on the exact same board untouched.
  • Beyond Sudoku: Preliminary tests on work-allocation and graph-coloring tasks show similar constraint-aligned representations (e.g., 0.966–0.976 exact match on worker/machine coverage vs. 0.546 on individual job assignments).
Figure 1: (Left) Mean exact match accuracy of three families of binary linear probes trained at the [clues_end] token over different layers. Blue: 729 probes predicting if a digit occupies a cell, trained and evaluated only on filled cells (exact match across all nine predictions for a cell); Orange: 729 probes predicting if a digit is a valid candidate in a cell, trained and evaluated only on empty cells (exact match across the cell’s candidate set); Green: 243 probes predicting if a digit is present in a substructure (exact match across all nine predictions for a substructure). Scores are averaged across cells or substructures, respectively. (Right) Logit drop of the clean model’s top-ranked placement token after activation patching of substructure probe directions across layers.

Limitations and Future Work

The deep mechanistic dive focuses on a single 8-layer architecture trained on randomized backtracking traces. It remains an open question whether larger or smaller models—or models trained without backtracking—develop the exact same substructure geometry and naked-single neurons. Additionally, while the authors explain what mid-layer attention heads do with the information they read (OV circuits), they haven't yet reverse-engineered how those heads learn where to look (QK circuits). Future work aims to watch how these circuits crystallize during training (such as checking for sudden "grokking" transitions) and test a wider variety of constraint-satisfaction problems.

Summary updated

Abstract

Do transformers, when trained on sequential reasoning traces, build internal models of the underlying task? And if so, does the structure of those internal representations mirror the structure of the domain? We train an 8-layer transformer on Sudoku solving traces and perform a mechanistic analysis of its internal computation. We find a linearly represented substructure world model: it does not represent the board state cell by cell, as a human analyst would expect, but organizes information around the rows, columns, and boxes that Sudoku's constraints act on. We see that mid-layer attention heads organize around Sudoku's substructures, suppressing placement logits for digits already present and promoting those for absent digits. We identify a naked-single circuit: a small set of dedicated neurons in the final MLP layer, each individually detecting when exactly one digit remains possible for a specific cell, and reliably promoting that digit. These findings suggest that transformers trained on solving traces may encode constraint-relevant information more cleanly than individual surface facts. For interpretability, probing only the obvious surface decomposition of a task may therefore underestimate what the model has learned.
BibTeX
@inproceedings{kniazev2026transformers,
  author = {Roman Kniazev and Nathanaël Fijalkow},
  title = {{Transformers Linearly Represent Constrained-based World Models in Sudoku}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=8RPfEpnyrk},
}
Figure