Transformers Linearly Represent Constrained-based World Models in Sudoku
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.