Manuscript Offprint

arXiv:2611.26228

Attention Head Specialization: Phase Transitions in Sample Complexity

Léo Catteau, O. Duranthon, Lenka Zdeborová

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Attention heads specialize into distinct functions during training, often emerging in stages together with sharp changes in model behavior. While this phenomenon has mostly been studied as a function of training time, we ask how head specialization depends on the amount of available training data. Empirically, we find that heads specialized to syntactic relations in BERT emerge as the dataset size increases. We then study this phenomenon in a solvable high-dimensional model of multi-head attention and establish that, in this model, head specialization is a genuine phase transition in sample complexity, corresponding to a non-analyticity in the test error and other observables. Depending on data structure and regularization, specialization can follow uninformative head differentiation or occur through a cascade of phase transitions that progressively recover weaker latent features, providing a statistical form of simplicity bias. Finally, we relate these statistical transitions to the stagewise emergence of specialized heads during online learning, disentangling statistical from dynamical origins of head specialization.

1 Introduction

Multi-head attention is a central architectural ingredient of modern transformer models, enabling multiple attention patterns to coexist within a single layer. Different heads learn to perform distinct functions, while their collaboration allows implementing circuits that no individual head captures alone. Empirical studies have identified such specialized heads across multiple settings, including induction heads involved in in-context learning (ICL) (Olsson et al., 2022; Yin and Steinhardt, 2025), heads specializing to different syntactic relations (Chen et al., 2024a), and heads progressively differentiating into distinct functional roles during training (Wang et al., 2025). Head specialization has predominantly been studied as a function of training time: specialized mechanisms emerge at distinct stages of training, sometimes coinciding with sharp improvements in performance or drops in training loss (Hoogland et al., 2025; Aoyama et al., 2026).

Much less is known about specialization as a function of the amount of available training data. Rather than asking when during training different heads specialize, one can ask how many samples are needed for distinct specialized heads to emerge. This distinction separates a statistical question about the information available in the dataset from the particular optimization dynamics used to learn it. We investigate this question in BERT masked language models (MLMs), where syntactic attention structure (SAS), characterized by heads specializing to different syntactic relations (Clark et al., 2019), emerges during training alongside a sharp drop in loss (Chen et al., 2024a). Empirically, training BERTSmall\mathrm{BERT}_{\mathrm{Small}} models from random initialization on datasets of NN sequences from BookCorpus and English Wikipedia reveals a clear phenomenology shown in Fig. 1: as NN increases, SAS emerges sharply over a characteristic range of dataset sizes, accompanied by abrupt changes in the learning curves. For each dataset size, we fix the sequences and masking patterns throughout training and report metrics at the checkpoint with lowest validation MLM loss. Following (Chen et al., 2024a), we quantify SAS on a separate syntactically annotated corpus as the fraction of parent-child pairs recovered by each head’s maximum word-level attention. Aggregating accuracy across relations for the best head gives the unlabeled attachment score (UAS), which measures alignment between attention and syntactic structure enabled by specialization of the heads.

Figure 1: Head specialization as a function of sample complexity. Left: BERTSmall\mathrm{BERT}_{\mathrm{Small}} models trained independently on fixed datasets of NN sequences through minimization of masked-language-modeling (MLM) loss. (first panel) Validation error and training MLM loss (140). (second panel) Unlabeled attachment score (UAS)(143), measuring the fraction of dependency parents correctly recovered from word-level attention by the best head, layer, and attention direction. Curves show averages over five runs, with shaded bands indicating seed variability. Reported metrics are evaluated at early-stopped checkpoints selected by the lowest validation loss along each training trajectory. Experimental details are provided in App. E.2. Right: Qualitative comparison with the solvable flipping spike model (Sec. 2) as the sample complexity α=N/D\alpha=N/D increases, with NN the number of sequences and DD the token dimension. Solid lines correspond to theoretical predictions and markers to numerical experiments with D=2000D=2000, ν1=0.35\nu_{1}=0.35, ν2=2.0\nu_{2}=2.0, L=10L=10, H=2H=2, λ=0.2\lambda=0.2. (third panel) Test and training errors exhibit non-analyticity at the specialization threshold. (fourth panel) Head–feature alignment reveals specialization to the latent feature.

Sample complexity provides a natural control parameter for asking whether such emergence corresponds to a genuine phase transition. In the statistical physics of learning, one considers a proportional high-dimensional limit in which the number of trainable degrees of freedom and training samples grow together, D,N→∞D,N\to\infty at fixed α=N/D\alpha=N/D. This framework has a long history in neural-network theory, where increasing sample complexity can induce phase transitions from permutation symmetric to specialized solutions in the committee machine (Schwarze and Hertz, 1992; Schwarze and Hertz, 1993; Aubin et al., 2018). In this limit, changes between qualitatively different learning regimes can become sharp, with nonanalyticities of macroscopic observables at critical values of α\alpha. For multi-head attention, this raises a precise question: can the emergence of specialized heads be understood as a genuine phase transition controlled by sample complexity?

We answer this question in a tractable multi-feature variant of the single-location regression (SLR) model (Marion et al., 2025; Sagitova et al., 2026), whose head-specialization dynamics under online learning were characterized in Sagitova et al. (2026). The task is to retrieve one token carrying a low-dimensional latent signal from a sequence of otherwise uninformative tokens, using multiple attention heads that can specialize to different latent features. Here, instead of following training dynamics, we study the associated empirical risk minimization (ERM) problem as a function of sample complexity. Fig. 1 shows that this model exhibits behavior qualitatively analogous to that observed in the BERTSmall\mathrm{BERT}_{\mathrm{Small}} experiment. Moreover, we show that, in this model, head specialization occurs through phase transitions in sample complexity, characterized by non-analyticities in the order parameters and prediction error at critical values of α\alpha.

The resulting phase diagram reveals a richer structure than a single specialization threshold. At low regularization and low sample complexity, specialization is preceded by an unspecialized phase with broken head-permutation symmetry, in which heads differ by fitting sample-specific fluctuations without recovering distinct latent features. This illustrates that distinct attention patterns alone do not imply specialization that improves generalization. For heterogeneous signals, increasing sample complexity instead produces a cascade of specialization transitions: heads successively recover latent features from strongest to weakest, so that increasingly subtle structure requires increasingly more data. This provides a statistical counterpart of stagewise learning and simplicity bias, arising here from the structure of the ERM solutions rather than from a particular training dynamics.

Finally, we connect these equilibrium transitions back to the training-time phenomenology from which we started (Olsson et al., 2022; Wang et al., 2025; Aoyama et al., 2026; Chen et al., 2024a). In online learning, training time and the amount of observed data increase together, entangling the statistical transition with optimization dynamics. In the solvable model, we show how the critical sample complexities map onto the emergence of specialized heads along training. This perspective suggests that some of the abrupt or stagewise emergence observed during transformer training may reflect underlying statistical phase transitions, while distinguishing these from phenomena that are genuinely dynamical and helping clarify how such transitions manifest in learning dynamics.

References (27)