A study of small transformer networks found that their strategy changes with the diversity of the data used for training.
Researchers analyzed a two-layer transformer trained to predict the next state in sequences generated by a finite set of discrete Markov chains. They identified four phases, differing in whether the network memorized the training processes or generalized beyond them, and whether it relied on one-point or two-point statistics.
The phases were implemented by different multi-layer subcircuits. One circuit estimated transition patterns directly from the sequence, while another identified the underlying process, pooled that information into a compact task representation and used it to make predictions. Two boundaries linked the shift between memorization and generalization to the diversity of the training data, with one arising from competition between circuits and the other from a limit on the network’s representation.
Four ways to predict
The researchers found four algorithmic phases: 1-point and 2-point generalization, and 1-point and 2-point memorization. In the generalizing route, a two-stage attention circuit extracted local pairs of states and matched them to estimate transition statistics. In the memorizing route, attention and feedforward layers formed an encoder-pool-decoder circuit: it built nonlinear representations of neighboring state pairs, pooled them across the sequence and decoded the resulting task representation together with local information.
The task-recognition circuit could also generalize, but only under stronger conditions than the statistical route. The study’s theory linked the transition between 1-point and 2-point generalization to the symmetry of the training dynamics and identified features of the loss landscape associated with generalization. The two boundaries between memorization and generalization depended on the number of training chains, K: one was attributed to competition between subcircuits and the other to a representational bottleneck.
Why the circuits matter
The findings show that in-context learning is not implemented by one universal process in this setting. A transformer can use sequence statistics directly or infer and retrieve a representation of the process that produced the sequence, and different training conditions favor these routes.
That distinction provides a mechanistic explanation for why the diversity of training data affects whether a network memorizes or generalizes. It also highlights separate roles for attention and feedforward layers in producing context-dependent predictions.
Evidence and limits
The study combines numerical experiments with a theory constrained by the symmetries of the model’s training dynamics, plus minimal models designed to isolate the two mechanisms. The experiments used a two-layer transformer with one attention and one feedforward block per layer, trained on sequences from a finite set of discrete Markov chains with 10 possible states and a 64-dimensional internal representation.
These results are established for this synthetic Markov-chain setting and this small transformer architecture. The excerpts do not show that the same four phases or boundaries occur unchanged in larger models or in natural-language tasks. The study characterizes mechanisms within its chosen setup rather than measuring performance across a broad range of real-world applications.
// Source
Physical Review X · 2026 · DOI: 10.1103/p3qs-d91v
Authors: Cole Gibson, Wenping Cui, Gautam Reddy