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) [22 , 37 ] , heads specializing to different syntactic relations [8 ] , and heads progressively differentiating into distinct functional roles during training [34 ] . 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 [16 , 1 ] .
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 [10 ] , emerges during training alongside a sharp drop in loss [8 ] . Empirically, training BERTSmall _{\text{Small}} Small models from random initialization on datasets of N N N sequences from BookCorpus and English Wikipedia reveals a clear phenomenology shown in Figure 1 : as N N N 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., [8 ] , 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: BERTS m a l l _{\mathrm{Small}} Small models trained independently on fixed datasets of N N N 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. § 15 .§ 3 . Right: Qualitative comparison with the solvable flipping spike model (§ 3 ) as the sample complexity α = N / D \alpha= N/D α = N / D increases, with N N N the number of sequences and D D D the token dimension. Solid lines correspond to theoretical predictions and markers to numerical experiments with D = 2000 D = 2000 D = 2000 , ν 1 = 0.35 \nu_1 = 0.35 ν 1 = 0.35 , ν 2 = 2.0 \nu_2 = 2.0 ν 2 = 2.0 , L = 10 L = 10 L = 10 , H = 2 H = 2 H = 2 , λ = 0.2 \lambda= 0.2 λ = 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 D , N → ∞ at fixed α = N / D \alpha= N/D α = 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 ([28 , 29 , 2 ] ). 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 ([21 , 26 ] ), whose head-specialization dynamics under online learning were characterized in Sagitova et al. [26 ] . 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. Figure 1 shows that this model exhibits behavior qualitatively analogous to that observed in the BERTS m a l l _{\mathrm{Small}} 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 [22 , 34 , 1 , 8 ] . 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.
Main Contributions. The main empirical result of the paper is the characterization of head specialization in the number of training samples. In a tractable model of multi-head attention, we then show that head specialization is a statistical phase transition in sample complexity, and connect the equilibrium transition to specialization during training. Our main technical contributions are:
We derive a tight asymptotic characterization of the regularized ERM problem in the proportional high-dimensional limit N , D → ∞ N, D \to\infty N , D → ∞ at fixed α = N / D \alpha= N/D α = N / D , through closed self-consistent equations for the errors and order parameters (§ 4 ).
We show that head specialization is a genuine phase transition in sample complexity. Depending on regularization and signal structure, we uncover an unspecialized phase with broken head-permutation symmetry, as well as a cascade of specialization transitions in which increasingly weaker latent features are recovered with increasing sample complexity, yielding a statistical form of simplicity bias (§ 5 ).
Notations. We write [ n ] = { 1 , … , n } [n] = \{1, \ldots, n\} [ n ] = { 1 , … , n } , δ i j \delta_{ij} δ ij for the Kronecker delta, and I n \mathbb{I}_n I n for the identity matrix. For a matrix A A A , A i A_i A i and A ⋅ j A_{\cdot j} A ⋅ j denote its i i i -th row and j j j -th column. We write ∥ ⋅ ∥ 2 \lVert\cdot\rVert_2 ∥ ⋅ ∥ 2 for the Euclidean norm, ∥ ⋅ ∥ F \lVert\cdot\rVert_F ∥ ⋅ ∥ F for the Frobenius norm, and v ⊗ 2 = v v T v^{\otimes2} = vv^{\mathsf{T}} v ⊗ 2 = v v T . We denote by N ( μ , Σ ) \mathcal{N}(\mu, \Sigma) N ( μ , Σ ) the Gaussian distribution with mean μ \mu μ and covariance Σ \Sigma Σ .
Empirical emergence and head specialization. Specialized attention heads have been observed across architectures and tasks, including induction heads associated with in-context learning [22 , 37 ] , syntactic heads in masked language models [8 ] , and circuits studied in controlled synthetic settings (Singh et al., 2024). A complementary literature studies when such capabilities and internal mechanisms emerge during training, including abrupt changes in performance [35 ] , stagewise development and head differentiation [16 , 34 ] , and the emergence time of induction heads [1 ] . Such behavior can depend strongly on data, initialization, and training trajectory: emergent capabilities can be transient [30 ] , vary across random seeds [17 , 40 ] , and depend on the structure of the training data [24 ] . While these works predominantly follow a model through training, our BERT experiments instead hold dataset size fixed for each training run, and study how syntactic head specialization changes across datasets of different sizes.
Theory of attention and head specialization. Recent solvable models characterize learning in attention architectures, including single-location regression [21 , 13 ] , sequence multi-index models [32 ] , attention-indexed models [5 ] , mapping to generalized Potts model [25 ] , or hierarchical models [6 ] . Multi-head specialization has primarily been studied through training dynamics [9 , 30 , 39 , 26 , 38 ] . Here we instead study specialization at equilibrium as a function of sample complexity.
Phase transitions and specialization in neural networks. Specialization as a sample-complexity phase transition has a long history in committee machines, where increasing α = N / D \alpha= N/D α = N / D can induce transitions to solutions in which different hidden units align with distinct features of the data [28 , 29 , 2 , 23 ] . Phase transitions have also been studied in solvable attention models [12 ] ; most closely, Lavie et al. [18 ] establish a sample-complexity transition for the emergence of a single copy head. We instead study specialization of attention heads and the associated emerging generalization capabilities.
Single-location regression model
We consider the multi-feature spiked single-location regression (SLR) model of Sagitova et al. [26 ] . The task is to retrieve one randomly located relevant token from a sequence of otherwise uninformative tokens. The informative token is structured by a low rank planted signal over F F F latent directions. Learning this structure with multiple low-rank heads provides a tractable setting for studying head specialization.
Data model. We consider an embedding dimension D D D . We first draw F F F independent hidden spikes k f ∗ ∼ N ( 0 , I D ) k_f^* \sim\mathcal{N}(0, \mathbb{I}_D) k f ∗ ∼ N ( 0 , I D ) defining the latent structure that remains fixed across all sequences. We denote K ∗ = { k f ∗ } f = 1 F K^* = \{k_f^*\}_{f=1}^{F} K ∗ = { k f ∗ } f = 1 F the matrix with rows k f ∗ T k_f^{*\mathsf{T}} k f ∗ T . A sequence X ∈ R L × D X \in\mathbb{R}^{L \times D} X ∈ R L × D consists of L L L tokens { X ℓ } 1 ≤ ℓ ≤ L \{X_\ell\}_{1 \le\ell\le L} { X ℓ } 1 ≤ ℓ ≤ L . A hidden index ϵ ∈ [ L ] \epsilon\in[L] ϵ ∈ [ L ] identifies the relevant token X ϵ X_\epsilon X ϵ containing a planted spike k ^ \hat{k} k ^ generated from the F F F latent directions, while remaining tokens X ℓ ≠ ϵ X_{\ell\ne\epsilon} X ℓ = ϵ are independent isotropic Gaussian noise. For each sequence, we independently draw ϵ ∼ Unif ( [ L ] ) \epsilon\sim\operatorname{Unif}([L]) ϵ ∼ Unif ([ L ]) and the feature weights θ ∼ P θ \theta\sim P_\theta θ ∼ P θ with θ ∈ R F \theta\in\mathbb{R}^{F} θ ∈ R F , defining the sequence-dependent spike k ^ \hat{k} k ^ , such that the tokens X ℓ X_\ell X ℓ are independently distributed conditionally on ϵ \epsilon ϵ and θ \theta θ as
k ^ = K ∗ T θ D ∈ R D , X ℓ ∼ N ( δ ℓ , ϵ k ^ , I D ) , ℓ ∈ [ L ] . (1) \hat{k} = \frac{K^{*\mathsf{T}}\theta}{\sqrt{D}} \in\mathbb{R}^{D}, \qquad X_\ell\sim\mathcal{N}(\delta_{\ell,\epsilon}\hat{k}, \mathbb{I}_D), \quad\ell\in[L]. \tag*{(1)} k ^ = D K ∗ T θ ∈ R D , X ℓ ∼ N ( δ ℓ , ϵ k ^ , I D ) , ℓ ∈ [ L ] . (1)
The associated label is the relevant token y = X ϵ y = X_\epsilon y = X ϵ . As the latent ϵ \epsilon ϵ and θ \theta θ are sampled at every sequence/context, deducing them can also be seen as a simple case of in-context learning. In the following, we will consider two choices for the distribution P θ P_\theta P θ . In the flipping spike mode , a latent direction is kept constant while another flips sign randomly across sequences: F = 2 F = 2 F = 2 , θ 1 = ν 1 \theta_1 = \sqrt{\nu_1} θ 1 = ν 1 , and θ 2 ∼ Unif ( { − ν 2 , ν 2 } ) \theta_2 \sim\operatorname{Unif}(\{-\sqrt{\nu_2}, \sqrt{\nu_2}\}) θ 2 ∼ Unif ({ − ν 2 , ν 2 }) , where we define signal strengths ν 1 > 0 \nu_1 > 0 ν 1 > 0 , ν 2 > 0 \nu_2 > 0 ν 2 > 0 . In the non-isotropic Gaussian model , all components of the planted spike fluctuate independently with different covariances: θ f ∼ N ( 0 , ν f ) \theta_f \sim\mathcal{N}(0,\nu_f) θ f ∼ N ( 0 , ν f ) , where we define signal strengths ν 1 ≥ ⋯ ≥ ν F ≥ 0 \nu_1 \ge\dots\ge\nu_F \ge0 ν 1 ≥ ⋯ ≥ ν F ≥ 0 .
Multi-head attention. We consider learning of the stated task with a single layer of low-rank attention with H H H heads. This architecture is well suited for retrieval of low rank structure, with different heads attending to different features. Specifically, we consider the estimator f K : R L × D → R D f_K : \mathbb{R}^{L \times D} \to\mathbb{R}^D f K : R L × D → R D given by rank-one attention heads with trainable weights K = { k h } h = 1 H ∈ R H × D K = \{k_h\}_{h=1}^H \in\mathbb{R}^{H \times D} K = { k h } h = 1 H ∈ R H × D :
f K ( X ) = 1 H ∑ h = 1 H softmax ( X k h D ) T X , (2) f_K(X) = \frac{1}{H} \sum_{h=1}^{H} \operatorname{softmax}\left(\frac{X k_h}{\sqrt{D}}\right)^{\mathsf{T}} X, \tag*{(2)} f K ( X ) = H 1 h = 1 ∑ H softmax ( D X k h ) T X , (2)
where attention vectors are uniformly averaged across heads. This model can be viewed as a simplification of cross-attention with fixed sequence-independent query embedding and identity value matrix, as discussed in Marion et al. [21 ] and Duranthon et al. [13 ] . Note that, while considering larger (extensive) rank attention is technically possible (Boncoraglio et al. [5 ] ), this is left for future work. Similarly, training the value matrix with a fixed number of parameters could be accommodated by an extended parametrization. The current model then constitutes a relevant minimal estimator for the study of head specialization in the designed task. As mentioned in Sagitova et al. [26 ] , this type of attention layer is also used in practice (Carion et al. [7 ] ).
Empirical risk minimization. We study learning from a finite dataset D = { X μ , y μ } μ = 1 N \mathcal{D} = \{X_\mu, y_\mu\}_{\mu=1}^{N} D = { X μ , y μ } μ = 1 N of N N N independently sampled sequences, and their associated labels. An attention layer f ^ K \hat{f}_K f ^ K is learned by regularized empirical risk minimization (ERM):
K ^ = argmin K ∈ R H × D L t r a i n ( K ) , L t r a i n ( K ) = ∑ μ = 1 N 1 2 D ∥ y μ − f K ( X μ ) ∥ 2 2 + λ 2 ∥ K ∥ F 2 , (3) \hat{K} = \underset{K \in\mathbb{R}^{H \times D}}{\operatorname{argmin}} \mathcal{L}_{\mathrm{train}}(K), \qquad\mathcal{L}_{\mathrm{train}}(K) = \sum_{\mu=1}^{N} \frac{1}{2D}\lVert y_\mu- f_K(X_\mu)\rVert_2^2 + \frac{\lambda}{2}\lVert K\rVert_F^2, \tag*{(3)} K ^ = K ∈ R H × D argmin L train ( K ) , L train ( K ) = μ = 1 ∑ N 2 D 1 ∥ y μ − f K ( X μ ) ∥ 2 2 + 2 λ ∥ K ∥ F 2 , (3)
where λ > 0 \lambda> 0 λ > 0 is the ℓ 2 \ell_2 ℓ 2 regularization strength. The performance of the estimator (3) is evaluated through the training error E t r a i n \mathcal{E}_{\mathrm{train}} E train associated with the objective (3) , and the test error E \mathcal{E} E :
E t r a i n = 1 N ∑ μ = 1 N 1 2 D ∥ y μ − f ^ K ( X μ ) ∥ 2 2 , E = E X , y [ 1 2 D ∥ y − f ^ K ( X ) ∥ 2 2 ] . (4) \mathcal{E}_{\mathrm{train}} = \frac{1}{N}\sum_{\mu=1}^{N}\frac{1}{2D}\lVert y_\mu- \hat{f}_K(X_\mu)\rVert_2^2, \qquad\mathcal{E} = \mathbb{E}_{X,y}\left[\frac{1}{2D}\lVert y - \hat{f}_K(X)\rVert_2^2\right]. \tag*{(4)} E train = N 1 μ = 1 ∑ N 2 D 1 ∥ y μ − f ^ K ( X μ ) ∥ 2 2 , E = E X , y [ 2 D 1 ∥ y − f ^ K ( X ) ∥ 2 2 ] . (4)
High-dimensional limit. We analyze the ERM problem (3) in the proportional limit where D , N → ∞ D,N \to\infty D , N → ∞ while the ratio α = N / D \alpha= N/D α = N / D , the sample complexity, remains of order Θ ( 1 ) \Theta(1) Θ ( 1 ) . In order to study head specialization, we further assume the number of heads H H H , the number of features F F F , the sequence length L L L , and the regularization strength λ \lambda λ to be Θ ( 1 ) \Theta(1) Θ ( 1 ) . This proportional limit has been considered in a stream of previous works (e.g. Cui et al. [12 ] ; Troiani et al. [32 ] ; Cui and Zdeborová [11 ] ; Duranthon et al. [13 ] ), and allows deriving a closed-form characterization of the ERM problem which we present in the next section. As the number of trainable degrees of freedom grows linearly with D D D , taking N = Θ ( D ) N = \Theta(D) N = Θ ( D ) retains nontrivial interactions between the dataset and the architecture, and sample complexity α \alpha α appears as a natural control parameter to study head-specialization phase transitions. This particular scaling is, however, setting-specific: other well-defined control parameters may arise in different high-dimensional limits (e.g. extensive-rank architectures Gerace et al. [15 ] ; Erba et al. [14 ] ; Boncoraglio et al. [5 ] ; Barbier et al. [4 ] ), or be defined through properties of the data.
Asymptotic characterization of the empirical risk
The main technical result of this work is a closed-form characterization of the minimizers of the regularized empirical risk (3) obtained in the high-dimensional limit for the model (2) through the test error (4) , training error (4) and additional summary statistics as functions of sample complexity. Defined from the high-dimensional weights, these summary statistics concentrate in the high-dimensional limit and fully describe the model’s macroscopic state: the head–feature overlaps m h f m_{hf} m h f quantify the alignment between each head’s learned attention vector k h k_h k h and each planted feature direction k f ∗ k_f^{*} k f ∗ , while the self-overlaps q h h ′ q_{hh'} q h h ′ quantify the alignment between learned attention vectors k h k_h k h and k h ′ k_{h'} k h ′ , with diagonal entries encoding their normalized squared norms.
Result 3.1. Under the assumption of replica symmetry, in the limit N , D → ∞ N,D \to\infty N , D → ∞ , with H , F , L , ∥ θ ∥ 2 , λ , N / D = Θ D ( 1 ) H,F,L,\lVert\theta\rVert_2,\lambda,N/D=\Theta_D(1) H , F , L , ∥ θ ∥ 2 , λ , N / D = Θ D ( 1 ) , the summary statistics
m = K K ∗ ⊤ D ∈ R H × F , q = K K ⊤ D ∈ R H × H (5) m=\frac{KK^{*\top}}{D}\in\mathbb{R}^{H\times F},\qquad q=\frac{KK^{\top}}{D}\in\mathbb{R}^{H\times H} \tag*{(5)} m = D K K ∗ ⊤ ∈ R H × F , q = D K K ⊤ ∈ R H × H (5) concentrate in probability, and are solutions of the set of finite-dimensional self-consistent equations
m = ( λ I H + V ^ ) − 1 m ^ q = ( λ I H + V ^ ) − 1 ( m ^ m ^ ⊤ + q ^ ) ( λ I H + V ^ ) − 1 V = ( λ I H + V ^ ) − 1 (6) \begin{aligned}
m&=(\lambda I_H+\widehat{V})^{-1}\widehat{m}\\
q&=(\lambda I_H+\widehat{V})^{-1}(\widehat{m}\widehat{m}^{\top}+\widehat{q})(\lambda I_H+\widehat{V})^{-1}\\
V&=(\lambda I_H+\widehat{V})^{-1} \tag*{(6)}
\end{aligned} m q V = ( λ I H + V ) − 1 m = ( λ I H + V ) − 1 ( m m ⊤ + q ) ( λ I H + V ) − 1 = ( λ I H + V ) − 1 (6) m ^ = α E θ , Ξ [ V − 1 ( prox ( θ , Ξ ) 1 − ω 1 ) θ ⊤ ] q ^ = α E θ , Ξ [ V − 1 ( ∑ ℓ = 1 L ( prox ( θ , Ξ ) ℓ − ω ℓ ) ⊗ 2 ) V − 1 ] V ^ = − α E θ , Ξ [ V − 1 ( ∑ ℓ = 1 L ( prox ( θ , Ξ ) ℓ − ω ℓ ) ξ ℓ ⊤ ] q − 1 / 2 ] , (7) \begin{aligned}
\widehat{m}&=\alpha\mathbb{E}_{\theta,\Xi}\left[V^{-1}\left(\operatorname{prox}(\theta,\Xi)_1-\omega_1\right)\theta^{\top}\right]\\
\widehat{q}&=\alpha\mathbb{E}_{\theta,\Xi}\left[V^{-1}\left(\sum_{\ell=1}^{L}\left(\operatorname{prox}(\theta,\Xi)_\ell-\omega_\ell\right)^{\otimes2}\right)V^{-1}\right]\\
\widehat{V}&=-\alpha\mathbb{E}_{\theta,\Xi}\left[V^{-1}\left(\sum_{\ell=1}^{L}\left(\operatorname{prox}(\theta,\Xi)_\ell-\omega_\ell\right)\xi_\ell^{\top}\right]q^{-1/2}\right], \tag*{(7)}
\end{aligned} m q V = α E θ , Ξ [ V − 1 ( prox ( θ , Ξ ) 1 − ω 1 ) θ ⊤ ] = α E θ , Ξ [ V − 1 ( ℓ = 1 ∑ L ( prox ( θ , Ξ ) ℓ − ω ℓ ) ⊗ 2 ) V − 1 ] = − α E θ , Ξ [ V − 1 ( ℓ = 1 ∑ L ( prox ( θ , Ξ ) ℓ − ω ℓ ) ξ ℓ ⊤ ] q − 1/2 ] , (7) with the summary statistics { m , q , V } \{m,q,V\} { m , q , V } and their conjugates { m ^ , q ^ , V ^ } \{\widehat{m},\widehat{q},\widehat{V}\} { m , q , V } . In (6-7), we define the Gaussian random variables Ξ = { ξ ℓ } ℓ = 1 L \Xi=\{\xi_\ell\}_{\ell=1}^{L} Ξ = { ξ ℓ } ℓ = 1 L with ξ ℓ ∼ N ( 0 , I H ) \xi_\ell\sim\mathcal{N}(0,I_H) ξ ℓ ∼ N ( 0 , I H ) and the associated local fields Ω = { ω ℓ } ℓ = 1 L \Omega=\{\omega_\ell\}_{\ell=1}^{L} Ω = { ω ℓ } ℓ = 1 L with ω ℓ : = δ ℓ , 1 m θ + q 1 / 2 ξ ℓ \omega_\ell:=\delta_{\ell,1}m\theta+q^{1/2}\xi_\ell ω ℓ := δ ℓ , 1 m θ + q 1/2 ξ ℓ . The proximals { prox ( θ , Ξ ) ℓ } ℓ = 1 L \{\operatorname{prox}(\theta,\Xi)_\ell\}_{\ell=1}^{L} { prox ( θ , Ξ ) ℓ } ℓ = 1 L are defined as minimizers of the Moreau envelope
M ( θ , Ξ ) = inf Z ∈ R L × H { 1 2 ∑ ℓ = 1 L ( δ ℓ 1 − 1 H ∑ h = 1 H softmax ( Z : h ) ℓ ) 2 + 1 2 ∑ ℓ = 1 L ( Z ℓ − ω ℓ ) ⊤ V − 1 ( Z ℓ − ω ℓ ) } . (8) \mathcal{M}(\theta,\Xi)=\inf_{Z\in\mathbb{R}^{L\times H}}\left\{\frac{1}{2}\sum_{\ell=1}^{L}\left(\delta_{\ell1}-\frac{1}{H}\sum_{h=1}^{H}\operatorname{softmax}(Z:h)_\ell\right)^2+\frac{1}{2}\sum_{\ell=1}^{L}(Z_\ell-\omega_\ell)^{\top}V^{-1}(Z_\ell-\omega_\ell)\right\}. \tag*{(8)} M ( θ , Ξ ) = Z ∈ R L × H inf ⎩ ⎨ ⎧ 2 1 ℓ = 1 ∑ L ( δ ℓ 1 − H 1 h = 1 ∑ H softmax ( Z : h ) ℓ ) 2 + 2 1 ℓ = 1 ∑ L ( Z ℓ − ω ℓ ) ⊤ V − 1 ( Z ℓ − ω ℓ ) ⎭ ⎬ ⎫ . (8) In the same limit, the test error (4) converges in probability to
E = 1 2 E θ , Ξ [ ∑ ℓ = 1 L ( δ ℓ 1 − 1 H ∑ h = 1 H softmax ( Ω : h ) ℓ ) 2 ] . (9) \mathcal{E}=\frac{1}{2}\mathbb{E}_{\theta,\Xi}\left[\sum_{\ell=1}^{L}\left(\delta_{\ell1}-\frac{1}{H}\sum_{h=1}^{H}\operatorname{softmax}(\Omega:h)_\ell\right)^2\right]. \tag*{(9)} E = 2 1 E θ , Ξ ℓ = 1 ∑ L ( δ ℓ 1 − H 1 h = 1 ∑ H softmax ( Ω : h ) ℓ ) 2 . (9) Finally, the training error at the ERM minimizer converges in probability to
E t r a i n = E θ , Ξ [ M ( θ , Ξ ) ] − 1 2 α Tr ( q ^ V ) . (10) \mathcal{E}_{\mathrm{train}}=\mathbb{E}_{\theta,\Xi}\left[\mathcal{M}(\theta,\Xi)\right]-\frac{1}{2\alpha}\operatorname{Tr}(\widehat{q}V). \tag*{(10)} E train = E θ , Ξ [ M ( θ , Ξ ) ] − 2 α 1 Tr ( q V ) . (10) Result 3.1 provides a tight asymptotic characterization of the test error E \mathcal{E} E (9) and the training error E t r a i n \mathcal{E}_{\mathrm{train}} E train (10) as a function of finite-dimensional summary statistics { m , q , V } \{m,q,V\} { m , q , V } characterized in closed form by the set of equations (6-7), providing a finite-dimensional description of the high dimensional learning problem (3) . Solutions of the self-consistent equations (6-7) asymptotically describes the global minimum of (3) as well as saddles and local minima. Multiple solutions can coexist and describe competing minima of the training loss. Thus, changing the control parameters such as sample complexity can change the stability of minima or selection of the global minimum, and produce phase transitions.
The derivation of Result 3.1, detailed in App. § 11 .§ 1 , relies on the replica method under a replica-symmetric (RS) ansatz. While replica-symmetric predictions have been rigorously established for convex ERM problems (see, e.g., Aubin et al. [3 ] ) and under specific conditions for non-convex ones (Vilucchio et al., [33 ] ), their validity in our non-convex setting remains an assumption. The resulting characterization is supported by numerical experiments: in the regimes studied, training the attention layer (2) on the ERM objective (3) by gradient-based optimization from random initializations (App. § 15 ) yields solutions whose summary statistics, training error and test error agree with those of the predicted global minima. Finally, we mention that while Result 3.1 is presented specifically with softmax activation of the training loss for clarity, similar results can be reached for generic activation function.
Head-specialization phase transition
Phases and phase transitions. We characterize the phase transitions that emerge in the high-dimensional limit, through the non-analyticities of the order parameters and the test error in the sample complexity. The empirical risk (3) is invariant under permutation of the heads, while the self-consistent equations (6-7) additionally inherit the symmetries of the data distribution. We call a phase specialized when the heads have distinct overlaps with the planted features, and unspecialized otherwise. At finite sample complexity, however, head weights can grow and correlate while being orthogonal to the planted features, allowing for the existence of an unspecialized phase breaking head-permutation symmetry in the self-overlap q q q .
For the flipping-spike model with H = 2 H = 2 H = 2 , F = 2 F = 2 F = 2 , the data distribution is invariant under sign reversal of the second feature. We distinguish the permutation symmetric (PS), permutation-symmetry-broken (PSB), and specialized (SPEC) phases using the head-feature overlap m m m and antisymmetric self-overlap q ⊥ ≡ ( q 11 + q 22 − 2 q 12 ) / 2 q_\perp\equiv(q_{11} + q_{22} - 2q_{12})/2 q ⊥ ≡ ( q 11 + q 22 − 2 q 12 ) /2 , which measures the squared distance between the attention-head vectors. The three phases satisfy
P S : m 11 = m 21 > 0 , m 12 = m 22 = 0 , q ⊥ = 0 , P S B : m 11 = m 21 > 0 , m 12 = m 22 = 0 , q ⊥ > 0 , S P E C : m 11 = m 21 > 0 , m 12 = − m 22 ≠ 0 , q ⊥ > 0. (11) \begin{aligned}
\mathrm{PS}:&\quad m_{11}=m_{21}>0,\quad m_{12}=m_{22}=0,\quad q_\perp=0,\\
\mathrm{PSB}:&\quad m_{11}=m_{21}>0,\quad m_{12}=m_{22}=0,\quad q_\perp>0,\\
\mathrm{SPEC}:&\quad m_{11}=m_{21}>0,\quad m_{12}=-m_{22}\ne0,\quad q_\perp>0. \tag*{(11)}
\end{aligned} PS : PSB : SPEC : m 11 = m 21 > 0 , m 12 = m 22 = 0 , q ⊥ = 0 , m 11 = m 21 > 0 , m 12 = m 22 = 0 , q ⊥ > 0 , m 11 = m 21 > 0 , m 12 = − m 22 = 0 , q ⊥ > 0. (11)
Thus, PSB distinguishes the heads without aligning their difference with the flipping feature, whereas SPEC develops opposite nonzero overlaps with this feature.
For the non-isotropic Gaussian model with distinct feature strengths ordered in decreasing order, the solutions studied below exhibit successive specialized phases (r r r -SPEC) indexed by r ∈ { 0 , … , min ( F , ⌊ H / 2 ⌋ ) } r \in\{0,\ldots,\min(F,\lfloor H/2\rfloor)\} r ∈ { 0 , … , min ( F , ⌊ H /2 ⌋)} and characterized by
r -SPEC : { ∥ m ⋅ f ∥ 2 > 0 , 1 ≤ f ≤ r , ∥ m ⋅ f ∥ 2 = 0 , r < f ≤ F . (12) r\text{-SPEC}:\quad
\begin{cases}
\lVert m_{\cdot f}\rVert_2>0, & 1\le f\le r,\\
\lVert m_{\cdot f}\rVert_2=0, & r<f\le F.
\end{cases} \tag*{(12)} r -SPEC : { ∥ m ⋅ f ∥ 2 > 0 , ∥ m ⋅ f ∥ 2 = 0 , 1 ≤ f ≤ r , r < f ≤ F . (12)
Here, r = 0 r=0 r = 0 corresponds to the unspecialized permutation symmetric solution. PSB phases can also occur at low regularization; for simplicity, we restrict their analysis to the flipping-spike model.
Head-specialization phase transition in the flipping spike model. We first turn to the flipping spike model defined in § 3 , where a constant latent direction is learnable without head specialization while a flipping direction requires specialized heads to be used in the retrieval task. At sufficiently large regularization λ ≥ λ t r i c \lambda\ge\lambda_{\mathrm{tric}} λ ≥ λ tric , where λ t r i c \lambda_{\mathrm{tric}} λ tric is the smallest regularization strength for which the PSB phase is absent, we find two solutions:
PS solution for α < α c s p e c ( λ ) \alpha< \alpha_c^{\mathrm{spec}}(\lambda) α < α c spec ( λ ) : both heads implement the same attention pattern, and generalization improves with sample complexity through recovery of the constant direction (∥ m ⋅ 1 ∥ 2 > 0 \lVert m_{\cdot1}\rVert_2 > 0 ∥ m ⋅ 1 ∥ 2 > 0 ), while the flipping feature remains unrecovered (∥ m ⋅ 2 ∥ 2 = 0 \lVert m_{\cdot2}\rVert_2 = 0 ∥ m ⋅ 2 ∥ 2 = 0 ).
SPEC solution for α > α c s p e c ( λ ) \alpha> \alpha_c^{\mathrm{spec}}(\lambda) α > α c spec ( λ ) : the heads implement distinct attention patterns, each adapted to one sign of the flipping feature (∥ m : 2 ∥ 2 > 0 \lVert m_{:2}\rVert_2 > 0 ∥ m : 2 ∥ 2 > 0 ). Recovery of this additional direction improves retrieval, with a gain in error depending on the relative signal strengths.
The multi-head attention model displays a phase transition in sample complexity from the PS solution to the SPEC solution at critical sample complexity α c s p e c \alpha_c^{\mathrm{spec}} α c spec . The transition is of second order, marked by non-analyticities in the overlaps and errors.
In Figure 2 , we compare different metrics for the lowest training loss solutions of the self-consistent equations as a function of sample complexity with the corresponding experimental results. Gradient based optimization on the ERM objective from random initializations reaches the predicted global minima, with errors and overlaps matching theoretical predictions. The transition is visible through the continuous splitting of the head-feature overlaps, the associated non-analyticity in the errors, and the onset of flipping-feature recovery at α c s p e c \alpha_c^{\mathrm{spec}} α c spec .
Figure 2. Head-specialization phase transition in the flipping spike model: ν 1 = 0.1 \nu_1 = 0.1 ν 1 = 0.1 , ν 2 = 2.0 \nu_2 = 2.0 ν 2 = 2.0 , L = 10 L = 10 L = 10 , H = 2 H = 2 H = 2 , λ = 0.2 \lambda= 0.2 λ = 0.2 , D = 2000 D = 2000 D = 2000 . Here and in Figure 3 and 4, black solid lines correspond to theoretical predictions (Res. 3.1). Markers with error bars correspond to training the model (§ 3 ) with L-BFGS from random initialization in dimension D D D across ten seeds. Left: Head-feature overlaps (m : 2 , m : 1 m_{:2},m_{:1} m : 2 , m : 1 ) parametrized by sample complexity. Grey arrows indicate the directions of the two possible draws of the planted spike k ^ \hat{k} k ^ . Center: Test error E \mathcal{E} E and training error E t r a i n \mathcal{E}_{\mathrm{train}} E train . Right: Norm of head-feature overlaps ∥ m : 1 ∥ 2 \lVert m_{:1}\rVert_2 ∥ m : 1 ∥ 2 , ∥ m : 2 ∥ 2 \lVert m_{:2}\rVert_2 ∥ m : 2 ∥ 2 . Grey and blue identify the permutation symmetric (PS) and specialized (SPEC) phases. Vertical lines mark the specialization threshold α c s p e c \alpha_c^{\mathrm{spec}} α c spec .
Low regularization strengths can favor fitting sample fluctuations without feature recovery. In the regime λ < λ t r i c \lambda< \lambda_{\mathrm{tric}} λ < λ tric , we find an additional solution to the asymptotic characterization:
When this solution becomes global, specialization in sample complexity is delayed, producing a re-entrant specialization phase boundary at low regularization. Figure 3 shows the resulting phase diagram and a low-regularization cut, where the PSB solution is visible in the head self-overlaps before the onset of flipping-feature recovery. A similar type of solution, noted "memorization", has been observed in the ERM of committee-machines ([23 ] ). Here we stress that, at low regularization, the validity of the RS ansatz requires particular scrutiny. In Figure 3 the validity of RS assumption in this regime is supported through agreement with simulations. In general, the possible need for a replica-symmetry-breaking (RSB) description needs to be investigated.
Figure 3. Head differentiation without specialization in the flipping spike model: ν 1 = 0.5 \nu_1 = 0.5 ν 1 = 0.5 , ν 2 = 2.0 \nu_2 = 2.0 ν 2 = 2.0 , L = 10 L = 10 L = 10 , H = 2 H = 2 H = 2 , D = 6000 D = 6000 D = 6000 . Left: Phase diagram in sample complexity α \alpha α and regularization λ \lambda λ . Phase boundaries are obtained by stability analysis of the different solutions (App. § 13 ). The red horizontal line at λ = 0.065 \lambda= 0.065 λ = 0.065 selects the cut shown in the other panels. Center: Head self-overlaps q 11 = q 22 q_{11} = q_{22} q 11 = q 22 and mutual overlaps q 12 = q 21 q_{12} = q_{21} q 12 = q 21 . Right: Head-feature overlaps m 12 m_{12} m 12 and m 22 m_{22} m 22 . Grey, orange and blue identify the permutation symmetric (PS), permutation symmetry broken (PSB) and specialized (SPEC) phases, respectively. Vertical lines mark their boundaries α c p s b \alpha_{\mathrm{c}}^{\mathrm{psb}} α c psb and α c s p e c \alpha_{\mathrm{c}}^{\mathrm{spec}} α c spec .
Head-specialization cascade and simplicity bias in the non-isotropic Gaussian model.
We now consider the non-isotropic Gaussian model, with zero-mean feature weights of strengths { ν f } f = 1 F \{\nu_f\}_{f=1}^{F} { ν f } f = 1 F . For F = 2 F = 2 F = 2 , we parameterize the latent structure by its total signal ν t o t \nu_{\mathrm{tot}} ν tot and anisotropy δ \delta δ :
ν t o t = ν 1 + ν 2 , δ = ν 1 − ν 2 ν 1 + ν 2 , (13) \nu_{\mathrm{tot}} = \nu_1 + \nu_2, \qquad\delta= \frac{\nu_1 - \nu_2}{\nu_1 + \nu_2}, \tag*{(13)} ν tot = ν 1 + ν 2 , δ = ν 1 + ν 2 ν 1 − ν 2 , (13)
where δ = 0 \delta= 0 δ = 0 corresponds to isotropic strengths and increasing δ \delta δ favors one latent direction. We take H = 2 F H = 2F H = 2 F , allowing one pair of heads per feature. At sufficiently large regularization we find:
r-SPEC solution for α c ( r ) < α < α c ( r + 1 ) \alpha_{\mathrm{c}}^{(r)} < \alpha< \alpha_{\mathrm{c}}^{(r+1)} α c ( r ) < α < α c ( r + 1 ) : the heads recover the r r r strongest latent features, from largest to smallest variance. Each additional specialization transition therefore recovers a weaker feature and incrementally improves retrieval.
Increasing sample complexity therefore produces a cascade of second-order specialization phase transitions at critical sample complexities { α c ( r ) } r = 1 F \{\alpha_{\mathrm{c}}^{(r)}\}_{r=1}^{F} { α c ( r ) } r = 1 F , marked by the recovery of successive latent features and associated non-analyticities in the errors. With stronger features recovered at lower sample complexity, this hierarchy constitutes a statistical form of simplicity bias in the global ERM solutions, independent of the training dynamics. In Figure 4 , the ( α , δ ) (\alpha,\delta) ( α , δ ) phase diagram illustrates this simplicity bias. At fixed anisotropy δ \delta δ , we compare the sample-complexity evolution of the errors and head-feature overlaps predicted by Result 3.1 with numerical experiments. Gradient-based optimization from random initialization reaches the predicted global minima, with errors and overlaps matching our theoretical predictions. The Bayes-optimal baseline in App. § 11 .§ 4 distinguishes the information-theoretic thresholds for feature recovery in the data model from the larger specialization thresholds of the attention estimator.
Figure 4. Head-specialization cascade in the non-isotropic Gaussian model: F = 2 F = 2 F = 2 , ν t o t = 9.0 \nu_{\mathrm{tot}} = 9.0 ν tot = 9.0 , L = 5 L = 5 L = 5 , H = 4 H = 4 H = 4 , λ = 0.2 \lambda= 0.2 λ = 0.2 , D = 4000 D = 4000 D = 4000 . Left: Phase diagram in sample complexity α \alpha α and anisotropy δ \delta δ . Phase boundaries are obtained by stability analysis of the different solutions (App. § 13 ). The red horizontal line at δ = 1 / 9 \delta= 1/9 δ = 1/9 corresponding to ( ν 1 , ν 2 ) = ( 5.0 , 4.0 ) (\nu_1,\nu_2) = (5.0, 4.0) ( ν 1 , ν 2 ) = ( 5.0 , 4.0 ) selects the cut shown in the other panels. Center: Test error E \mathcal{E} E and training error E t r a i n \mathcal{E}_{\mathrm{train}} E train . Right: Head-feature overlaps m h f m_{hf} m h f for all heads and both latent features. Grey, light blue and darker blue identify the permutation symmetric (PS) and successively specialized (1-SPEC, 2-SPEC) phases, respectively. Vertical dash-dotted lines mark the specialization thresholds α c ( 1 ) \alpha_c^{(1)} α c ( 1 ) and α c ( 2 ) \alpha_c^{(2)} α c ( 2 ) along the cut.
Link between statistical transitions and dynamical emergence
We now connect the phase transitions in sample complexity to specialization during online learning. We consider the non-isotropic Gaussian model where ( m , q ) = ( 0 , 0 ) (m,q) = (0,0) ( m , q ) = ( 0 , 0 ) is a saddle point of the loss, and focus on the first specialization, assumed to occur only along k 1 ∗ k_1^* k 1 ∗ . In the right limits, we show that the sample complexity and the time for specialization are governed by the largest curvature C ∈ R + C \in\mathbb{R}^{+} C ∈ R + of minus the population loss E p o p \mathcal{E}_{\mathrm{pop}} E pop along this feature, defined as:
C = λ max [ − k 1 ∗ ( ∇ K , K 2 E p o p ( 0 ) ) k 1 ∗ ] , E p o p ( K ) = E X , y [ 1 2 D ∥ y − f K ( X ) ∥ 2 2 ] , (14) C = \lambda_{\max}\left[-k_1^{*} \left(\nabla^2_{K,K}\mathcal{E}_{\mathrm{pop}}(0)\right) k_1^{*}\right], \qquad\mathcal{E}_{\mathrm{pop}}(K) = \mathbb{E}_{X,y}\left[\frac{1}{2D}\left\lVert y-f_K(X)\right\rVert_2^2\right], \tag*{(14)} C = λ m a x [ − k 1 ∗ ( ∇ K , K 2 E pop ( 0 ) ) k 1 ∗ ] , E pop ( K ) = E X , y [ 2 D 1 ∥ y − f K ( X ) ∥ 2 2 ] , (14)
where λ max [ ⋅ ] \lambda_{\max}[\cdot] λ m a x [ ⋅ ] denotes the largest eigenvalue and ∇ K , K 2 \nabla^2_{K,K} ∇ K , K 2 denotes the Hessian.
To describe the dynamics, we consider the gradient-flow limit of unregularized online SGD,
d K d τ = − D ∇ K E p o p ( K ) (15) \frac{\mathrm{d}K}{\mathrm{d}\tau} = -D\nabla_K\mathcal{E}_{\mathrm{pop}}(K) \tag*{(15)} d τ d K = − D ∇ K E pop ( K ) (15)
with independent initial weights k h ( τ = 0 ) ∼ N ( 0 , η 2 I D ) k_h(\tau= 0) \sim\mathcal{N}(0,\eta^2\mathbb{I}_D) k h ( τ = 0 ) ∼ N ( 0 , η 2 I D ) . We take the limit of vanishing initialization η → 0 \eta\to0 η → 0 after D → ∞ D \to\infty D → ∞ , often referred to as the feature-learning limit (e.g. Wu et al. (2025)). Sagitova et al. [26 ] derives closed evolution equations for the order parameters and shows that specialization is governed by an exponential escape from the saddle of the head-feature overlap m m m . A self-contained derivation is provided in App. § 14 .§ 1 . We compare these dynamics with ERM (Res. 3.1) in the limit of large regularization λ \lambda λ , α ≫ 1 \alpha\gg1 α ≫ 1 with α / λ = Θ ( 1 ) \alpha/\lambda= \Theta(1) α / λ = Θ ( 1 ) , in which the ERM landscape is well approximated by the population loss. A linear stability analysis (App. § 14 .§ 3 ) then relates the critical sample complexity to the specialization time through the Hessian ((14) ). Defining τ s p e c \tau^{\mathrm{spec}} τ spec as the first time at which the specializing component reaches a fixed small amplitude ∥ m 1 ∥ > ε \lVert m_1\rVert> \varepsilon ∥ m 1 ∥ > ε , for small enough ε > 0 \varepsilon> 0 ε > 0 independent of D D D and η \eta η , we obtain:
lim η → 0 + lim D → ∞ τ s p e c log ( D / η ) = lim λ → ∞ α c s p e c λ = 1 C . (16) \lim_{\eta\to0^+}\lim_{D\to\infty}\frac{\tau^{\mathrm{spec}}}{\log(\sqrt{D}/\eta)} = \lim_{\lambda\to\infty}\frac{\alpha_c^{\mathrm{spec}}}{\lambda} = \frac{1}{C}. \tag*{(16)} η → 0 + lim D → ∞ lim log ( D / η ) τ spec = λ → ∞ lim λ α c spec = C 1 . (16)
In the considered limits the rescaled static and dynamical specialization transitions are governed by the same instability. The rescaled time is asymptotically deterministic and independent of the initialization and of ε \varepsilon ε . As in online learning training, time and number of observed sequences increase together, this correspondence illustrates how a statistical phase transition can manifest itself dynamically through sudden drops in the loss at critical training times.
Discussion and conclusion
The theoretical picture developed in this work suggests that abrupt and stagewise changes observed during training of multi-head attention layers can be dynamical manifestations of underlying statistical phase transitions. Solvable models make this perspective precise by identifying a limit in which specialization phase transitions are well defined, with sample complexity as a control parameter for studying the minima of the ERM objective. In our setting, this description distinguishes the statistical origins of specialization, encoded in the structure of the ERM loss landscape, from its dynamical origins. This theoretical perspective helps to clarify a possible statistical interpretation of the drops in loss that accompany abrupt changes in capabilities during the training of language models.
MLM experiments with BERT models provide strong empirical support for this statistical interpretation. Syntactic attention structure associated with head specialization emerges sharply with increasing dataset sizes, coherently with the already observed drops in the loss in training time, as suggested by the connections between ERM and online learning. While, by nature, finite-dimensional experiments do not by themselves establish the asymptotic non-analyticities that define phase transitions, these observations parallel the specialization phenomenology of the solvable model and strongly suggest a statistical phase transition interpretation of the emergence of specialized heads and SAS in BERT. For head specialization, sample complexity appears as the principled choice of control parameter to study these phase transitions. More generally, other capability changes could also have purely dynamical origins and not have a corresponding statistical characterization.
Our results motivate further experiments to characterize specialization transitions yet more systematically. For example, the enhanced variability across seeds near the emergence of SAS observed in Figure 1 suggests that fluctuations could help locate candidate transitions in sample complexity. This approach is motivated by the diverging sensitivity of macroscopic observables to perturbations near second-order phase transitions, a familiar phenomenon in physics. Related considerations about variability across runs are beginning to be explored in mechanistic interpretability [17 , 40 ] . A further test of the sample-complexity interpretation would extend our BERT experiments by varying training procedures with regularized objective and training controlled to convergence. For protocols reaching comparable ERM minima, one could examine whether SAS emerges at the same characteristic dataset size. Repeating this comparison across model sizes could help identify an effective scaling of sample complexity, while extending the analysis to individual syntactic relations could reveal distinct thresholds for the emergence of statistically more complex capabilities.
Reproducibility statement
A complete derivation of all the claims is included in the appendix with references provided in the main text. All the results can be reproduced using the code provided in the repository: https://github.com/SPUC-group/Attention-head-specialization . For the experimental setup, details are provided in App. § 15 .
Acknowledgments
We thank Margarita Sagitova for discussions and insights on the multi-feature spiked single-location regression model from Sagitova et al. [26 ] . We thank Pierre Marion and Naomi Saphra for insightful discussions. We acknowledge funding from the Swiss National Science Foundation grants SNSF SMArtNet (grant number 212049), the Simons Collaboration on the Physics of Learning and Neural Computation via the Simons Foundation grant (#1257413 (LZ)), and the Swiss State Secretariat for Education, Research and Innovation (SERI), which funded the ERC Advanced Grant SPASM-net.
AI use statement
In this work, we used generative AI tools to help formulate mathematical claims, implement numerical methods, and polish writing. We have reviewed all AI-assisted work. We used LLMs to sketch extensions of our hand-derived linear stability analysis to other solutions and to adapt the associated numerical implementations for the evaluation of critical sample complexity. We also used LLMs to help implement and reproduce a previously designed experiment using a reference paper’s repository. Finally, we used LLMs for language editing (grammar, spelling). We take responsibility for the final content of this work, including text, claims or artifacts produced with the aid of generative AI.
Derivations for the exact characterization of the ERM
Derivation of result 3.1 with the replica method
This appendix provides a derivation of result 3.1 based on the replica method of the statistical physics of disordered systems. The derivation is standard and closely related to Duranthon et al. [13 ] .
Setting and notation
Recall that our goal is to characterize the minimizers of the regularized empirical risk (3) for the multi-head attention estimator (2) in the high-dimensional setting of § 3 . We take N , D → ∞ N,D \to\infty N , D → ∞ at fixed α = N / D \alpha=N/D α = N / D , H H H , F F F , and L L L , such that D − 1 K ∗ K ∗ ⊤ → I F D^{-1}K^{*}K^{*\top} \to I_F D − 1 K ∗ K ∗ ⊤ → I F . Let K ^ \hat{K} K ^ be the minimizer of the empirical risk:
L ( K ) = ∑ μ = 1 N ℓ ( y μ , f K ( X μ ) ) + λ 2 ∥ K ∥ F 2 , ℓ ( y , y ^ ) = 1 2 D ∥ y − y ^ ∥ 2 , (17) \mathcal{L}(K)=\sum_{\mu=1}^{N}\ell(y_\mu,f_K(X^\mu))+\frac{\lambda}{2}\lVert K\rVert_F^2,\qquad\ell(y,\hat{y})=\frac{1}{2D}\lVert y-\hat{y}\rVert^2, \tag*{(17)} L ( K ) = μ = 1 ∑ N ℓ ( y μ , f K ( X μ )) + 2 λ ∥ K ∥ F 2 , ℓ ( y , y ^ ) = 2 D 1 ∥ y − y ^ ∥ 2 , (17)
where f K f_K f K is the estimator (2) , and we assume λ > 0 \lambda>0 λ > 0 . Both error and regularization contributions to the loss are extensive; we define the unregularized training error associated with K ^ \hat{K} K ^
E t r a i n = 1 N ∑ μ = 1 N ℓ ( y μ , f K ^ ( X μ ) ) . (18) \mathcal{E}_{\mathrm{train}}=\frac{1}{N}\sum_{\mu=1}^{N}\ell(y^\mu,f_{\hat{K}}(X^\mu)). \tag*{(18)} E train = N 1 μ = 1 ∑ N ℓ ( y μ , f K ^ ( X μ )) . (18)
We first derive the results for generic feature weights distribution P θ P_\theta P θ , and later evaluate the remaining feature average for the flipping spike and non isotropic Gaussian models. We also consider generic activation function σ : R L → R L \sigma:\mathbb{R}^{L}\to\mathbb{R}^{L} σ : R L → R L , and specialize to softmax at the end of the derivation.
To begin with, we define the Gibbs measure d μ β d\mu_\beta d μ β over weights K ∈ R H × D K\in\mathbb{R}^{H\times D} K ∈ R H × D , and recall that for any observable ϕ ( K ^ ) \phi(\hat{K}) ϕ ( K ^ ) of the minimizer K ^ \hat{K} K ^ of (3) ,
E D [ ϕ ( K ^ ) ] = lim β → ∞ E D [ ∫ ϕ ( K ) d μ β ] , d μ β = 1 Z β e − β L ( K ) d K , (19) \mathbb{E}_D[\phi(\hat{K})]=\lim_{\beta\to\infty}\mathbb{E}_D\left[\int\phi(K)d\mu_\beta\right],\qquad d\mu_\beta=\frac{1}{Z_\beta}e^{-\beta\mathcal{L}(K)}dK, \tag*{(19)} E D [ ϕ ( K ^ )] = β → ∞ lim E D [ ∫ ϕ ( K ) d μ β ] , d μ β = Z β 1 e − β L ( K ) d K , (19)
where Z β Z_\beta Z β is the normalization factor also known as partition function in statistical physics:
Z β = ∫ d K e − β L ( K ) . (20) Z_\beta=\int dK\,e^{-\beta\mathcal{L}(K)}. \tag*{(20)} Z β = ∫ d K e − β L ( K ) . (20)
The goal of the replica method is to compute the generating function associated to the Gibbs measure (19) , the free entropy density
Φ β = lim D → ∞ 1 D E D [ log Z β ] , (21) \Phi_\beta=\lim_{D\to\infty}\frac{1}{D}\mathbb{E}_D[\log Z_\beta], \tag*{(21)} Φ β = D → ∞ lim D 1 E D [ log Z β ] , (21)
building on the identity
E D [ log Z β ] = lim n → 0 E D [ Z β n ] − 1 n . (22) \mathbb{E}_D[\log Z_\beta]=\lim_{n\to0}\frac{\mathbb{E}_D[Z_\beta^n]-1}{n}. \tag*{(22)} E D [ log Z β ] = n → 0 lim n E D [ Z β n ] − 1 . (22)
Therefore, the whole problem reduces to computing the average replicated partition function:
E D [ Z β n ] = E D [ ∫ ∏ a = 1 n d K a e − β ∑ a = 1 n [ ∑ μ = 1 N ℓ ( y μ , f K a ( X μ ) ) + λ 2 ∥ K a ∥ F 2 ] ] . (23) \mathbb{E}_D[Z_\beta^n]=\mathbb{E}_D\left[\int\prod_{a=1}^{n}dK^a\,e^{-\beta\sum_{a=1}^{n}\left[\sum_{\mu=1}^{N}\ell(y_\mu,f_{K^a}(X^\mu))+\frac{\lambda}{2}\lVert K^a\rVert_F^2\right]}\right]. \tag*{(23)} E D [ Z β n ] = E D [ ∫ a = 1 ∏ n d K a e − β ∑ a = 1 n [ ∑ μ = 1 N ℓ ( y μ , f K a ( X μ )) + 2 λ ∥ K a ∥ F 2 ] ] . (23)
Replicated partition function
With explicit dataset definitions, the partition function reads
E D [ Z β n ] = ∫ d P K ∗ ∏ a = 1 n d K a e − β λ 2 ∑ a = 1 n ∥ K a ∥ F 2 ∏ μ = 1 N E ϵ μ , θ μ , X μ , y μ ∣ K ∗ [ e − β ∑ a = 1 n ℓ ( y μ , f K a ( X μ ) ) ] . (24) \mathbb{E}_{D}\left[\mathcal{Z}_{\beta}^{n}\right]=\int dP_{K^{*}}\prod_{a=1}^{n}dK^{a}e^{-\frac{\beta\lambda}{2}\sum_{a=1}^{n}\lVert K^{a}\rVert_{F}^{2}}\prod_{\mu=1}^{N}\mathbb{E}_{\epsilon_{\mu},\theta_{\mu},X_{\mu},y_{\mu}\mid K^{*}}\left[e^{-\beta\sum_{a=1}^{n}\ell\left(y_{\mu},f_{K^{a}}(X_{\mu})\right)}\right]. \tag*{(24)} E D [ Z β n ] = ∫ d P K ∗ a = 1 ∏ n d K a e − 2 β λ ∑ a = 1 n ∥ K a ∥ F 2 μ = 1 ∏ N E ϵ μ , θ μ , X μ , y μ ∣ K ∗ [ e − β ∑ a = 1 n ℓ ( y μ , f K a ( X μ ) ) ] . (24)
We introduce the local fields
Z μ a = X μ K a ⊤ D ∈ R L × H , Z μ ∗ = X μ K ∗ ⊤ D ∈ R L × F , (25) Z_{\mu}^{a}=\frac{X_{\mu}K^{a\top}}{\sqrt{D}}\in\mathbb{R}^{L\times H},\qquad Z_{\mu}^{*}=\frac{X_{\mu}K^{*\top}}{\sqrt{D}}\in\mathbb{R}^{L\times F}, \tag*{(25)} Z μ a = D X μ K a ⊤ ∈ R L × H , Z μ ∗ = D X μ K ∗ ⊤ ∈ R L × F , (25)
following jointly Gaussian statistics with means
E X [ Z ℓ a ] = δ ℓ ϵ m a θ , E X [ Z ℓ ∗ ] = δ ℓ ϵ θ , (26) \mathbb{E}_{X}\left[Z_{\ell}^{a}\right]=\delta_{\ell\epsilon}m^{a}\theta,\qquad\mathbb{E}_{X}\left[Z_{\ell}^{*}\right]=\delta_{\ell\epsilon}\theta, \tag*{(26)} E X [ Z ℓ a ] = δ ℓ ϵ m a θ , E X [ Z ℓ ∗ ] = δ ℓ ϵ θ , (26)
and covariances
Cov ( Z ℓ a , Z ℓ ′ b ⊤ ) = δ ℓ ℓ ′ K a K b ⊤ D , Cov ( Z ℓ a , Z ℓ ′ ∗ ⊤ ) = δ ℓ ℓ ′ K a K ∗ ⊤ D , Cov ( Z ℓ ∗ , Z ℓ ′ ∗ ⊤ ) = δ ℓ ℓ ′ I F . (27) \operatorname{Cov}\left(Z_{\ell}^{a},Z_{\ell'}^{b\top}\right)=\delta_{\ell\ell'}\frac{K^{a}K^{b\top}}{D},\qquad\operatorname{Cov}\left(Z_{\ell}^{a},Z_{\ell'}^{*\top}\right)=\delta_{\ell\ell'}\frac{K^{a}K^{*\top}}{D},\qquad\operatorname{Cov}\left(Z_{\ell}^{*},Z_{\ell'}^{*\top}\right)=\delta_{\ell\ell'}I_{F}. \tag*{(27)} Cov ( Z ℓ a , Z ℓ ′ b ⊤ ) = δ ℓ ℓ ′ D K a K b ⊤ , Cov ( Z ℓ a , Z ℓ ′ ∗ ⊤ ) = δ ℓ ℓ ′ D K a K ∗ ⊤ , Cov ( Z ℓ ∗ , Z ℓ ′ ∗ ⊤ ) = δ ℓ ℓ ′ I F . (27)
Expanding the squared loss then yields the reparametrization
ℓ ( y μ , f K a ( X μ ) ) → ℓ ( ϵ μ , Z μ a ) : = 1 2 ∑ ℓ = 1 L ( δ ℓ ϵ μ − 1 H ∑ h = 1 H σ ( Z μ ; h ℓ a ) ) 2 , (28) \ell\left(y_{\mu},f_{K^{a}}(X_{\mu})\right)\to\ell\left(\epsilon_{\mu},Z_{\mu}^{a}\right):=\frac{1}{2}\sum_{\ell=1}^{L}\left(\delta_{\ell\epsilon_{\mu}}-\frac{1}{H}\sum_{h=1}^{H}\sigma\left(Z_{\mu;h\ell}^{a}\right)\right)^{2}, \tag*{(28)} ℓ ( y μ , f K a ( X μ ) ) → ℓ ( ϵ μ , Z μ a ) := 2 1 ℓ = 1 ∑ L ( δ ℓ ϵ μ − H 1 h = 1 ∑ H σ ( Z μ ; h ℓ a ) ) 2 , (28)
where we used the fact that X ℓ ⊤ X ℓ ′ / D → δ ℓ ℓ ′ X_{\ell}^{\top}X_{\ell'}/D\to\delta_{\ell\ell'} X ℓ ⊤ X ℓ ′ / D → δ ℓ ℓ ′ in the considered limit. Enforcing the definitions of local fields with Dirac deltas in the replicated partition function gives
E D [ Z β n ] ∝ ∫ d P K ∗ ∏ a = 1 n d K a e − β λ 2 ∑ a = 1 n ∥ K a ∥ F 2 × ∏ μ = 1 N d Z μ ∗ d Z ^ μ ∗ ∏ a = 1 n d Z μ a d Z ^ μ a E ϵ μ , θ μ { e − β ∑ a = 1 n ℓ ( ϵ μ , Z μ a ) × E X μ ∣ ϵ μ , θ μ , K ∗ [ e i ∑ ℓ = 1 L Z ^ μ , ℓ ∗ ⊤ ( Z μ , ℓ ∗ − K ∗ X μ , ℓ D ) + i ∑ ℓ = 1 L ∑ a = 1 n Z ^ μ , ℓ a ⊤ ( Z μ , ℓ a − K a X μ , ℓ D ) ] } . (29) \begin{aligned}
\mathbb{E}_{D}\left[\mathcal{Z}_{\beta}^{n}\right]\propto{}&\int dP_{K^{*}}\prod_{a=1}^{n}dK^{a}e^{-\frac{\beta\lambda}{2}\sum_{a=1}^{n}\lVert K^{a}\rVert_{F}^{2}}\\
&\times\prod_{\mu=1}^{N}dZ_{\mu}^{*}d\widehat{Z}_{\mu}^{*}\prod_{a=1}^{n}dZ_{\mu}^{a}d\widehat{Z}_{\mu}^{a}\,\mathbb{E}_{\epsilon_{\mu},\theta_{\mu}}\left\{e^{-\beta\sum_{a=1}^{n}\ell(\epsilon_{\mu},Z_{\mu}^{a})}\right.\\
&\left.\qquad\times\mathbb{E}_{X_{\mu}\mid\epsilon_{\mu},\theta_{\mu},K^{*}}\left[e^{i\sum_{\ell=1}^{L}\widehat{Z}_{\mu,\ell}^{*\top}\left(Z_{\mu,\ell}^{*}-\frac{K^{*}X_{\mu,\ell}}{\sqrt{D}}\right)+i\sum_{\ell=1}^{L}\sum_{a=1}^{n}\widehat{Z}_{\mu,\ell}^{a\top}\left(Z_{\mu,\ell}^{a}-\frac{K^{a}X_{\mu,\ell}}{\sqrt{D}}\right)}\right]\right\}. \tag*{(29)}
\end{aligned} E D [ Z β n ] ∝ ∫ d P K ∗ a = 1 ∏ n d K a e − 2 β λ ∑ a = 1 n ∥ K a ∥ F 2 × μ = 1 ∏ N d Z μ ∗ d Z μ ∗ a = 1 ∏ n d Z μ a d Z μ a E ϵ μ , θ μ { e − β ∑ a = 1 n ℓ ( ϵ μ , Z μ a ) × E X μ ∣ ϵ μ , θ μ , K ∗ [ e i ∑ ℓ = 1 L Z μ , ℓ ∗ ⊤ ( Z μ , ℓ ∗ − D K ∗ X μ , ℓ ) + i ∑ ℓ = 1 L ∑ a = 1 n Z μ , ℓ a ⊤ ( Z μ , ℓ a − D K a X μ , ℓ ) ] } . (29)
∝ ∫ d P K ∗ ∏ a = 1 n d K a e − β λ 2 ∑ a = 1 n ∥ K a ∥ F 2 × ∏ μ = 1 N d Z μ ∗ d Z ^ μ ∗ ∏ a = 1 n d Z μ a d Z ^ μ a E ϵ μ , θ μ { e − β ∑ a = 1 n ℓ ( ϵ μ , Z μ a ) + θ ⊤ Z μ , ϵ μ ∗ − 1 2 θ ⊤ θ μ × E X μ ∼ N ( 0 , I D ) [ e i ∑ ℓ = 1 L Z ^ μ , ℓ ∗ ⊤ ( Z μ , ℓ ∗ − K ∗ X μ , ℓ D ) + i ∑ ℓ = 1 L ∑ a = 1 n Z ^ μ , ℓ a ⊤ ( Z μ , ℓ a − K a X μ , ℓ D ) ] } . (30) \begin{aligned}
\propto{}&\int dP_{K^{*}}\prod_{a=1}^{n}dK^{a}e^{-\frac{\beta\lambda}{2}\sum_{a=1}^{n}\lVert K^{a}\rVert_{F}^{2}}\\
&\times\prod_{\mu=1}^{N}dZ_{\mu}^{*}d\widehat{Z}_{\mu}^{*}\prod_{a=1}^{n}dZ_{\mu}^{a}d\widehat{Z}_{\mu}^{a}\,\mathbb{E}_{\epsilon_{\mu},\theta_{\mu}}\left\{e^{-\beta\sum_{a=1}^{n}\ell(\epsilon_{\mu},Z_{\mu}^{a})+\theta^{\top}Z_{\mu,\epsilon_{\mu}}^{*}-\frac{1}{2}\theta^{\top}\theta_{\mu}}\right.\\
&\left.\qquad\times\mathbb{E}_{X_{\mu}\sim\mathcal{N}(0,I_{D})}\left[e^{i\sum_{\ell=1}^{L}\widehat{Z}_{\mu,\ell}^{*\top}\left(Z_{\mu,\ell}^{*}-\frac{K^{*}X_{\mu,\ell}}{\sqrt{D}}\right)+i\sum_{\ell=1}^{L}\sum_{a=1}^{n}\widehat{Z}_{\mu,\ell}^{a\top}\left(Z_{\mu,\ell}^{a}-\frac{K^{a}X_{\mu,\ell}}{\sqrt{D}}\right)}\right]\right\}. \tag*{(30)}
\end{aligned} ∝ ∫ d P K ∗ a = 1 ∏ n d K a e − 2 β λ ∑ a = 1 n ∥ K a ∥ F 2 × μ = 1 ∏ N d Z μ ∗ d Z μ ∗ a = 1 ∏ n d Z μ a d Z μ a E ϵ μ , θ μ { e − β ∑ a = 1 n ℓ ( ϵ μ , Z μ a ) + θ ⊤ Z μ , ϵ μ ∗ − 2 1 θ ⊤ θ μ × E X μ ∼ N ( 0 , I D ) [ e i ∑ ℓ = 1 L Z μ , ℓ ∗ ⊤ ( Z μ , ℓ ∗ − D K ∗ X μ , ℓ ) + i ∑ ℓ = 1 L ∑ a = 1 n Z μ , ℓ a ⊤ ( Z μ , ℓ a − D K a X μ , ℓ ) ] } . (30)
∝ ∫ d P K ∗ ∏ a = 1 n d K a e − β λ 2 ∑ a = 1 n ∥ K a ∥ F 2 ∏ μ = 1 N d Z μ ∗ ∏ a = 1 n d Z μ a × E ϵ μ , θ μ { e − β ∑ a = 1 n ℓ ( ϵ μ , Z μ a ) + θ ⊤ Z μ , ϵ μ ∗ − 1 2 θ ⊤ θ μ ∏ ℓ = 1 L N ( ( Z μ , ℓ ∗ Z μ , ℓ a ) ; 0 , ( I F m ⊤ m Q ) ) } . (31) \begin{aligned}
\propto{}&\int dP_{K^{*}}\prod_{a=1}^{n}dK^{a}e^{-\frac{\beta\lambda}{2}\sum_{a=1}^{n}\lVert K^{a}\rVert_{F}^{2}}\prod_{\mu=1}^{N}dZ_{\mu}^{*}\prod_{a=1}^{n}dZ_{\mu}^{a}\\
&\times\mathbb{E}_{\epsilon_{\mu},\theta_{\mu}}\left\{e^{-\beta\sum_{a=1}^{n}\ell(\epsilon_{\mu},Z_{\mu}^{a})+\theta^{\top}Z_{\mu,\epsilon_{\mu}}^{*}-\frac{1}{2}\theta^{\top}\theta_{\mu}}\prod_{\ell=1}^{L}\mathcal{N}\left(\begin{pmatrix}Z_{\mu,\ell}^{*}\\ Z_{\mu,\ell}^{a}\end{pmatrix};0,\begin{pmatrix}I_{F}&m^{\top}\\m&Q\end{pmatrix}\right)\right\}. \tag*{(31)}
\end{aligned} ∝ ∫ d P K ∗ a = 1 ∏ n d K a e − 2 β λ ∑ a = 1 n ∥ K a ∥ F 2 μ = 1 ∏ N d Z μ ∗ a = 1 ∏ n d Z μ a × E ϵ μ , θ μ { e − β ∑ a = 1 n ℓ ( ϵ μ , Z μ a ) + θ ⊤ Z μ , ϵ μ ∗ − 2 1 θ ⊤ θ μ ℓ = 1 ∏ L N ( ( Z μ , ℓ ∗ Z μ , ℓ a ) ; 0 , ( I F m m ⊤ Q ) ) } . (31)
where we introduced the summary statistics
m a = K a K ∗ ⊤ D ∈ R H × F , Q a b = K a K b ⊤ D ∈ R H × H . (32) m^{a}=\frac{K^{a}K^{*\top}}{D}\in\mathbb{R}^{H\times F},\qquad Q^{ab}=\frac{K^{a}K^{b\top}}{D}\in\mathbb{R}^{H\times H}. \tag*{(32)} m a = D K a K ∗ ⊤ ∈ R H × F , Q ab = D K a K b ⊤ ∈ R H × H . (32)
with Z μ , ℓ = { Z μ , ℓ a } a = 1 n Z_{\mu,\ell}=\{Z_{\mu,\ell}^{a}\}_{a=1}^{n} Z μ , ℓ = { Z μ , ℓ a } a = 1 n , m = { m a } a = 1 n m=\{m^{a}\}_{a=1}^{n} m = { m a } a = 1 n , Q = { Q a b } a , b = 1 n Q=\{Q^{ab}\}_{a,b=1}^{n} Q = { Q ab } a , b = 1 n . Enforcing the definitions of m a m^{a} m a and Q a b Q^{ab} Q ab with Dirac functions brings the replicated partition function in the following form:
E D [ Z β n ] ∝ ∫ ∏ a = 1 n d m a d m ^ a ∏ a , b = 1 n d Q a b d Q ^ a b e − D ∑ a = 1 n Tr ( m ^ a T m a ) + D 2 ∑ a , b = 1 n Tr ( Q ^ a b T Q a b ) \mathbb{E}_{D}\left[Z_{\beta}^{n}\right]\propto\int\prod_{a=1}^{n}dm^{a}d\hat{m}^{a}\prod_{a,b=1}^{n}dQ^{ab}d\hat{Q}^{ab}\,e^{-D\sum_{a=1}^{n}\operatorname{Tr}(\hat{m}^{a\mathsf{T}}m^{a})+\frac{D}{2}\sum_{a,b=1}^{n}\operatorname{Tr}(\hat{Q}^{ab\mathsf{T}}Q^{ab})} E D [ Z β n ] ∝ ∫ a = 1 ∏ n d m a d m ^ a a , b = 1 ∏ n d Q ab d Q ^ ab e − D ∑ a = 1 n Tr ( m ^ a T m a ) + 2 D ∑ a , b = 1 n Tr ( Q ^ ab T Q ab )
× ∫ d P K ∗ ∏ a = 1 n d K a e − β λ 2 ∑ a = 1 n ∥ K a ∥ F 2 + ∑ a = 1 n Tr ( m ^ a T K a K ∗ T ) − 1 2 ∑ a , b = 1 n Tr ( Q ^ a b T K b K a T ) \qquad\times\int dP_{K^{*}}\prod_{a=1}^{n}dK^{a}e^{-\frac{\beta\lambda}{2}\sum_{a=1}^{n}\lVert K^{a}\rVert_{F}^{2}+\sum_{a=1}^{n}\operatorname{Tr}(\hat{m}^{a\mathsf{T}}K^{a}K^{*\mathsf{T}})-\frac{1}{2}\sum_{a,b=1}^{n}\operatorname{Tr}(\hat{Q}^{ab\mathsf{T}}K^{b}K^{a\mathsf{T}})} × ∫ d P K ∗ a = 1 ∏ n d K a e − 2 β λ ∑ a = 1 n ∥ K a ∥ F 2 + ∑ a = 1 n Tr ( m ^ a T K a K ∗ T ) − 2 1 ∑ a , b = 1 n Tr ( Q ^ ab T K b K a T )
× E ϵ , θ { E Z ∗ , { Z a } a = 1 n [ e − β ∑ a = 1 n ℓ ( ϵ , Z a ) + θ T Z ϵ ∗ − 1 2 θ T θ ] } α D . (33) \qquad\times\mathbb{E}_{\epsilon,\theta}\left\{\mathbb{E}_{Z^{*},\{Z^{a}\}_{a=1}^{n}}\left[e^{-\beta\sum_{a=1}^{n}\ell(\epsilon,Z^{a})+\theta^{\mathsf{T}}Z_{\epsilon}^{*}-\frac{1}{2}\theta^{\mathsf{T}}\theta}\right]\right\}^{\alpha D}. \tag*{(33)} × E ϵ , θ { E Z ∗ , { Z a } a = 1 n [ e − β ∑ a = 1 n ℓ ( ϵ , Z a ) + θ T Z ϵ ∗ − 2 1 θ T θ ] } α D . (33)
We decomposed the replicated free entropy into the trace Ψ t \Psi_{t} Ψ t , entropic Ψ K \Psi_{K} Ψ K and energetic Ψ y \Psi_{y} Ψ y potentials. In the high-dimensional limit where D → ∞ D\to\infty D → ∞ while α = N / D \alpha=N/D α = N / D stay finite, the integral (33) , written explicitly as
E D [ Z β n ] ∝ ∫ ∏ a = 1 n d m a d m ^ a ∏ a , b = 1 n d Q a b d Q ^ a b e D Φ β ( n ) ( m a , m ^ a , Q a b , Q ^ a b ) , (34) \mathbb{E}_{D}\left[Z_{\beta}^{n}\right]\propto\int\prod_{a=1}^{n}dm^{a}d\hat{m}^{a}\prod_{a,b=1}^{n}dQ^{ab}d\hat{Q}^{ab}e^{D\Phi_{\beta}^{(n)}(m^{a},\hat{m}^{a},Q^{ab},\hat{Q}^{ab})}, \tag*{(34)} E D [ Z β n ] ∝ ∫ a = 1 ∏ n d m a d m ^ a a , b = 1 ∏ n d Q ab d Q ^ ab e D Φ β ( n ) ( m a , m ^ a , Q ab , Q ^ ab ) , (34)
concentrate around the values of the overlaps that extremize the finite temperature free entropy Φ β ( n ) ( m a , m ^ a , Q a b , Q ^ a b ) = n ( Ψ t + Ψ K + α Ψ y ) \Phi_{\beta}^{(n)}(m^{a},\hat{m}^{a},Q^{ab},\hat{Q}^{ab})=n\left(\Psi_{t}+\Psi_{K}+\alpha\Psi_{y}\right) Φ β ( n ) ( m a , m ^ a , Q ab , Q ^ ab ) = n ( Ψ t + Ψ K + α Ψ y ) , and can be evaluated using a Laplace saddle-point approximation.
Replica-symmetric ansatz
We have thus rephrased the analysis of the measure (19) as a optimization problem over the order parameters { m a , Q a b } \{m^{a},Q^{ab}\} { m a , Q ab } , and the associated conjugate variables. However, these still represent 2 n H F + 2 n 2 H 2 2nHF+2n^{2}H^{2} 2 n H F + 2 n 2 H 2 variables with n → 0 n\to0 n → 0 . In order to make progress, we assume that the saddle point is of replica-symmetric (RS) form
m a = m ∈ R H × F , m ^ a = m ^ ∈ R H × F , (35) m^{a}=m\in\mathbb{R}^{H\times F},\qquad\hat{m}^{a}=\hat{m}\in\mathbb{R}^{H\times F}, \tag*{(35)} m a = m ∈ R H × F , m ^ a = m ^ ∈ R H × F , (35)
Q a b = q δ a ≠ b + Q δ a b ∈ R H × H , Q ^ a b = − q ^ δ a ≠ b + Q ^ δ a b ∈ R H × H . (36) Q^{ab}=q\delta_{a\ne b}+Q\delta_{ab}\in\mathbb{R}^{H\times H},\qquad\hat{Q}^{ab}=-\hat{q}\delta_{a\ne b}+\hat{Q}\delta_{ab}\in\mathbb{R}^{H\times H}. \tag*{(36)} Q ab = q δ a = b + Q δ ab ∈ R H × H , Q ^ ab = − q ^ δ a = b + Q ^ δ ab ∈ R H × H . (36)
The RS ansatz holds in a number of machine learning settings, notably for convex problems and Bayes-optimal settings. In the present setting, since the empirical loss (17) is non-convex, the RS ansatz constitutes a heuristic technical assumption of our analysis.
Under this ansatz, we can factorize the replicas by introducing random Gaussian variables Ξ = { ξ ℓ } ℓ = 1 L \Xi=\{\xi_{\ell}\}_{\ell=1}^{L} Ξ = { ξ ℓ } ℓ = 1 L with ξ ℓ ∼ N ( 0 , I H ) \xi_{\ell}\sim\mathcal{N}(0,I_{H}) ξ ℓ ∼ N ( 0 , I H ) . With quadratic regularization, we can perform the integration over the weights K K K in the entropic term. Introducing the variance order parameter
V = Q − q , V ^ = Q ^ + q ^ , (37) V=Q-q,\qquad\hat{V}=\hat{Q}+\hat{q}, \tag*{(37)} V = Q − q , V ^ = Q ^ + q ^ , (37)
and taking the limit n → 0 n\to0 n → 0 , the free entropy can then be expressed as
Φ β = lim n → 0 1 n extr m , m ^ , q , q ^ , V , V ^ { Φ β ( n ) ( m a , m ^ a , Q a b , Q ^ a b ) } = extr m , m ^ , q , q ^ , V , V ^ { Ψ t + Ψ K + α Ψ y } (38) \Phi_{\beta}=\lim_{n\to0}\frac{1}{n}\underset{m,\hat{m},q,\hat{q},V,\hat{V}}{\operatorname{extr}}\left\{\Phi_{\beta}^{(n)}(m^{a},\hat{m}^{a},Q^{ab},\hat{Q}^{ab})\right\}=\underset{m,\hat{m},q,\hat{q},V,\hat{V}}{\operatorname{extr}}\left\{\Psi_{t}+\Psi_{K}+\alpha\Psi_{y}\right\} \tag*{(38)} Φ β = n → 0 lim n 1 m , m ^ , q , q ^ , V , V ^ extr { Φ β ( n ) ( m a , m ^ a , Q ab , Q ^ ab ) } = m , m ^ , q , q ^ , V , V ^ extr { Ψ t + Ψ K + α Ψ y } (38)
with
Ψ t = − Tr ( m ^ T m ) + 1 2 Tr [ V ^ ( q + V ) − q ^ V ] (39) \Psi_{t}=-\operatorname{Tr}(\hat{m}^{\mathsf{T}}m)+\frac{1}{2}\operatorname{Tr}\left[\hat{V}(q+V)-\hat{q}V\right] \tag*{(39)} Ψ t = − Tr ( m ^ T m ) + 2 1 Tr [ V ^ ( q + V ) − q ^ V ] (39)
Ψ K = − 1 2 log [ det ( β λ I H + V ^ ) ] + 1 2 Tr [ ( β λ I H + V ^ ) − 1 ( q ^ + m ^ m ^ T ) ] (40) \Psi_{K}=-\frac{1}{2}\log\left[\det(\beta\lambda I_{H}+\hat{V})\right]+\frac{1}{2}\operatorname{Tr}\left[(\beta\lambda I_{H}+\hat{V})^{-1}(\hat{q}+\hat{m}\hat{m}^{\mathsf{T}})\right] \tag*{(40)} Ψ K = − 2 1 log [ det ( β λ I H + V ^ ) ] + 2 1 Tr [ ( β λ I H + V ^ ) − 1 ( q ^ + m ^ m ^ T ) ] (40)
Ψ y = E Ξ , ϵ , θ { log [ ∫ d Z e − β ℓ ( ϵ , Z ) e − 1 2 ∑ ℓ = 1 L ( Z ℓ − ω ℓ ) T V − 1 ( Z ℓ − ω ℓ ) det ( 2 π V ) L / 2 ] } (41) \Psi_{y}=\mathbb{E}_{\Xi,\epsilon,\theta}\left\{\log\left[\int dZ\,e^{-\beta\ell(\epsilon,Z)}\frac{e^{-\frac{1}{2}\sum_{\ell=1}^{L}(Z_{\ell}-\omega_{\ell})^{\mathsf{T}}V^{-1}(Z_{\ell}-\omega_{\ell})}}{\det(2\pi V)^{L/2}}\right]\right\} \tag*{(41)} Ψ y = E Ξ , ϵ , θ { log [ ∫ d Z e − β ℓ ( ϵ , Z ) det ( 2 π V ) L /2 e − 2 1 ∑ ℓ = 1 L ( Z ℓ − ω ℓ ) T V − 1 ( Z ℓ − ω ℓ ) ] } (41)
where we introduced the local fields Ω = { ω ℓ } ℓ = 1 L \Omega= \{\omega_\ell\}_{\ell=1}^{L} Ω = { ω ℓ } ℓ = 1 L with ω ℓ : = δ ℓ m θ + q 1 / 2 ξ ℓ \omega_\ell:= \delta_{\ell m}\theta+ q^{1/2}\xi_\ell ω ℓ := δ ℓ m θ + q 1/2 ξ ℓ and we omit additive constants in the potentials. Note that these expressions do not depend on K ∗ K^{*} K ∗ anymore; the planted directions enter only through K ∗ K ∗ ⊤ / D → I F K^{*}K^{*\top}/D \to I_{F} K ∗ K ∗ ⊤ / D → I F , such that no further specification or averaging of their distribution is required.
Zero temperature limit
We now take the limit β → ∞ \beta\to\infty β → ∞ , rescaling
m ^ → β m ^ , q ^ → β 2 q ^ , V ^ → β V ^ , V → β − 1 V . (42) \hat{m} \to\beta\hat{m}, \qquad\hat{q} \to\beta^{2}\hat{q}, \qquad\hat{V} \to\beta\hat{V}, \qquad V \to\beta^{-1}V. \tag*{(42)} m ^ → β m ^ , q ^ → β 2 q ^ , V ^ → β V ^ , V → β − 1 V . (42)
The potentials and free entropy reduce to
Φ = lim β → ∞ 1 β Φ β = extr m , m ^ , q , q ^ , V , V ^ { Ψ t + Ψ K + α Ψ y } (43) \Phi= \lim_{\beta\to\infty} \frac{1}{\beta}\Phi_{\beta} = \underset{m,\hat{m},q,\hat{q},V,\hat{V}}{\operatorname{extr}}\left\{\Psi_t+\Psi_K+\alpha\Psi_y\right\} \tag*{(43)} Φ = β → ∞ lim β 1 Φ β = m , m ^ , q , q ^ , V , V ^ extr { Ψ t + Ψ K + α Ψ y } (43)
with
Ψ t = − Tr ( m ^ ⊤ m ) + 1 2 Tr ( V ^ q − q ^ V ) (44) \Psi_t = -\operatorname{Tr}(\hat{m}^{\top}m)+\frac{1}{2}\operatorname{Tr}(\hat{V}q-\hat{q}V) \tag*{(44)} Ψ t = − Tr ( m ^ ⊤ m ) + 2 1 Tr ( V ^ q − q ^ V ) (44)
Ψ K = 1 2 Tr [ ( λ I H + V ^ ) − 1 ( q ^ + m ^ m ^ ⊤ ) ] (45) \Psi_K = \frac{1}{2}\operatorname{Tr}\left[(\lambda I_H+\hat{V})^{-1}(\hat{q}+\hat{m}\hat{m}^{\top})\right] \tag*{(45)} Ψ K = 2 1 Tr [ ( λ I H + V ^ ) − 1 ( q ^ + m ^ m ^ ⊤ ) ] (45)
Ψ y = − E Ξ , ϵ , θ [ M ( ϵ , θ , Ξ ) ] (46) \Psi_y = -\mathbb{E}_{\Xi,\epsilon,\theta}\left[\mathcal{M}(\epsilon,\theta,\Xi)\right] \tag*{(46)} Ψ y = − E Ξ , ϵ , θ [ M ( ϵ , θ , Ξ ) ] (46)
where the Moreau envelope is defined as
M ( ϵ , θ , Ξ ) = inf Z ∈ R L × H { ℓ ( ϵ , Z ) + 1 2 ∑ ℓ = 1 L ( Z ℓ − ω ℓ ) ⊤ V − 1 ( Z ℓ − ω ℓ ) } . (47) \mathcal{M}(\epsilon,\theta,\Xi)=\underset{Z\in\mathbb{R}^{L\times H}}{\inf}\left\{\ell(\epsilon,Z)+\frac{1}{2}\sum_{\ell=1}^{L}(Z_\ell-\omega_\ell)^{\top}V^{-1}(Z_\ell-\omega_\ell)\right\}. \tag*{(47)} M ( ϵ , θ , Ξ ) = Z ∈ R L × H inf { ℓ ( ϵ , Z ) + 2 1 ℓ = 1 ∑ L ( Z ℓ − ω ℓ ) ⊤ V − 1 ( Z ℓ − ω ℓ ) } . (47)
Replica free entropy
Up to this point, the derivation can be carried generally with respect to the activation function and low dimensional distributions of the data model. One already reached a low dimensional characterization and can in principle state the final result generally. For clarity, we state the results for the particular setting studied. Specifying the distribution of ϵ \epsilon ϵ and using permutation equivariance of softmax with respect to the tokens to fix ϵ = 1 \epsilon=1 ϵ = 1 , we can simplify further the equations (45–49). One finally reaches an expression for the replica free entropy:
Φ = extr m , m ^ , q , q ^ , V , V ^ { 1 2 Tr ( V ^ q − q ^ V ) − Tr ( m ^ ⊤ m ) + 1 2 Tr [ ( λ I H + V ^ ) − 1 ( q ^ + m ^ m ^ ⊤ ) ] − α E Ξ , θ [ M ( θ , Ξ ) ] } (48) \Phi=\underset{m,\hat{m},q,\hat{q},V,\hat{V}}{\operatorname{extr}}\left\{\frac{1}{2}\operatorname{Tr}(\hat{V}q-\hat{q}V)-\operatorname{Tr}(\hat{m}^{\top}m)+\frac{1}{2}\operatorname{Tr}\left[(\lambda I_H+\hat{V})^{-1}(\hat{q}+\hat{m}\hat{m}^{\top})\right]-\alpha\mathbb{E}_{\Xi,\theta}\left[\mathcal{M}(\theta,\Xi)\right]\right\} \tag*{(48)} Φ = m , m ^ , q , q ^ , V , V ^ extr { 2 1 Tr ( V ^ q − q ^ V ) − Tr ( m ^ ⊤ m ) + 2 1 Tr [ ( λ I H + V ^ ) − 1 ( q ^ + m ^ m ^ ⊤ ) ] − α E Ξ , θ [ M ( θ , Ξ ) ] } (48)
where we defined the local fields ω ℓ = δ ℓ 1 m θ + q 1 / 2 ξ ℓ \omega_\ell=\delta_{\ell1}m\theta+q^{1/2}\xi_\ell ω ℓ = δ ℓ 1 m θ + q 1/2 ξ ℓ with ξ ℓ ∼ N ( 0 , I H ) \xi_\ell\sim\mathcal{N}(0,I_H) ξ ℓ ∼ N ( 0 , I H ) and the Moreau envelope
M ( θ , Ξ ) = inf Z ∈ R L × H { 1 2 ∑ ℓ = 1 L ( δ ℓ 1 − 1 H ∑ h = 1 H softmax ( Z : h ) ℓ ) 2 + 1 2 ∑ ℓ = 1 L ( Z ℓ − ω ℓ ) ⊤ V − 1 ( Z ℓ − ω ℓ ) } . (49) \mathcal{M}(\theta,\Xi)=\underset{Z\in\mathbb{R}^{L\times H}}{\inf}\left\{\frac{1}{2}\sum_{\ell=1}^{L}\left(\delta_{\ell1}-\frac{1}{H}\sum_{h=1}^{H}\operatorname{softmax}(Z_{:h})_\ell\right)^{2}+\frac{1}{2}\sum_{\ell=1}^{L}(Z_\ell-\omega_\ell)^{\top}V^{-1}(Z_\ell-\omega_\ell)\right\}. \tag*{(49)} M ( θ , Ξ ) = Z ∈ R L × H inf ⎩ ⎨ ⎧ 2 1 ℓ = 1 ∑ L ( δ ℓ 1 − H 1 h = 1 ∑ H softmax ( Z : h ) ℓ ) 2 + 2 1 ℓ = 1 ∑ L ( Z ℓ − ω ℓ ) ⊤ V − 1 ( Z ℓ − ω ℓ ) ⎭ ⎬ ⎫ . (49)
Saddle-point equations
The extremization for the free entropy (48) obtained by setting the gradient of its potential to zero yields the following system of self-consistent equations on the summary statistics:
m = ( λ I H + V ^ ) − 1 m ^ q = ( λ I H + V ^ ) − 1 ( m ^ m ^ ⊤ + q ^ ) ( λ I H + V ^ ) − 1 V = ( λ I H + V ^ ) − 1 (50) \begin{aligned}
m &= (\lambda I_H+\hat{V})^{-1}\hat{m}\\
q &= (\lambda I_H+\hat{V})^{-1}(\hat{m}\hat{m}^{\top}+\hat{q})(\lambda I_H+\hat{V})^{-1}\\
V &= (\lambda I_H+\hat{V})^{-1} \tag*{(50)}
\end{aligned} m q V = ( λ I H + V ^ ) − 1 m ^ = ( λ I H + V ^ ) − 1 ( m ^ m ^ ⊤ + q ^ ) ( λ I H + V ^ ) − 1 = ( λ I H + V ^ ) − 1 (50)
m ^ = α E θ , Ξ [ V − 1 ( prox ( θ , Ξ ) 1 − ω 1 ) θ ⊤ ] q ^ = α E θ , Ξ [ V − 1 ( ∑ ℓ = 1 L ( prox ( θ , Ξ ) ℓ − ω ℓ ) ⊗ 2 ) V − 1 ] V ^ = − α E θ , Ξ [ V − 1 ( ∑ ℓ = 1 L ( prox ( θ , Ξ ) ℓ − ω ℓ ) ξ ℓ ⊤ ] q − 1 / 2 ] (51) \begin{aligned}
\hat{m} &= \alpha\mathbb{E}_{\theta,\Xi}\left[V^{-1}\left(\operatorname{prox}(\theta,\Xi)_1-\omega_1\right)\theta^{\top}\right]\\
\hat{q} &= \alpha\mathbb{E}_{\theta,\Xi}\left[V^{-1}\left(\sum_{\ell=1}^{L}\left(\operatorname{prox}(\theta,\Xi)_\ell-\omega_\ell\right)^{\otimes2}\right)V^{-1}\right]\\
\hat{V} &= -\alpha\mathbb{E}_{\theta,\Xi}\left[V^{-1}\left(\sum_{\ell=1}^{L}\left(\operatorname{prox}(\theta,\Xi)_\ell-\omega_\ell\right)\xi_\ell^{\top}\right]q^{-1/2}\right] \tag*{(51)}
\end{aligned} m ^ q ^ V ^ = α E θ , Ξ [ V − 1 ( prox ( θ , Ξ ) 1 − ω 1 ) θ ⊤ ] = α E θ , Ξ [ V − 1 ( ℓ = 1 ∑ L ( prox ( θ , Ξ ) ℓ − ω ℓ ) ⊗ 2 ) V − 1 ] = − α E θ , Ξ [ V − 1 ( ℓ = 1 ∑ L ( prox ( θ , Ξ ) ℓ − ω ℓ ) ξ ℓ ⊤ ] q − 1/2 ] (51)
where the proximals { prox ( θ , Ξ ) ℓ } ℓ = 1 L \{\operatorname{prox}(\theta,\Xi)_{\ell}\}_{\ell=1}^{L} { prox ( θ , Ξ ) ℓ } ℓ = 1 L refer to the minimizers of the Moreau envelope M ( θ , Ξ ) \mathcal{M}(\theta,\Xi) M ( θ , Ξ ) (49) .
Note that the update equation for V ^ \widehat{V} V contains a term q − 1 / 2 q^{-1/2} q − 1/2 that could become singular, in particular on the PS branch. This apparent singularity is removable using integration by parts
V ^ = − α E θ , Ξ [ ∑ ℓ = 1 L V − 1 ( ∂ prox ( θ , Ξ ) ℓ ∂ ω ℓ − I H ) ] , (52) \widehat{V}=-\alpha\mathbb{E}_{\theta,\Xi}\left[\sum_{\ell=1}^{L}V^{-1}\left(\frac{\partial\operatorname{prox}(\theta,\Xi)_{\ell}}{\partial\omega_{\ell}}-\mathbb{I}_{H}\right)\right], \tag*{(52)} V = − α E θ , Ξ [ ℓ = 1 ∑ L V − 1 ( ∂ ω ℓ ∂ prox ( θ , Ξ ) ℓ − I H ) ] , (52)
and we use this formulation to improve the stability of the numerical implementation of state evolution for the non-isotropic Gaussian model.
Test error
The generalization performance is measured by the test error
E = lim D → ∞ E D { E X , y ∣ K ∗ [ 1 2 D ∥ y − f K ^ ( X ) ∥ 2 ] } , (53) \mathcal{E}=\lim_{D\to\infty}\mathbb{E}_{\mathcal{D}}\left\{\mathbb{E}_{X,y\mid K^{*}}\left[\frac{1}{2D}\left\|y-f_{\widehat{K}}(X)\right\|^{2}\right]\right\}, \tag*{(53)} E = D → ∞ lim E D { E X , y ∣ K ∗ [ 2 D 1 ∥ y − f K ( X ) ∥ 2 ] } , (53)
where the test samples { X , y } \{X,y\} { X , y } are independent of the training set D \mathcal{D} D , conditionally on the planted spikes K ∗ K^{*} K ∗ . Introducing the local fields X K ^ T / D X\widehat{K}^{\mathsf{T}}/\sqrt{D} X K T / D and expliciting the expression for the data model, the test error admits an asymptotic reparameterization in terms of the summary statistics characterized by (50) :
E = 1 2 E θ , Ξ [ ∑ ℓ = 1 L ( δ ℓ 1 − 1 H ∑ h = 1 H softmax ( Ω : h ) ℓ ) 2 ] (54) \mathcal{E}=\frac{1}{2}\mathbb{E}_{\theta,\Xi}\left[\sum_{\ell=1}^{L}\left(\delta_{\ell1}-\frac{1}{H}\sum_{h=1}^{H}\operatorname{softmax}(\Omega:h)_{\ell}\right)^{2}\right] \tag*{(54)} E = 2 1 E θ , Ξ ℓ = 1 ∑ L ( δ ℓ 1 − H 1 h = 1 ∑ H softmax ( Ω : h ) ℓ ) 2 (54)
where, as before, θ ∼ P θ \theta\sim P_{\theta} θ ∼ P θ , Ξ = { ξ ℓ } ℓ = 1 L \Xi=\{\xi_{\ell}\}_{\ell=1}^{L} Ξ = { ξ ℓ } ℓ = 1 L with ξ ℓ ∼ N ( 0 , I H ) \xi_{\ell}\sim\mathcal{N}(0,\mathbb{I}_{H}) ξ ℓ ∼ N ( 0 , I H ) , Ω = { ω ℓ } ℓ = 1 L \Omega=\{\omega_{\ell}\}_{\ell=1}^{L} Ω = { ω ℓ } ℓ = 1 L , ω ℓ = δ ℓ 1 m θ + q 1 / 2 ξ ℓ \omega_{\ell}=\delta_{\ell1}m\theta+q^{1/2}\xi_{\ell} ω ℓ = δ ℓ 1 m θ + q 1/2 ξ ℓ , and we used token permutation equivariance of the softmax activation.
Training error
As noted in Cui et al. [12 ] , the unregularized training error (18) can be obtained through the free energy − Φ -\Phi − Φ at zero temperature:
E t r a i n = − 1 α Φ − λ 2 α Tr ( q ) = E θ , Ξ [ M ( θ , Ξ ) ] − 1 2 α Tr ( q ^ V ) , (55) \mathcal{E}_{\mathrm{train}}=-\frac{1}{\alpha}\Phi-\frac{\lambda}{2\alpha}\operatorname{Tr}(q)=\mathbb{E}_{\theta,\Xi}[\mathcal{M}(\theta,\Xi)]-\frac{1}{2\alpha}\operatorname{Tr}(\widehat{q}V), \tag*{(55)} E train = − α 1 Φ − 2 α λ Tr ( q ) = E θ , Ξ [ M ( θ , Ξ )] − 2 α 1 Tr ( q V ) , (55)
where again, Ξ = { ξ ℓ } ℓ = 1 L \Xi=\{\xi_{\ell}\}_{\ell=1}^{L} Ξ = { ξ ℓ } ℓ = 1 L with ξ ℓ ∼ N ( 0 , I H ) \xi_{\ell}\sim\mathcal{N}(0,\mathbb{I}_{H}) ξ ℓ ∼ N ( 0 , I H ) , and M ( θ , Ξ ) \mathcal{M}(\theta,\Xi) M ( θ , Ξ ) denotes the Moreau envelope (49) . This can also be obtained directly from the relation L t r a i n = − lim β → ∞ ∂ β log Z β \mathcal{L}_{\mathrm{train}}=-\lim_{\beta\to\infty}\partial_{\beta}\log Z_{\beta} L train = − lim β → ∞ ∂ β log Z β , where the derivative is taken on the finite temperature free entropy (38) before the limit.
Model-specific saddle-point equations
We now evaluate the remaining feature averages for the two choices of P θ P_{\theta} P θ defining the models of Sec. 2.
Flipping spike model
In the case of the flipping spike distribution where θ 1 = ν 1 \theta_{1}=\sqrt{\nu_{1}} θ 1 = ν 1 and θ 2 ∼ Unif ( { − ν 2 , ν 2 } ) \theta_{2}\sim\operatorname{Unif}(\{-\sqrt{\nu_{2}},\sqrt{\nu_{2}}\}) θ 2 ∼ Unif ({ − ν 2 , ν 2 }) we can define
P θ = 1 2 ( δ θ + + δ θ − ) , θ ± = ( ν 1 ± ν 2 ) . (56) P_{\theta}=\frac{1}{2}(\delta_{\theta_{+}}+\delta_{\theta_{-}}),\qquad\theta_{\pm}=\begin{pmatrix}\sqrt{\nu_{1}}\\ \pm\sqrt{\nu_{2}}\end{pmatrix}. \tag*{(56)} P θ = 2 1 ( δ θ + + δ θ − ) , θ ± = ( ν 1 ± ν 2 ) . (56)
The random variable is discrete and averaging over θ \theta θ leads to the saddle-point equations:
m = ( λ I H + V ^ ) − 1 m ^ q = ( λ I H + V ^ ) − 1 ( m ^ m ^ T + q ^ ) ( λ I H + V ^ ) − 1 V = ( λ I H + V ^ ) − 1 (57) \begin{aligned}
m &= (\lambda\mathbb{I}_{H}+\hat{V})^{-1}\hat{m}\\
q &= (\lambda\mathbb{I}_{H}+\hat{V})^{-1}(\hat{m}\hat{m}^{\mathsf{T}}+\hat{q})(\lambda\mathbb{I}_{H}+\hat{V})^{-1}\\
V &= (\lambda\mathbb{I}_{H}+\hat{V})^{-1} \tag*{(57)}
\end{aligned} m q V = ( λ I H + V ^ ) − 1 m ^ = ( λ I H + V ^ ) − 1 ( m ^ m ^ T + q ^ ) ( λ I H + V ^ ) − 1 = ( λ I H + V ^ ) − 1 (57)
m ^ = α 2 ∑ s = ± 1 E Ξ [ V − 1 ( prox ( Ξ ) ( s ) − ω 1 ( s ) ) θ s T ] q ^ = α 2 ∑ s = ± 1 E Ξ [ V − 1 ( ∑ ℓ = 1 L ( prox ( Ξ ) ℓ ( s ) − ω ℓ ( s ) ) ⊗ 2 ) V − 1 ] V ^ = − α 2 ∑ s = ± 1 E Ξ [ V − 1 ( ∑ ℓ = 1 L ( prox ( Ξ ) ℓ ( s ) − ω ℓ ( s ) ) ξ ℓ T ) q − 1 / 2 ] (58) \begin{aligned}
\hat{m} &= \frac{\alpha}{2}\sum_{s=\pm1}\mathbb{E}_{\Xi}\left[V^{-1}\left(\operatorname{prox}(\Xi)^{(s)}-\omega_{1}^{(s)}\right)\theta_{s}^{\mathsf{T}}\right]\\
\hat{q} &= \frac{\alpha}{2}\sum_{s=\pm1}\mathbb{E}_{\Xi}\left[V^{-1}\left(\sum_{\ell=1}^{L}\left(\operatorname{prox}(\Xi)_{\ell}^{(s)}-\omega_{\ell}^{(s)}\right)^{\otimes2}\right)V^{-1}\right]\\
\hat{V} &= -\frac{\alpha}{2}\sum_{s=\pm1}\mathbb{E}_{\Xi}\left[V^{-1}\left(\sum_{\ell=1}^{L}\left(\operatorname{prox}(\Xi)_{\ell}^{(s)}-\omega_{\ell}^{(s)}\right)\xi_{\ell}^{\mathsf{T}}\right)q^{-1/2}\right] \tag*{(58)}
\end{aligned} m ^ q ^ V ^ = 2 α s = ± 1 ∑ E Ξ [ V − 1 ( prox ( Ξ ) ( s ) − ω 1 ( s ) ) θ s T ] = 2 α s = ± 1 ∑ E Ξ [ V − 1 ( ℓ = 1 ∑ L ( prox ( Ξ ) ℓ ( s ) − ω ℓ ( s ) ) ⊗ 2 ) V − 1 ] = − 2 α s = ± 1 ∑ E Ξ [ V − 1 ( ℓ = 1 ∑ L ( prox ( Ξ ) ℓ ( s ) − ω ℓ ( s ) ) ξ ℓ T ) q − 1/2 ] (58)
where we define the local fields Ω ( s ) = { ω ℓ ( s ) } ℓ = 1 L \Omega^{(s)}=\{\omega_{\ell}^{(s)}\}_{\ell=1}^{L} Ω ( s ) = { ω ℓ ( s ) } ℓ = 1 L as ω ℓ ( s ) : = δ ℓ 1 m θ s + q 1 / 2 ξ ℓ \omega_{\ell}^{(s)}:=\delta_{\ell1}m\theta_{s}+q^{1/2}\xi_{\ell} ω ℓ ( s ) := δ ℓ 1 m θ s + q 1/2 ξ ℓ and with ξ ∼ N ( 0 , I H ) \xi\sim\mathcal{N}(0,\mathbb{I}_{H}) ξ ∼ N ( 0 , I H ) the proximals { prox ( Ξ ) ℓ ( s ) } ℓ = 1 L \{\operatorname{prox}(\Xi)_{\ell}^{(s)}\}_{\ell=1}^{L} { prox ( Ξ ) ℓ ( s ) } ℓ = 1 L refer to the minimizers of the Moreau envelope
M ( Ξ ) ( s ) = inf Z ∈ R L × H { 1 2 ∑ ℓ = 1 L ( δ ℓ 1 − 1 H ∑ h = 1 H softmax ( Z ⋅ h ) ℓ ) 2 + 1 2 ∑ ℓ = 1 L ( Z ℓ − ω ℓ ( s ) ) T V − 1 ( Z ℓ − ω ℓ ( s ) ) } . (59) \mathcal{M}(\Xi)^{(s)}=\inf_{Z\in\mathbb{R}^{L\times H}}\left\{\frac{1}{2}\sum_{\ell=1}^{L}\left(\delta_{\ell1}-\frac{1}{H}\sum_{h=1}^{H}\operatorname{softmax}(Z_{\cdot h})_{\ell}\right)^{2}+\frac{1}{2}\sum_{\ell=1}^{L}(Z_{\ell}-\omega_{\ell}^{(s)})^{\mathsf{T}}V^{-1}(Z_{\ell}-\omega_{\ell}^{(s)})\right\}. \tag*{(59)} M ( Ξ ) ( s ) = Z ∈ R L × H inf ⎩ ⎨ ⎧ 2 1 ℓ = 1 ∑ L ( δ ℓ 1 − H 1 h = 1 ∑ H softmax ( Z ⋅ h ) ℓ ) 2 + 2 1 ℓ = 1 ∑ L ( Z ℓ − ω ℓ ( s ) ) T V − 1 ( Z ℓ − ω ℓ ( s ) ) ⎭ ⎬ ⎫ . (59)
The test error then becomes
E = 1 4 ∑ s = ± 1 E Ξ [ ∑ ℓ = 1 L ( δ ℓ 1 − 1 H ∑ h = 1 H softmax ( Ω h ( s ) ) ℓ ) 2 ] , (60) \mathcal{E}=\frac{1}{4}\sum_{s=\pm1}\mathbb{E}_{\Xi}\left[\sum_{\ell=1}^{L}\left(\delta_{\ell1}-\frac{1}{H}\sum_{h=1}^{H}\operatorname{softmax}(\Omega_{h}^{(s)})_{\ell}\right)^{2}\right], \tag*{(60)} E = 4 1 s = ± 1 ∑ E Ξ ℓ = 1 ∑ L ( δ ℓ 1 − H 1 h = 1 ∑ H softmax ( Ω h ( s ) ) ℓ ) 2 , (60)
and the train error
E t r a i n = 1 2 ∑ s = ± 1 E Ξ [ M ( Ξ ) ( s ) ] − 1 2 α Tr ( q ^ V ) . (61) \mathcal{E}_{\mathrm{train}}=\frac{1}{2}\sum_{s=\pm1}\mathbb{E}_{\Xi}\left[\mathcal{M}(\Xi)^{(s)}\right]-\frac{1}{2\alpha}\operatorname{Tr}(\hat{q}V). \tag*{(61)} E train = 2 1 s = ± 1 ∑ E Ξ [ M ( Ξ ) ( s ) ] − 2 α 1 Tr ( q ^ V ) . (61)
Non-isotropic Gaussian model
In the case of the non-isotropic Gaussian distribution we have
θ ∼ N ( 0 , Λ ) , Λ = diag ( ν 1 , … , ν F ) . (62) \theta\sim\mathcal{N}(0,\Lambda),\qquad\Lambda=\operatorname{diag}(\nu_{1},\ldots,\nu_{F}). \tag*{(62)} θ ∼ N ( 0 , Λ ) , Λ = diag ( ν 1 , … , ν F ) . (62)
Dependencies on θ \theta θ enter the proximals only through the local fields Ω = { ω ℓ } ℓ = 1 L \Omega=\{\omega_{\ell}\}_{\ell=1}^{L} Ω = { ω ℓ } ℓ = 1 L and we have
E [ θ ∣ Ω ] = Λ m T ( q + m Λ m T ) − 1 ω 1 , E [ ξ ℓ ∣ Ω ] = q 1 / 2 ( q + δ ℓ 1 m Λ m T ) − 1 ω ℓ . (63) \mathbb{E}[\theta\mid\Omega]=\Lambda m^{\mathsf{T}}(q+m\Lambda m^{\mathsf{T}})^{-1}\omega_{1},\qquad\mathbb{E}[\xi_{\ell}\mid\Omega]=q^{1/2}(q+\delta_{\ell1}m\Lambda m^{\mathsf{T}})^{-1}\omega_{\ell}. \tag*{(63)} E [ θ ∣ Ω ] = Λ m T ( q + m Λ m T ) − 1 ω 1 , E [ ξ ℓ ∣ Ω ] = q 1/2 ( q + δ ℓ 1 m Λ m T ) − 1 ω ℓ . (63)
Averaging over ( θ , Ξ ) (\theta,\Xi) ( θ , Ξ ) conditionally on the local fields then leads to the saddle-point equations:
m = ( λ I H + V ^ ) − 1 m ^ q = ( λ I H + V ^ ) − 1 ( m ^ m ^ T + q ^ ) ( λ I H + V ^ ) − 1 V = ( λ I H + V ^ ) − 1 (64) \begin{aligned}
m &= (\lambda\mathbb{I}_{H}+\hat{V})^{-1}\hat{m}\\
q &= (\lambda\mathbb{I}_{H}+\hat{V})^{-1}(\hat{m}\hat{m}^{\mathsf{T}}+\hat{q})(\lambda\mathbb{I}_{H}+\hat{V})^{-1}\\
V &= (\lambda\mathbb{I}_{H}+\hat{V})^{-1} \tag*{(64)}
\end{aligned} m q V = ( λ I H + V ^ ) − 1 m ^ = ( λ I H + V ^ ) − 1 ( m ^ m ^ T + q ^ ) ( λ I H + V ^ ) − 1 = ( λ I H + V ^ ) − 1 (64)
m ^ = α E Ω [ V − 1 ( prox ( Ω ) 1 − ω 1 ) ω 1 T ] ( q + m Λ m T ) − 1 m Λ q ^ = α E Ω [ V − 1 ( ∑ ℓ = 1 L ( prox ( Ω ) ℓ − ω ℓ ) ⊗ 2 ) V − 1 ] V ^ = − α E Ω [ V − 1 ( ∑ ℓ = 1 L ( prox ( Ω ) ℓ − ω ℓ ) ω ℓ T ( q + δ ℓ 1 m Λ m T ) − 1 ) ] (65) \begin{aligned}
\hat{m} &= \alpha\mathbb{E}_{\Omega}\left[V^{-1}(\operatorname{prox}(\Omega)_{1}-\omega_{1})\omega_{1}^{\mathsf{T}}\right](q+m\Lambda m^{\mathsf{T}})^{-1}m\Lambda\\
\hat{q} &= \alpha\mathbb{E}_{\Omega}\left[V^{-1}\left(\sum_{\ell=1}^{L}(\operatorname{prox}(\Omega)_{\ell}-\omega_{\ell})^{\otimes2}\right)V^{-1}\right]\\
\hat{V} &= -\alpha\mathbb{E}_{\Omega}\left[V^{-1}\left(\sum_{\ell=1}^{L}(\operatorname{prox}(\Omega)_{\ell}-\omega_{\ell})\omega_{\ell}^{\mathsf{T}}(q+\delta_{\ell1}m\Lambda m^{\mathsf{T}})^{-1}\right)\right] \tag*{(65)}
\end{aligned} m ^ q ^ V ^ = α E Ω [ V − 1 ( prox ( Ω ) 1 − ω 1 ) ω 1 T ] ( q + m Λ m T ) − 1 m Λ = α E Ω [ V − 1 ( ℓ = 1 ∑ L ( prox ( Ω ) ℓ − ω ℓ ) ⊗ 2 ) V − 1 ] = − α E Ω [ V − 1 ( ℓ = 1 ∑ L ( prox ( Ω ) ℓ − ω ℓ ) ω ℓ T ( q + δ ℓ 1 m Λ m T ) − 1 ) ] (65)
where Ω = { ω ℓ } ℓ = 1 L \Omega=\{\omega_{\ell}\}_{\ell=1}^{L} Ω = { ω ℓ } ℓ = 1 L with ω ℓ ∼ N ( 0 , q + δ ℓ 1 m Λ m T ) \omega_{\ell}\sim\mathcal{N}(0,q+\delta_{\ell1}m\Lambda m^{\mathsf{T}}) ω ℓ ∼ N ( 0 , q + δ ℓ 1 m Λ m T ) and { prox ( Ω ) ℓ } ℓ = 1 L \{\operatorname{prox}(\Omega)_{\ell}\}_{\ell=1}^{L} { prox ( Ω ) ℓ } ℓ = 1 L refer to the minimizers of the Moreau envelope
M ( Ω ) = inf Z ∈ R L × H { 1 2 ∑ ℓ = 1 L ( δ ℓ 1 − 1 H ∑ h = 1 H softmax ( Z ⋅ h ) ℓ ) 2 + 1 2 ∑ ℓ = 1 L ( Z ℓ − ω ℓ ) T V − 1 ( Z ℓ − ω ℓ ) } . (66) \mathcal{M}(\Omega)=\inf_{Z\in\mathbb{R}^{L\times H}}\left\{\frac{1}{2}\sum_{\ell=1}^{L}\left(\delta_{\ell1}-\frac{1}{H}\sum_{h=1}^{H}\operatorname{softmax}(Z_{\cdot h})_{\ell}\right)^{2}+\frac{1}{2}\sum_{\ell=1}^{L}(Z_{\ell}-\omega_{\ell})^{\mathsf{T}}V^{-1}(Z_{\ell}-\omega_{\ell})\right\}. \tag*{(66)} M ( Ω ) = Z ∈ R L × H inf ⎩ ⎨ ⎧ 2 1 ℓ = 1 ∑ L ( δ ℓ 1 − H 1 h = 1 ∑ H softmax ( Z ⋅ h ) ℓ ) 2 + 2 1 ℓ = 1 ∑ L ( Z ℓ − ω ℓ ) T V − 1 ( Z ℓ − ω ℓ ) ⎭ ⎬ ⎫ . (66)
The test error then becomes
E = 1 2 E Ω [ ∑ ℓ = 1 L ( δ ℓ 1 − 1 H ∑ h = 1 H softmax ( Ω : h ) ℓ ) 2 ] (67) \mathcal{E}=\frac{1}{2}\mathbb{E}_{\Omega}\left[\sum_{\ell=1}^{L}\left(\delta_{\ell1}-\frac{1}{H}\sum_{h=1}^{H}\operatorname{softmax}(\Omega_{:h})_{\ell}\right)^{2}\right] \tag*{(67)} E = 2 1 E Ω ℓ = 1 ∑ L ( δ ℓ 1 − H 1 h = 1 ∑ H softmax ( Ω : h ) ℓ ) 2 (67)
and the train error
E t r a i n = E Ω [ M ( Ω ) ] − 1 2 α Tr ( q ^ V ) . (68) \mathcal{E}_{\mathrm{train}}=\mathbb{E}_{\Omega}\left[\mathcal{M}(\Omega)\right]-\frac{1}{2\alpha}\operatorname{Tr}(\hat{q}V). \tag*{(68)} E train = E Ω [ M ( Ω ) ] − 2 α 1 Tr ( q ^ V ) . (68)
Bayes-optimal
In this section, we characterize the Bayes-optimal (BO) estimator y ^ B O ( X , D ) \hat{y}_{\mathrm{BO}}(X,\mathcal{D}) y ^ BO ( X , D ) , which minimizes the expected test squared error among all predictors based on the training dataset D \mathcal{D} D and the test input X X X . The data-generating model and priors are assumed known, while the planted spikes must be inferred from D \mathcal{D} D . The Bayes risk E B O \mathcal{E}_{\mathrm{BO}} E BO therefore acts as a benchmark providing a lower bound on the expected test error achievable by the attention model. Inferring the planted spikes can be reduced to low-rank matrix estimation, studied in Lesieur et al. [19 ] . For completeness, we provide a self-contained characterization of the Bayes-optimal estimator in our setting. Given the training dataset D = { X μ , y μ } μ = 1 N \mathcal{D}=\{X_{\mu},y_{\mu}\}_{\mu=1}^{N} D = { X μ , y μ } μ = 1 N , the expected test square error of the BO is
E B O = E X , y , D [ 1 2 D ∥ y − y ^ B O ( X , D ) ∥ 2 2 ] (69) \mathcal{E}_{\mathrm{BO}}=\mathbb{E}_{X,y,\mathcal{D}}\left[\frac{1}{2D}\left\|y-\hat{y}_{\mathrm{BO}}(X,\mathcal{D})\right\|_{2}^{2}\right] \tag*{(69)} E BO = E X , y , D [ 2 D 1 ∥ y − y ^ BO ( X , D ) ∥ 2 2 ] (69)
where the estimator y ^ B O ( X , D ) \hat{y}_{\mathrm{BO}}(X,\mathcal{D}) y ^ BO ( X , D ) is the posterior mean under the probabilistic model of § 3 :
y ^ B O ( X , D ) = E y [ y ∣ X , D ] = E ϵ [ X ϵ ∣ X , D ] = ∑ ℓ = 1 L P ( ℓ = ϵ ∣ X , D ) X ℓ . (70) \hat{y}_{\mathrm{BO}}(X,\mathcal{D})=\mathbb{E}_{y}\left[y\mid X,\mathcal{D}\right]=\mathbb{E}_{\epsilon}\left[X_{\epsilon}\mid X,\mathcal{D}\right]=\sum_{\ell=1}^{L}P(\ell=\epsilon\mid X,\mathcal{D})X_{\ell}. \tag*{(70)} y ^ BO ( X , D ) = E y [ y ∣ X , D ] = E ϵ [ X ϵ ∣ X , D ] = ℓ = 1 ∑ L P ( ℓ = ϵ ∣ X , D ) X ℓ . (70)
We can compute it using the Bayes formula
P ( ℓ = ϵ ∣ X , D ) = P ( ℓ = ϵ , X ∣ D ) P ( X ∣ D ) = P ( ℓ = ϵ , X ∣ D ) ∑ ℓ ′ = 1 L P ( ℓ ′ = ϵ , X ∣ D ) , (71) P(\ell=\epsilon\mid X,\mathcal{D})=\frac{P(\ell=\epsilon,X\mid\mathcal{D})}{P(X\mid\mathcal{D})}=\frac{P(\ell=\epsilon,X\mid\mathcal{D})}{\sum_{\ell'=1}^{L}P(\ell'=\epsilon,X\mid\mathcal{D})}, \tag*{(71)} P ( ℓ = ϵ ∣ X , D ) = P ( X ∣ D ) P ( ℓ = ϵ , X ∣ D ) = ∑ ℓ ′ = 1 L P ( ℓ ′ = ϵ , X ∣ D ) P ( ℓ = ϵ , X ∣ D ) , (71)
where the numerator is
P ( ℓ = ϵ , X ∣ D ) = ∫ d K d θ P ( X , ℓ = ϵ , θ , K ∣ D ) = ∫ d K d θ P ( X ∣ ℓ = ϵ , θ , K ) P ( ℓ = ϵ ) P ( θ ) P ( K ∣ D ) (72) \begin{aligned}
P(\ell=\epsilon,X\mid\mathcal{D})=\int dK\,d\theta\,P(X,\ell=\epsilon,\theta,K\mid\mathcal{D}) \\
&=\int dK\,d\theta\,P(X\mid\ell=\epsilon,\theta,K)P(\ell=\epsilon)P(\theta)P(K\mid\mathcal{D}) \tag*{(72)}
\end{aligned} P ( ℓ = ϵ , X ∣ D ) = ∫ d K d θ P ( X , ℓ = ϵ , θ , K ∣ D ) = ∫ d K d θ P ( X ∣ ℓ = ϵ , θ , K ) P ( ℓ = ϵ ) P ( θ ) P ( K ∣ D ) (72)
and, given the data generation process,
P ( X ∣ ℓ = ϵ , θ , K ) = 1 ( 2 π ) L D / 2 e X ℓ T K T θ D − 1 2 ∥ K T θ D ∥ 2 2 ∏ ℓ ′ = 1 L e − 1 2 ∥ X ℓ ′ ∥ 2 2 . (73) P(X\mid\ell=\epsilon,\theta,K)=\frac{1}{(2\pi)^{LD/2}}e^{X_{\ell}^{\mathsf{T}}\frac{K^{\mathsf{T}}\theta}{\sqrt{D}}-\frac{1}{2}\left\|\frac{K^{\mathsf{T}}\theta}{\sqrt{D}}\right\|_{2}^{2}}\prod_{\ell'=1}^{L}e^{-\frac{1}{2}\|X_{\ell'}\|_{2}^{2}}. \tag*{(73)} P ( X ∣ ℓ = ϵ , θ , K ) = ( 2 π ) L D /2 1 e X ℓ T D K T θ − 2 1 D K T θ 2 2 ℓ ′ = 1 ∏ L e − 2 1 ∥ X ℓ ′ ∥ 2 2 . (73)
Putting everything together, we get
y ^ B O ( X , D ) = ∑ ℓ = 1 L E K ∣ D E θ [ exp ( X ℓ T ( K T θ / D ) − ∥ K T θ / D ∥ 2 2 / 2 ) ] ∑ ℓ ′ = 1 L E K ∣ D E θ [ exp ( X ℓ ′ T ( K T θ / D ) − ∥ K T θ / D ∥ 2 2 / 2 ) ] X ℓ . (74) \hat{y}_{\mathrm{BO}}(X,\mathcal{D})=\sum_{\ell=1}^{L}\frac{\mathbb{E}_{K\mid\mathcal{D}}\mathbb{E}_{\theta}\left[\exp\left(X_{\ell}^{\mathsf{T}}\left(K^{\mathsf{T}}\theta/\sqrt{D}\right)-\left\|K^{\mathsf{T}}\theta/\sqrt{D}\right\|_{2}^{2}/2\right)\right]}{\sum_{\ell'=1}^{L}\mathbb{E}_{K\mid\mathcal{D}}\mathbb{E}_{\theta}\left[\exp\left(X_{\ell'}^{\mathsf{T}}\left(K^{\mathsf{T}}\theta/\sqrt{D}\right)-\left\|K^{\mathsf{T}}\theta/\sqrt{D}\right\|_{2}^{2}/2\right)\right]}X_{\ell}. \tag*{(74)} y ^ BO ( X , D ) = ℓ = 1 ∑ L ∑ ℓ ′ = 1 L E K ∣ D E θ [ exp ( X ℓ ′ T ( K T θ / D ) − K T θ / D 2 2 /2 ) ] E K ∣ D E θ [ exp ( X ℓ T ( K T θ / D ) − K T θ / D 2 2 /2 ) ] X ℓ . (74)
The remaining steps to obtain an expression for the estimator concern the average over the posterior P ( K ∣ D ) P(K\mid\mathcal{D}) P ( K ∣ D ) . We have
P ( K ∣ D ) = P K ( K ) P ( D ∣ K ) ∫ d K ′ P K ( K ′ ) P ( D ∣ K ′ ) . (75) P(K\mid\mathcal{D})=\frac{P_{K}(K)P(\mathcal{D}\mid K)}{\int dK'P_{K}(K')P(\mathcal{D}\mid K')}. \tag*{(75)} P ( K ∣ D ) = ∫ d K ′ P K ( K ′ ) P ( D ∣ K ′ ) P K ( K ) P ( D ∣ K ) . (75)
and using marginalization to isolate the data generating process,
P ( D ∣ K ) = ∏ μ = 1 N ∑ ℓ = 1 L ∫ d θ μ P θ ( θ μ ) P ( ℓ = ϵ μ ) P ( X μ , y μ ∣ K , θ μ , ϵ μ ) = exp ( − 1 2 ∑ μ , ℓ ∥ X μ , ℓ ∥ 2 ) L N ( 2 π ) N L D / 2 ∏ μ = 1 N E θ μ [ exp ( θ μ T K D y μ − θ μ T K K T θ μ 2 D ) ] . (76) \begin{aligned}
P(\mathcal{D}\mid K)=\prod_{\mu=1}^{N}\sum_{\ell=1}^{L}\int d\theta_{\mu}P_{\theta}(\theta_{\mu})P(\ell=\epsilon_{\mu})P(X_{\mu},y_{\mu}\mid K,\theta_{\mu},\epsilon_{\mu}) \\
&=\frac{\exp\left(-\frac{1}{2}\sum_{\mu,\ell}\lVert X_{\mu,\ell}\rVert^{2}\right)}{L^{N}(2\pi)^{NL D/2}}\prod_{\mu=1}^{N}\mathbb{E}_{\theta_{\mu}}\left[\exp\left(\frac{\theta_{\mu}^{\mathsf{T}}K}{\sqrt{D}}y_{\mu}-\frac{\theta_{\mu}^{\mathsf{T}}KK^{\mathsf{T}}\theta_{\mu}}{2D}\right)\right]. \tag*{(76)}
\end{aligned} P ( D ∣ K ) = μ = 1 ∏ N ℓ = 1 ∑ L ∫ d θ μ P θ ( θ μ ) P ( ℓ = ϵ μ ) P ( X μ , y μ ∣ K , θ μ , ϵ μ ) = L N ( 2 π ) N L D /2 exp ( − 2 1 ∑ μ , ℓ ∥ X μ , ℓ ∥ 2 ) μ = 1 ∏ N E θ μ [ exp ( D θ μ T K y μ − 2 D θ μ T K K T θ μ ) ] . (76)
Terms independent of K K K simplify in the numerator and denominator of the posterior, giving
P ( K ∣ D ) = P K ( K ) Z ( D ) ∏ μ = 1 N E θ μ [ exp ( θ μ T K D y μ − θ μ T K K T θ μ 2 D ) ] , (77) P(K\mid\mathcal{D})=\frac{P_{K}(K)}{\mathcal{Z}(\mathcal{D})}\prod_{\mu=1}^{N}\mathbb{E}_{\theta_{\mu}}\left[\exp\left(\frac{\theta_{\mu}^{\mathsf{T}}K}{\sqrt{D}}y_{\mu}-\frac{\theta_{\mu}^{\mathsf{T}}KK^{\mathsf{T}}\theta_{\mu}}{2D}\right)\right], \tag*{(77)} P ( K ∣ D ) = Z ( D ) P K ( K ) μ = 1 ∏ N E θ μ [ exp ( D θ μ T K y μ − 2 D θ μ T K K T θ μ ) ] , (77)
where we introduced the reduced partition function
Z ( D ) = ∫ d K P K ( K ) ∏ μ = 1 N E θ μ [ exp ( θ μ T K D y μ − θ μ T K K T θ μ 2 D ) ] . (78) \mathcal{Z}(\mathcal{D})=\int dK\,P_{K}(K)\prod_{\mu=1}^{N}\mathbb{E}_{\theta_{\mu}}\left[\exp\left(\frac{\theta_{\mu}^{\mathsf{T}}K}{\sqrt{D}}y_{\mu}-\frac{\theta_{\mu}^{\mathsf{T}}KK^{\mathsf{T}}\theta_{\mu}}{2D}\right)\right]. \tag*{(78)} Z ( D ) = ∫ d K P K ( K ) μ = 1 ∏ N E θ μ [ exp ( D θ μ T K y μ − 2 D θ μ T K K T θ μ ) ] . (78)
To compute the summary statistics of P ( K ∣ D ) P(K\mid\mathcal{D}) P ( K ∣ D ) we again resort to the replica method, computing the free entropy. The replicated partition function reads
E D [ Z n ] = ∫ d K ∗ P K ( K ∗ ) ∏ a = 1 n d K a P K ( K a ) ∏ μ = 1 N E θ μ ∗ , y μ ∣ K ∗ [ ∏ a = 1 n E θ μ a [ exp ( θ μ a T K a D y μ − θ μ a T K a K a T θ μ a 2 D ) ] ] = ∫ d K ∗ P K ( K ∗ ) ∏ a = 1 n d K a P K ( K a ) ∏ μ = 1 N E θ μ ∗ , { θ μ a } a = 1 n [ exp ( ∑ a θ μ a T K a K ∗ T θ μ ∗ D + ∑ a < b θ μ a T K a K b T θ μ b D ) ] . (79) \begin{aligned}
\mathbb{E}_{\mathcal{D}}\left[\mathcal{Z}^{n}\right]=\int dK^{\ast}P_{K}(K^{\ast})\prod_{a=1}^{n}dK^{a}P_{K}(K^{a})
\prod_{\mu=1}^{N}\mathbb{E}_{\theta_{\mu}^{\ast},y_{\mu}\mid K^{\ast}}\left[\prod_{a=1}^{n}\mathbb{E}_{\theta_{\mu}^{a}}\left[\exp\left(\frac{\theta_{\mu}^{a\mathsf{T}}K^{a}}{\sqrt{D}}y_{\mu}-\frac{\theta_{\mu}^{a\mathsf{T}}K^{a}K^{a\mathsf{T}}\theta_{\mu}^{a}}{2D}\right)\right]\right] \\
&=\int dK^{\ast}P_{K}(K^{\ast})\prod_{a=1}^{n}dK^{a}P_{K}(K^{a})
\prod_{\mu=1}^{N}\mathbb{E}_{\theta_{\mu^{\ast}},\{\theta_{\mu}^{a}\}_{a=1}^{n}}\left[\exp\left(\sum_{a}\frac{\theta_{\mu}^{a\mathsf{T}}K^{a}K^{\ast\mathsf{T}}\theta_{\mu}^{\ast}}{D}+\sum_{a<b}\frac{\theta_{\mu}^{a\mathsf{T}}K^{a}K^{b\mathsf{T}}\theta_{\mu}^{b}}{D}\right)\right]. \tag*{(79)}
\end{aligned} E D [ Z n ] = ∫ d K ∗ P K ( K ∗ ) a = 1 ∏ n d K a P K ( K a ) μ = 1 ∏ N E θ μ ∗ , y μ ∣ K ∗ [ a = 1 ∏ n E θ μ a [ exp ( D θ μ a T K a y μ − 2 D θ μ a T K a K a T θ μ a ) ] ] = ∫ d K ∗ P K ( K ∗ ) a = 1 ∏ n d K a P K ( K a ) μ = 1 ∏ N E θ μ ∗ , { θ μ a } a = 1 n [ exp ( a ∑ D θ μ a T K a K ∗ T θ μ ∗ + a < b ∑ D θ μ a T K a K b T θ μ b ) ] . (79)
where in the second line we used the fact that y μ = K ∗ T θ μ ∗ / D + z μ y_{\mu}=K^{\ast\mathsf{T}}\theta_{\mu}^{\ast}/\sqrt{D}+z_{\mu} y μ = K ∗ T θ μ ∗ / D + z μ with z μ ∼ N ( 0 , I D ) z_{\mu}\sim\mathcal{N}(0,I_{D}) z μ ∼ N ( 0 , I D ) and averaged over the gaussian noise. We introduce the summary statistics
m a = K a K ∗ T D ∈ R F × F , Q a b = K a K b T D ∈ R F × F . (80) m^{a}=\frac{K^{a}K^{\ast\mathsf{T}}}{D}\in\mathbb{R}^{F\times F},\qquad Q^{ab}=\frac{K^{a}K^{b\mathsf{T}}}{D}\in\mathbb{R}^{F\times F}. \tag*{(80)} m a = D K a K ∗ T ∈ R F × F , Q ab = D K a K b T ∈ R F × F . (80)
Assuming distinct signal strengths in the Gaussian model, these overlaps are defined with a consistent choice of signs for the latent spikes. Enforcing their definitions with Dirac deltas brings the replicated partition function in the following form:
E D [ Z n ] = ∫ ∏ a = 1 n d m a d m ^ a ∏ a , b = 1 n d Q a b d Q ^ a b e − D 2 ∑ a = 1 n Tr ( m ^ a T m a ) + D 2 ∑ a , b = 1 n Tr ( Q ^ a b Q a b ) ∫ d K ∗ P K ( K ∗ ) ∏ a = 1 n d K a P K ( K a ) e ∑ a = 1 n Tr ( m ^ a T K a K ∗ T ) − 1 2 ∑ a , b = 1 n Tr ( Q ^ a b T K a K b T ) [ ∫ d θ ∗ P θ ( θ ∗ ) ∏ a = 1 n d θ a P θ ( θ a ) e ∑ a = 1 n θ a T m a θ ∗ + ∑ a < b θ a T Q a b θ b ] α D . (81) \mathbb{E}_{\mathcal{D}}\left[\mathcal{Z}^{n}\right]=\int\prod_{a=1}^{n}dm^{a}d\hat{m}^{a}\prod_{a,b=1}^{n}dQ^{ab}d\hat{Q}^{ab}\,
e^{-\frac{D}{2}\sum_{a=1}^{n}\operatorname{Tr}(\hat{m}^{a\mathsf{T}}m^{a})+\frac{D}{2}\sum_{a,b=1}^{n}\operatorname{Tr}(\hat{Q}^{ab}Q^{ab})}
\int dK^{\ast}P_{K}(K^{\ast})\prod_{a=1}^{n}dK^{a}P_{K}(K^{a})e^{\sum_{a=1}^{n}\operatorname{Tr}(\hat{m}^{a\mathsf{T}}K^{a}K^{\ast\mathsf{T}})-\frac{1}{2}\sum_{a,b=1}^{n}\operatorname{Tr}(\hat{Q}^{ab\mathsf{T}}K^{a}K^{b\mathsf{T}})}
\left[\int d\theta^{\ast}P_{\theta}(\theta^{\ast})\prod_{a=1}^{n}d\theta^{a}P_{\theta}(\theta^{a})e^{\sum_{a=1}^{n}\theta^{a\mathsf{T}}m^{a}\theta^{\ast}+\sum_{a<b}\theta^{a\mathsf{T}}Q^{ab}\theta^{b}}\right]^{\alpha D}. \tag*{(81)} E D [ Z n ] = ∫ a = 1 ∏ n d m a d m ^ a a , b = 1 ∏ n d Q ab d Q ^ ab e − 2 D ∑ a = 1 n Tr ( m ^ a T m a ) + 2 D ∑ a , b = 1 n Tr ( Q ^ ab Q ab ) ∫ d K ∗ P K ( K ∗ ) a = 1 ∏ n d K a P K ( K a ) e ∑ a = 1 n Tr ( m ^ a T K a K ∗ T ) − 2 1 ∑ a , b = 1 n Tr ( Q ^ ab T K a K b T ) [ ∫ d θ ∗ P θ ( θ ∗ ) a = 1 ∏ n d θ a P θ ( θ a ) e ∑ a = 1 n θ a T m a θ ∗ + ∑ a < b θ a T Q ab θ b ] α D . (81)
We decomposed the replicated free entropy into the trace Ψ t \Psi_t Ψ t , entropic Ψ K \Psi_K Ψ K and energetic Ψ y \Psi_y Ψ y potentials. One again assumes the replica symmetric ansatz
m a = m , m ^ a = m ^ , (82) m^a=m,\qquad\hat{m}^a=\hat{m}, \tag*{(82)} m a = m , m ^ a = m ^ , (82)
Q a b = q δ a ≠ b + Q δ a b , Q ^ a b = − q ^ δ a ^ ≠ b ^ + Q ^ δ a ^ b ^ . (83) Q^{ab}=q\delta_{a\ne b}+Q\delta_{ab},\qquad\hat{Q}^{ab}=-\hat{q}\delta_{\hat{a}\ne\hat{b}}+\hat{Q}\delta_{\hat{a}\hat{b}}. \tag*{(83)} Q ab = q δ a = b + Q δ ab , Q ^ ab = − q ^ δ a ^ = b ^ + Q ^ δ a ^ b ^ . (83)
and takes the limit n → 0 n\to0 n → 0 , reaching
Ψ t = − Tr ( m ^ T m ) + 1 2 Tr ( Q ^ Q ) + 1 2 Tr ( q ^ T q ) , (84) \Psi_t=-\operatorname{Tr}(\hat{m}^{\mathsf{T}}m)+\frac{1}{2}\operatorname{Tr}(\hat{Q}Q)+\frac{1}{2}\operatorname{Tr}(\hat{q}^{\mathsf{T}}q), \tag*{(84)} Ψ t = − Tr ( m ^ T m ) + 2 1 Tr ( Q ^ Q ) + 2 1 Tr ( q ^ T q ) , (84)
Ψ K = − 1 2 log ( det ( I F + Q ^ + q ^ ) ) + 1 2 Tr ( ( I F + Q ^ + q ^ ) − 1 ( m ^ m T + q ^ ) ) , (85) \Psi_K=-\frac{1}{2}\log\left(\det(\mathbb{I}_F+\hat{Q}+\hat{q})\right)+\frac{1}{2}\operatorname{Tr}\left((\mathbb{I}_F+\hat{Q}+\hat{q})^{-1}(\hat{m}m^{\mathsf{T}}+\hat{q})\right), \tag*{(85)} Ψ K = − 2 1 log ( det ( I F + Q ^ + q ^ ) ) + 2 1 Tr ( ( I F + Q ^ + q ^ ) − 1 ( m ^ m T + q ^ ) ) , (85)
Ψ y = E θ ∗ , ξ [ log ( E θ [ exp ( θ T ( m θ ∗ + q 1 / 2 ξ ) − 1 2 θ T q θ ) ] ) ] . (86) \Psi_y=\mathbb{E}_{\theta^*,\xi}\left[\log\left(\mathbb{E}_{\theta}\left[\exp\left(\theta^{\mathsf{T}}\left(m\theta^*+q^{1/2}\xi\right)-\frac{1}{2}\theta^{\mathsf{T}}q\theta\right)\right]\right)\right]. \tag*{(86)} Ψ y = E θ ∗ , ξ [ log ( E θ [ exp ( θ T ( m θ ∗ + q 1/2 ξ ) − 2 1 θ T q θ ) ] ) ] . (86)
with ξ ∼ N ( 0 , I F ) \xi\sim\mathcal{N}(0,\mathbb{I}_F) ξ ∼ N ( 0 , I F ) . A main simplification, known as Nishimori condition, follows from the exchangeability, conditional on the training data, of the planted parameters and posterior replicas: we have m = q , Q = I F , m ^ = q ^ m=q,Q=\mathbb{I}_F,\hat{m}=\hat{q} m = q , Q = I F , m ^ = q ^ , also leading to Q ^ = 0 \hat{Q}=0 Q ^ = 0 . Therefore, the free entropy reads
Φ = extr q , q ^ [ − 1 2 Tr ( q ^ q ) + 1 2 Tr ( q ^ ) − 1 2 log ( det ( I F + q ^ ) ) + α E θ ∗ , ξ [ log ( E θ [ exp ( θ T ( q θ ∗ + q 1 / 2 ξ ) − 1 2 θ T q θ ) ] ) ] ] . (87) \Phi=\underset{q,\hat{q}}{\operatorname{extr}}\left[-\frac{1}{2}\operatorname{Tr}(\hat{q}q)+\frac{1}{2}\operatorname{Tr}(\hat{q})-\frac{1}{2}\log\left(\det(\mathbb{I}_F+\hat{q})\right)+\alpha\mathbb{E}_{\theta^*,\xi}\left[\log\left(\mathbb{E}_{\theta}\left[\exp\left(\theta^{\mathsf{T}}\left(q\theta^*+q^{1/2}\xi\right)-\frac{1}{2}\theta^{\mathsf{T}}q\theta\right)\right]\right)\right]\right]. \tag*{(87)} Φ = q , q ^ extr [ − 2 1 Tr ( q ^ q ) + 2 1 Tr ( q ^ ) − 2 1 log ( det ( I F + q ^ ) ) + α E θ ∗ , ξ [ log ( E θ [ exp ( θ T ( q θ ∗ + q 1/2 ξ ) − 2 1 θ T q θ ) ] ) ] ] . (87)
Thus, for independent posterior samples K a ∼ P ( K ∣ D ) K^a\sim P(K\mid D) K a ∼ P ( K ∣ D ) , extremization of the free entropy (87) gives the summary statistics
K a K ∗ T D = q , K a K b T D = q + ( I F − q ) δ a b . (88) \frac{K^aK^{*\mathsf{T}}}{D}=q,\qquad\frac{K^aK^{b\mathsf{T}}}{D}=q+(\mathbb{I}_F-q)\delta_{ab}. \tag*{(88)} D K a K ∗ T = q , D K a K b T = q + ( I F − q ) δ ab . (88)
Given a new test sample X \mathbf{X} X with, by definition,
X ℓ = δ ℓ ϵ K ∗ T θ ∗ D + z ℓ (89) X_\ell=\delta_{\ell\epsilon}\frac{K^{*\mathsf{T}}\theta^*}{\sqrt{D}}+z_\ell \tag*{(89)} X ℓ = δ ℓ ϵ D K ∗ T θ ∗ + z ℓ (89)
where z ℓ ∼ N ( 0 , I D ) z_\ell\sim\mathcal{N}(0,\mathbb{I}_D) z ℓ ∼ N ( 0 , I D ) and θ ∗ ∼ P θ \theta^*\sim P_\theta θ ∗ ∼ P θ , the law of the projections is determined by the summary statistics
K a X ℓ D ∼ δ ℓ ϵ q θ ∗ + q 1 / 2 ξ ℓ + ( I F − q ) 1 / 2 η ℓ a (90) \frac{K^aX_\ell}{\sqrt{D}}\sim\delta_{\ell\epsilon}q\theta^*+q^{1/2}\xi_\ell+(\mathbb{I}_F-q)^{1/2}\eta_\ell^a \tag*{(90)} D K a X ℓ ∼ δ ℓ ϵ q θ ∗ + q 1/2 ξ ℓ + ( I F − q ) 1/2 η ℓ a (90)
with ξ ℓ , η ℓ a ∼ N ( 0 , I F ) \xi_\ell,\eta_\ell^a\sim\mathcal{N}(0,\mathbb{I}_F) ξ ℓ , η ℓ a ∼ N ( 0 , I F ) . Going back to the evaluation of the BO estimator, the posterior average in (74) can then be written
E K ∣ D E θ [ e θ T K X ℓ D − 1 2 θ T K K T D θ ] = E θ E η [ e θ T ( δ ℓ ϵ q θ ∗ + q 1 / 2 ξ ℓ ) + θ T ( I F − q ) 1 / 2 η − 1 2 θ T θ ] (91) \mathbb{E}_{K\mid D}\mathbb{E}_{\theta}\left[e^{\theta^{\mathsf{T}}\frac{KX_\ell}{\sqrt{D}}-\frac{1}{2}\theta^{\mathsf{T}}\frac{KK^{\mathsf{T}}}{D}\theta}\right]=\mathbb{E}_{\theta}\mathbb{E}_{\eta}\left[e^{\theta^{\mathsf{T}}(\delta_{\ell\epsilon}q\theta^*+q^{1/2}\xi_\ell)+\theta^{\mathsf{T}}(\mathbb{I}_F-q)^{1/2}\eta-\frac{1}{2}\theta^{\mathsf{T}}\theta}\right] \tag*{(91)} E K ∣ D E θ [ e θ T D K X ℓ − 2 1 θ T D K K T θ ] = E θ E η [ e θ T ( δ ℓ ϵ q θ ∗ + q 1/2 ξ ℓ ) + θ T ( I F − q ) 1/2 η − 2 1 θ T θ ] (91)
= E θ [ e θ T ( δ ℓ ϵ q θ ∗ + q 1 / 2 ξ ℓ ) − 1 2 θ T q θ ] . (92) =\mathbb{E}_{\theta}\left[e^{\theta^{\mathsf{T}}(\delta_{\ell\epsilon}q\theta^*+q^{1/2}\xi_\ell)-\frac{1}{2}\theta^{\mathsf{T}}q\theta}\right]. \tag*{(92)} = E θ [ e θ T ( δ ℓ ϵ q θ ∗ + q 1/2 ξ ℓ ) − 2 1 θ T q θ ] . (92)
Fixing the structured token ϵ = 1 \epsilon=1 ϵ = 1 , giving y = X 1 y=X_1 y = X 1 without loss of generality, the BO error (69) can then be expressed as
E B O = E X , D [ 1 2 D ∥ X 1 − y ^ B O ( X , D ) ∥ 2 2 ] = E θ ∗ , { ξ ℓ } ℓ = 1 L [ 1 2 D ∥ X 1 − ∑ ℓ = 1 L p ℓ ∑ ℓ ′ = 1 L p ℓ ′ X ℓ ∥ 2 2 ] . (93) \mathcal{E}_{\mathrm{BO}}=\mathbb{E}_{X,D}\left[\frac{1}{2D}\left\|X_1-\hat{y}_{\mathrm{BO}}(X,D)\right\|_2^2\right]=\mathbb{E}_{\theta^*,\{\xi_\ell\}_{\ell=1}^{L}}\left[\frac{1}{2D}\left\|X_1-\sum_{\ell=1}^{L}\frac{p_\ell}{\sum_{\ell'=1}^{L}p_{\ell'}}X_\ell\right\|_2^2\right]. \tag*{(93)} E BO = E X , D [ 2 D 1 ∥ X 1 − y ^ BO ( X , D ) ∥ 2 2 ] = E θ ∗ , { ξ ℓ } ℓ = 1 L 2 D 1 X 1 − ℓ = 1 ∑ L ∑ ℓ ′ = 1 L p ℓ ′ p ℓ X ℓ 2 2 . (93)
Expanding the square, using X ℓ T X ℓ ′ / D → δ ℓ ℓ ′ X_\ell^{\mathsf{T}}X_{\ell'}/D\to\delta_{\ell\ell'} X ℓ T X ℓ ′ / D → δ ℓ ℓ ′ and E θ ∗ , { ξ ℓ } [ ∑ ℓ p ℓ 2 / ( ∑ j p j ) 2 ] = E θ ∗ , { ξ ℓ } [ p 1 / ∑ j p j ] \mathbb{E}_{\theta^*,\{\xi_\ell\}}\left[\sum_{\ell}p_\ell^2/(\sum_jp_j)^2\right]=\mathbb{E}_{\theta^*,\{\xi_\ell\}}\left[p_1/\sum_jp_j\right] E θ ∗ , { ξ ℓ } [ ∑ ℓ p ℓ 2 / ( ∑ j p j ) 2 ] = E θ ∗ , { ξ ℓ } [ p 1 / ∑ j p j ] , we reach
E B O = 1 2 E θ ∗ , { ξ ℓ } ℓ = 1 L [ 1 − p 1 ∑ ℓ = 1 L p ℓ ] , p ℓ = E θ [ e θ T ( δ ℓ ϵ q θ ∗ + q 1 / 2 ξ ℓ ) − 1 2 θ T q θ ] . (94) \mathcal{E}_{\mathrm{BO}}=\frac{1}{2}\mathbb{E}_{\theta^*,\{\xi_\ell\}_{\ell=1}^{L}}\left[1-\frac{p_1}{\sum_{\ell=1}^{L}p_\ell}\right],\qquad p_\ell=\mathbb{E}_{\theta}\left[e^{\theta^{\mathsf{T}}(\delta_{\ell\epsilon}q\theta^*+q^{1/2}\xi_\ell)-\frac{1}{2}\theta^{\mathsf{T}}q\theta}\right]. \tag*{(94)} E BO = 2 1 E θ ∗ , { ξ ℓ } ℓ = 1 L [ 1 − ∑ ℓ = 1 L p ℓ p 1 ] , p ℓ = E θ [ e θ T ( δ ℓ ϵ q θ ∗ + q 1/2 ξ ℓ ) − 2 1 θ T q θ ] . (94)
Flipping spike model
In the case of the flipping spike model where
θ = ( ν 1 s ν 2 ) , θ ∗ = ( ν 1 s ∗ ν 2 ) , P ( s = ± 1 ) = P ( s ∗ = ± 1 ) = 1 2 , (95) \theta= \begin{pmatrix} \sqrt{\nu_1} \\ s\sqrt{\nu_2} \end{pmatrix}, \quad\theta^* = \begin{pmatrix} \sqrt{\nu_1} \\ s^*\sqrt{\nu_2} \end{pmatrix}, \quad P(s = \pm1) = P(s^* = \pm1) = \frac{1}{2}, \tag*{(95)} θ = ( ν 1 s ν 2 ) , θ ∗ = ( ν 1 s ∗ ν 2 ) , P ( s = ± 1 ) = P ( s ∗ = ± 1 ) = 2 1 , (95)
averaging over the random variables s s s , s ∗ s^* s ∗ , and using E ξ [ ( q 2 1 / ξ 2 ) 2 ] = q 22 \mathbb{E}_{\xi}\left[\left(q_{2}^{1}/\xi_{2}\right)^2\right] = q_{22} E ξ [ ( q 2 1 / ξ 2 ) 2 ] = q 22 , we reach
Φ = extr q , q ^ [ − 1 2 Tr ( q ^ q ) + 1 2 Tr ( q ^ ) − 1 2 log ( det ( I F + q ^ ) ) + α ν 1 q 11 − ν 2 q 22 2 + α E z [ log ( cosh ( ν 2 q 22 + ν 2 q 22 z ) ) ] ] (96) \Phi= \underset{q,\hat{q}}{\operatorname{extr}}\left[-\frac{1}{2}\operatorname{Tr}(\hat{q}q) + \frac{1}{2}\operatorname{Tr}(\hat{q}) - \frac{1}{2}\log\left(\det(\mathbb{I}_{F}+\hat{q})\right)
+ \alpha\frac{\nu_1q_{11}-\nu_2q_{22}}{2} + \alpha\mathbb{E}_{z}\left[\log\left(\cosh\left(\nu_2q_{22}+\sqrt{\nu_2q_{22}}z\right)\right)\right]\right] \tag*{(96)} Φ = q , q ^ extr [ − 2 1 Tr ( q ^ q ) + 2 1 Tr ( q ^ ) − 2 1 log ( det ( I F + q ^ ) ) + α 2 ν 1 q 11 − ν 2 q 22 + α E z [ log ( cosh ( ν 2 q 22 + ν 2 q 22 z ) ) ] ] (96)
where we introduced z ∼ N ( 0 , 1 ) z \sim\mathcal{N}(0,1) z ∼ N ( 0 , 1 ) . The extremization of the free entropy then leads to the following self-consistent equations:
q 11 = q ^ 11 1 + q ^ 11 q 22 = q ^ 22 1 + q ^ 22 q ^ 11 = α ν 1 q ^ 22 = α ν 2 E z [ tanh 2 ( ν 2 q 22 + ν 2 q 22 z ) ] . (97) \begin{aligned}
q_{11} &= \frac{\hat{q}_{11}}{1+\hat{q}_{11}} \\
q_{22} &= \frac{\hat{q}_{22}}{1+\hat{q}_{22}}
\end{aligned}
\qquad
\begin{aligned}
\hat{q}_{11} &= \alpha\nu_1 \\
\hat{q}_{22} &= \alpha\nu_2\mathbb{E}_{z}\left[\tanh^2\left(\nu_2q_{22}+\sqrt{\nu_2q_{22}}z\right)\right]. \tag*{(97)}
\end{aligned} q 11 q 22 = 1 + q ^ 11 q ^ 11 = 1 + q ^ 22 q ^ 22 q ^ 11 q ^ 22 = α ν 1 = α ν 2 E z [ tanh 2 ( ν 2 q 22 + ν 2 q 22 z ) ] . (97)
Similarly, expliciting the expression of P θ P_{\theta} P θ gives the BO error for the flipping spike model:
E B O = 1 2 E { z ℓ } ℓ = 1 L [ 1 − e ν 1 q 11 + ν 1 q 11 z 11 cosh ( ν 2 q 22 + ν 2 q 22 z 12 ) ∑ ℓ = 1 L e δ ℓ 1 ν 1 q 11 + ν 1 q 11 z ℓ 1 cosh ( δ ℓ 1 ν 2 q 22 + ν 2 q 22 z ℓ 2 ) ] , (98) \mathcal{E}_{\mathrm{BO}} = \frac{1}{2}\mathbb{E}_{\{z_{\ell}\}_{\ell=1}^{L}}\left[1-\frac{e^{\nu_1q_{11}+\sqrt{\nu_1q_{11}}z_{11}}\cosh\left(\nu_2q_{22}+\sqrt{\nu_2q_{22}}z_{12}\right)}{\sum_{\ell=1}^{L}e^{\delta_{\ell1}\nu_1q_{11}+\sqrt{\nu_1q_{11}}z_{\ell1}}\cosh\left(\delta_{\ell1}\nu_2q_{22}+\sqrt{\nu_2q_{22}}z_{\ell2}\right)}\right], \tag*{(98)} E BO = 2 1 E { z ℓ } ℓ = 1 L [ 1 − ∑ ℓ = 1 L e δ ℓ 1 ν 1 q 11 + ν 1 q 11 z ℓ 1 cosh ( δ ℓ 1 ν 2 q 22 + ν 2 q 22 z ℓ 2 ) e ν 1 q 11 + ν 1 q 11 z 11 cosh ( ν 2 q 22 + ν 2 q 22 z 12 ) ] , (98)
with z ℓ ∼ N ( 0 , I 2 ) z_{\ell} \sim\mathcal{N}(0,\mathbb{I}_2) z ℓ ∼ N ( 0 , I 2 ) . In Figure 5 , we compare the performances of the BO estimator in recovering the spikes, with ρ f B O = q f f \rho_f^{\mathrm{BO}} = q_{ff} ρ f BO = q f f and E B O \mathcal{E}_{\mathrm{BO}} E BO given by the solutions of (99-100), to the ones of minimizer of the empirical risk. For comparison with the results of § 4 , we quantify the recovery of planted features independently from weight norm in ERM with the normalized overlaps
Figure 5. Bayes-optimal estimator for the flipping spike model: ν 1 = 0.1 \nu_1 = 0.1 ν 1 = 0.1 , ν 2 = 2.0 \nu_2 = 2.0 ν 2 = 2.0 , L = 10 L = 10 L = 10 , H = 2 H = 2 H = 2 , λ = 0.2 \lambda= 0.2 λ = 0.2 . Solid lines correspond to theoretical predictions (Res. 3.1, App. § 11 .§ 4 ). Markers with errorbars correspond to training the model (§ 3 ) with L-BFGS from random initialization in dimension D = 2000 D = 2000 D = 2000 across ten seeds. Left: Test error E \mathcal{E} E and training loss E t r a i n \mathcal{E}_{\mathrm{train}} E train of the attention model, test error E B O \mathcal{E}_{\mathrm{BO}} E BO of the Bayes-optimal estimator. Center: Normalized head-feature overlap ρ 1 E R M \rho_1^{\mathrm{ERM}} ρ 1 ERM of the attention model and overlap ρ 1 B O \rho_1^{\mathrm{BO}} ρ 1 BO of the Bayes-optimal estimator. Right: Normalized head-feature overlap ρ 2 E R M \rho_2^{\mathrm{ERM}} ρ 2 ERM of the attention model and overlap ρ 2 B O \rho_2^{\mathrm{BO}} ρ 2 BO of the Bayes-optimal estimator. Grey and blue identify the permutation-symmetric (PS) and specialized (SPEC) phases. Vertical lines mark the specialization threshold α c s p e c \alpha_{\mathrm{c}}^{\mathrm{spec}} α c spec .
ρ f E R M = max h ( m h f E R M ) 2 q h h E R M (99) \rho_f^{\mathrm{ERM}} = \max_h \frac{\left(m_{hf}^{\mathrm{ERM}}\right)^2}{q_{hh}^{\mathrm{ERM}}} \tag*{(99)} ρ f ERM = h max q hh ERM ( m h f ERM ) 2 (99)
where we note m E R M m^{\mathrm{ERM}} m ERM and q E R M q^{\mathrm{ERM}} q ERM the summary statistics from Result 3.1.
Non-isotropic Gaussian model
In the case of the non-isotropic Gaussian model where
θ , θ ∗ ∼ N ( 0 , Λ ) , Λ = diag ( ν 1 , … , ν F ) , (100) \theta,\theta^* \sim\mathcal{N}(0,\Lambda), \qquad\Lambda= \operatorname{diag}(\nu_1,\ldots,\nu_F), \tag*{(100)} θ , θ ∗ ∼ N ( 0 , Λ ) , Λ = diag ( ν 1 , … , ν F ) , (100)
averaging over the gaussian variables θ , θ ∗ , ξ \theta,\theta^*,\xi θ , θ ∗ , ξ , we reach
Φ = extr q , q ^ [ − 1 2 Tr ( q ^ q ) + 1 2 Tr ( q ^ ) − 1 2 log ( det ( I F + q ^ ) ) + α 2 Tr ( Λ q ) − α 2 log ( det ( I F + Λ q ) ) ] . (101) \Phi= \underset{q,\hat{q}}{\operatorname{extr}}\left[-\frac{1}{2}\operatorname{Tr}(\hat{q}q)+\frac{1}{2}\operatorname{Tr}(\hat{q})-\frac{1}{2}\log\left(\det(I_F+\hat{q})\right)+\frac{\alpha}{2}\operatorname{Tr}(\Lambda q)-\frac{\alpha}{2}\log\left(\det(I_F+\Lambda q)\right)\right]. \tag*{(101)} Φ = q , q ^ extr [ − 2 1 Tr ( q ^ q ) + 2 1 Tr ( q ^ ) − 2 1 log ( det ( I F + q ^ ) ) + 2 α Tr ( Λ q ) − 2 α log ( det ( I F + Λ q ) ) ] . (101)
The extremization of the free entropy then leads to the following self-consistent equations:
q = I F − ( I F + q ^ ) − 1 q ^ = α [ Λ − ( I F + Λ q ) − 1 Λ ] , (102) \begin{aligned}
q &= I_F-(I_F+\hat{q})^{-1}\\
\hat{q} &= \alpha\left[\Lambda-(I_F+\Lambda q)^{-1}\Lambda\right], \tag*{(102)}
\end{aligned} q q ^ = I F − ( I F + q ^ ) − 1 = α [ Λ − ( I F + Λ q ) − 1 Λ ] , (102)
with explicit solutions
q f f = { 0 , if α ν f 2 ≤ 1 , α ν f 2 − 1 ν f ( α ν f + 1 ) , if α ν f 2 > 1 , (103) q_{ff} =
\begin{cases}
0, & \text{if } \alpha\nu_f^2 \le1,\\
\frac{\alpha\nu_f^2-1}{\nu_f(\alpha\nu_f+1)}, & \text{if } \alpha\nu_f^2 > 1,
\end{cases} \tag*{(103)} q f f = { 0 , ν f ( α ν f + 1 ) α ν f 2 − 1 , if α ν f 2 ≤ 1 , if α ν f 2 > 1 , (103)
and q h f = 0 q_{hf}=0 q h f = 0 for h ≠ f h\ne f h = f . The BO error for the non-isotropic Gaussian model is
E B O = 1 2 E { z ℓ } ℓ = 1 L [ 1 − exp ( 1 2 ∑ f = 1 F ν f q f f z 1 2 ) exp ( 1 2 ∑ f = 1 F ν f q f f z 1 2 ) + ∑ ℓ = 2 L exp ( 1 2 ∑ f = 1 F ν f q f f 1 + ν f q f f z ℓ 2 ) ] , (104) \mathcal{E}_{\mathrm{BO}}=\frac{1}{2}\mathbb{E}_{\{z_\ell\}_{\ell=1}^{L}}\left[1-\frac{\exp\left(\frac{1}{2}\sum_{f=1}^{F}\nu_fq_{ff}z_1^2\right)}{\exp\left(\frac{1}{2}\sum_{f=1}^{F}\nu_fq_{ff}z_1^2\right)+\sum_{\ell=2}^{L}\exp\left(\frac{1}{2}\sum_{f=1}^{F}\frac{\nu_fq_{ff}}{1+\nu_fq_{ff}}z_\ell^2\right)}\right], \tag*{(104)} E BO = 2 1 E { z ℓ } ℓ = 1 L 1 − exp ( 2 1 ∑ f = 1 F ν f q f f z 1 2 ) + ∑ ℓ = 2 L exp ( 2 1 ∑ f = 1 F 1 + ν f q f f ν f q f f z ℓ 2 ) exp ( 2 1 ∑ f = 1 F ν f q f f z 1 2 ) , (104)
with z ℓ ∼ N ( 0 , I F ) z_\ell\sim\mathcal{N}(0,I_F) z ℓ ∼ N ( 0 , I F ) . In Figure 6 , we compare the performances of the BO estimator, with ρ f B O = q f f \rho_f^{\mathrm{BO}}=q_{ff} ρ f BO = q f f and E B O \mathcal{E}_{\mathrm{BO}} E BO given by the solutions of (105-106), to the ones of minimizer of the empirical risk. For comparison with the results of § 4 , we introduce the normalized overlaps
Figure 6. Bayes-optimal estimator for the non-isotropic Gaussian model: ν 1 = 5.0 \nu_1 = 5.0 ν 1 = 5.0 , ν 2 = 4.0 \nu_2 = 4.0 ν 2 = 4.0 , L = 5 L = 5 L = 5 , H = 4 H = 4 H = 4 , λ = 0.2 \lambda= 0.2 λ = 0.2 . Solid lines correspond to theoretical predictions (Res. 3.1, App. § 11 .§ 4 ). Markers with errorbars correspond to training the model (§ 3 ) with L-BFGS from random initialization in dimension D = 2000 D = 2000 D = 2000 across ten seeds. Left: Test error E \mathcal{E} E and training loss E t r a i n \mathcal{E}_{\mathrm{train}} E train of the attention model, test error E B O \mathcal{E}_{\mathrm{BO}} E BO of the Bayes-optimal estimator. Center: Normalized head-feature overlap ρ 1 E R M \rho_1^{\mathrm{ERM}} ρ 1 ERM of the attention model and overlap ρ 1 B O \rho_1^{\mathrm{BO}} ρ 1 BO of the Bayes-optimal estimator. Right: Normalized head-feature overlap ρ 2 E R M \rho_2^{\mathrm{ERM}} ρ 2 ERM of the attention model and overlap ρ 2 B O \rho_2^{\mathrm{BO}} ρ 2 BO of the Bayes-optimal estimator. Grey, light blue and darker blue identify the permutation-symmetric (PS) and successive specialized (1-SPEC, 2-SPEC) phases, respectively. Vertical dash-dotted lines mark the specialization thresholds α c ( 1 ) \alpha_{\mathrm{c}}^{(1)} α c ( 1 ) and α c ( 2 ) \alpha_{\mathrm{c}}^{(2)} α c ( 2 ) .
ρ f E R M = max h ( m h f E R M ) 2 q h h E R M (105) \rho_f^{\mathrm{ERM}}=\max_h\frac{(m_{hf}^{\mathrm{ERM}})^2}{q_{hh}^{\mathrm{ERM}}} \tag*{(105)} ρ f ERM = h max q hh ERM ( m h f ERM ) 2 (105)
where we note m E R M m^{\mathrm{ERM}} m ERM and q E R M q^{\mathrm{ERM}} q ERM the summary statistics from Result 3.1.
Model details and supplementary figures
Flipping spike model
In the flipping spike model defined in § 3 , a constant latent direction is learnable without head specialization while a flipping direction requires specialized heads to be used in the retrieval task. The signal strengths ( ν 1 , ν 2 ) (\nu_1,\nu_2) ( ν 1 , ν 2 ) can be parametrized as
ν t o t = ν 1 + ν 2 , δ = ν 2 ν 1 + ν 2 , (106) \nu_{\mathrm{tot}} = \nu_1 + \nu_2,\qquad\delta= \frac{\nu_2}{\nu_1+\nu_2}, \tag*{(106)} ν tot = ν 1 + ν 2 , δ = ν 1 + ν 2 ν 2 , (106)
to control total signal strength ν t o t \nu_{\mathrm{tot}} ν tot and flipping ratio δ \delta δ . More total signal facilitates the retrieval task, while larger flipping ratio increases the importance of specialization. For ν 2 = 0 \nu_2 = 0 ν 2 = 0 , task requires no head specialization, and no phase transition occurs. For ν 1 = 0 \nu_1 = 0 ν 1 = 0 , there is no constant direction and specialization is necessary for generalization, as in the non-isotropic Gaussian model. In Figure 7 we present the effect of the relative importance of the two features on specialization and performances.
Figure 7. Influence of signal composition on head specialization in the flipping spike model: ν t o t = 4 \nu_{\mathrm{tot}} = 4 ν tot = 4 , L = 10 L = 10 L = 10 , H = 2 H = 2 H = 2 , λ = 0.2 \lambda= 0.2 λ = 0.2 . Black solid lines correspond to theoretical predictions (Res. 3.1). Markers with error bars correspond to training the model (§ 3 ) with L-BFGS from random initialization in dimension D = 2000 D = 2000 D = 2000 across ten seeds. Left: Phase diagram in sample complexity α \alpha α and flipping ratio δ \delta δ . Phase boundaries are obtained by stability analysis of the different solutions (App. § 13 ). The red horizontal line at δ = 0.5 \delta= 0.5 δ = 0.5 corresponding to ν 1 = ν 2 = 2 \nu_1 = \nu_2 = 2 ν 1 = ν 2 = 2 , selects the cut shown in the other panels. Center: Test error E \mathcal{E} E and training error E t r a i n \mathcal{E}_{\mathrm{train}} E train . Right: Norms of the head–feature overlaps ∥ m : 1 ∥ 2 \lVert m_{:1}\rVert_2 ∥ m : 1 ∥ 2 and ∥ m : 2 ∥ 2 \lVert m_{:2}\rVert_2 ∥ m : 2 ∥ 2 . Vertical dash-dotted lines mark the specialization threshold α c s p e c \alpha^{\mathrm{spec}}_{\mathrm{c}} α c spec along the selected cut.
Non-isotropic Gaussian model
In Figure 8 we present additional figures for the non-isotropic Gaussian model, notably parametric curves for the head–feature overlaps. In Figure 9 we present the same results for isotropic Gaussian distribution of the weights ( ν 1 = ν 2 ) (\nu_1 = \nu_2) ( ν 1 = ν 2 ) .
Figure 8. Head-specialization phase transitions in the non-isotropic Gaussian model: ν 1 = 5.0 \nu_1 = 5.0 ν 1 = 5.0 , ν 2 = 4.0 \nu_2 = 4.0 ν 2 = 4.0 , L = 5 L = 5 L = 5 , H = 4 H = 4 H = 4 , λ = 0.2 \lambda= 0.2 λ = 0.2 . Black solid lines correspond to theoretical predictions (Res. 3.1). Markers with error bars correspond to training the model (§ 3 ) with L-BFGS from random initialization in dimension D = 4000 D = 4000 D = 4000 across ten seeds. Left: Head-feature overlaps (m : 2 , m : 1 m_{:2},m_{:1} m : 2 , m : 1 ) parametrized by sample complexity. Grey ellipse indicates the distribution anisotropy of possible draws of the planted spike k ^ \hat{k} k ^ . Center: Test error E \mathcal{E} E and training error E t r a i n \mathcal{E}_{\mathrm{train}} E train . Right: Head-feature overlaps m h f m_{hf} m h f for all heads and both latent features. Grey, light blue and darker blue identify the permutation-symmetric (PS) and successive specialized (1-SPEC, 2-SPEC) phases, respectively. Vertical dash-dotted lines mark the specialization thresholds α c ( 1 ) \alpha_c^{(1)} α c ( 1 ) and α c ( 2 ) \alpha_c^{(2)} α c ( 2 ) .
Figure 9. Head-specialization phase transitions for isotropic Gaussian latent spikes: ν 1 = 4.0 \nu_1 = 4.0 ν 1 = 4.0 , ν 2 = 4.0 \nu_2 = 4.0 ν 2 = 4.0 , L = 5 L = 5 L = 5 , H = 4 H = 4 H = 4 , λ = 0.2 \lambda= 0.2 λ = 0.2 . Black solid lines correspond to theoretical predictions (Res. 3.1). Markers with error bars correspond to training the model (§ 3 ) with L-BFGS from random initialization in dimension D = 2000 D = 2000 D = 2000 across ten seeds. Left: Head-feature overlaps (m : 2 , m : 1 m_{:2},m_{:1} m : 2 , m : 1 ) parametrized by sample complexity. Grey circle indicates the distribution isotropy of possible draws of the planted spike k ^ \hat{k} k ^ . Center: Test error E \mathcal{E} E and training error E t r a i n \mathcal{E}_{\mathrm{train}} E train . Right: Head-feature overlaps m h f m_{hf} m h f for all heads and both latent features. Grey and darker blue identify the permutation-symmetric (PS) and specialized (2-SPEC) phases, respectively. Vertical dash-dotted lines mark the specialization thresholds α c ( 1 ) = α c ( 2 ) \alpha_c^{(1)} = \alpha_c^{(2)} α c ( 1 ) = α c ( 2 ) .
Local stability and phase boundaries
We derive the local stability conditions for the solutions of the self-consistent equations (6) by tracking small perturbations under the state-evolution (SE) map. These conditions are used to compute the phase boundaries shown in Figure 3 , Figure 4 , and Figure 7 .
Flipping-spike model
Stability against specialization Both PS and PSB satisfy m : 2 = 0 m_{:2} = 0 m : 2 = 0 , a condition preserved by the SE map. Denote an unperturbed solution by ( m 0 , q 0 , V 0 ) (m_0, q_0, V_0) ( m 0 , q 0 , V 0 ) , its local fields by Ω 0 \Omega^0 Ω 0 , and its proximal by Z 0 Z^0 Z 0 , with V 0 = ( λ I H + V ^ 0 ) − 1 V_0 = (\lambda I_H + \hat{V}^0)^{-1} V 0 = ( λ I H + V ^ 0 ) − 1 . We perturb m : 2 = δ m m_{:2} = \delta m m : 2 = δ m and denote the corresponding conjugate perturbation by δ m ^ \delta\hat{m} δ m ^ . By symmetry under θ 2 ↦ − θ 2 \theta_2 \mapsto-\theta_2 θ 2 ↦ − θ 2 , the remaining order parameters have no first-order variation. Writing θ 2 = s ν 2 \theta_2 = s\sqrt{\nu_2} θ 2 = s ν 2 , with s = ± 1 s = \pm1 s = ± 1 , the relevant linearized updates are
{ δ m = V 0 δ m ^ , δ m ^ = α 2 ∑ s = ± 1 E Ξ [ V 0 − 1 ( δ Z 1 ′ ( s ) − δ ω 1 ( s ) ) s V 2 ] . (107) \begin{cases}
\delta m = V_0\delta\hat m,\\
\delta\hat m = \frac{\alpha}{2}\sum_{s=\pm1}\mathbb{E}_{\Xi}\left[V_0^{-1}\left(\delta Z_1^{\prime(s)}-\delta\omega_1^{(s)}\right)s\sqrt{V_2}\right]. \tag*{(107)}
\end{cases} { δ m = V 0 δ m ^ , δ m ^ = 2 α ∑ s = ± 1 E Ξ [ V 0 − 1 ( δ Z 1 ′ ( s ) − δ ω 1 ( s ) ) s V 2 ] . (107)
We therefore need the first-order variations of the local fields and proximal. The fields are already linear in the perturbation:
ω ℓ ( s ) = ω ℓ 0 + δ ℓ 1 s V 2 δ m , ω ℓ 0 = δ ℓ 1 m 0 V 1 + q 0 1 / 2 ξ ℓ . (108) \omega_\ell^{(s)}=\omega_\ell^0+\delta\ell_1s\sqrt{V_2}\,\delta m,\qquad
\omega_\ell^0=\delta\ell_1m_0\sqrt{V_1}+q_0^{1/2}\,\xi_\ell. \tag*{(108)} ω ℓ ( s ) = ω ℓ 0 + δ ℓ 1 s V 2 δ m , ω ℓ 0 = δ ℓ 1 m 0 V 1 + q 0 1/2 ξ ℓ . (108)
Thus δ ω 1 ( s ) = s V 2 δ m \delta\omega_1^{(s)}=s\sqrt{V_2}\,\delta m δ ω 1 ( s ) = s V 2 δ m , while the other fields remain unchanged. To obtain δ Z ′ ( s ) \delta Z^{\prime(s)} δ Z ′ ( s ) , we expand the condition defining the proximal. Let ℓ ( Z ) \ell(Z) ℓ ( Z ) denote the loss term in the Moreau minimization. Writing Z ′ ( s ) = Z ′ 0 + δ Z ′ ( s ) Z^{\prime(s)}=Z^{\prime0}+\delta Z^{\prime(s)} Z ′ ( s ) = Z ′0 + δ Z ′ ( s ) , its stationarity condition is
0 = ∇ Z ℓ ( Z ′ 0 + δ Z ′ ( s ) ) + ( I L ⊗ V 0 − 1 ) ( Z ′ 0 + δ Z ′ ( s ) − Ω 0 − δ Ω ( s ) ) . (109) 0=\nabla_Z\ell\left(Z^{\prime0}+\delta Z^{\prime(s)}\right)+\left(\mathbb{I}_L\otimes V_0^{-1}\right)\left(Z^{\prime0}+\delta Z^{\prime(s)}-\Omega^0-\delta\Omega^{(s)}\right). \tag*{(109)} 0 = ∇ Z ℓ ( Z ′0 + δ Z ′ ( s ) ) + ( I L ⊗ V 0 − 1 ) ( Z ′0 + δ Z ′ ( s ) − Ω 0 − δ Ω ( s ) ) . (109)
The zeroth-order terms cancel because Z ′ 0 Z^{\prime0} Z ′0 satisfies the unperturbed stationarity condition. Taylor-expanding the gradient therefore gives, to first order,
[ ∇ Z 2 ℓ ( Z ′ 0 ) + I L ⊗ V 0 − 1 ] δ Z ′ ( s ) = ( I L ⊗ V 0 − 1 ) δ Ω ( s ) . (110) \left[\nabla_Z^2\ell\left(Z^{\prime0}\right)+\mathbb{I}_L\otimes V_0^{-1}\right]\delta Z^{\prime(s)}
=\left(\mathbb{I}_L\otimes V_0^{-1}\right)\delta\Omega^{(s)}. \tag*{(110)} [ ∇ Z 2 ℓ ( Z ′0 ) + I L ⊗ V 0 − 1 ] δ Z ′ ( s ) = ( I L ⊗ V 0 − 1 ) δ Ω ( s ) . (110)
Since only ω 1 \omega_1 ω 1 is perturbed, we obtain
δ Z 1 ′ ( s ) = ( [ ∇ Z 2 ℓ ( Z ′ 0 ) + I L ⊗ V 0 − 1 ] − 1 ) 11 V 0 − 1 δ ω 1 ( s ) . (111) \delta Z_1^{\prime(s)}
=\left(\left[\nabla_Z^2\ell\left(Z^{\prime0}\right)+\mathbb{I}_L\otimes V_0^{-1}\right]^{-1}\right)_{11}V_0^{-1}\delta\omega_1^{(s)}. \tag*{(111)} δ Z 1 ′ ( s ) = ( [ ∇ Z 2 ℓ ( Z ′0 ) + I L ⊗ V 0 − 1 ] − 1 ) 11 V 0 − 1 δ ω 1 ( s ) . (111)
Therefore, at first order,
δ m ^ = α 2 ∑ s = ± 1 E Ξ [ V 0 − 1 ( ( [ ∇ Z 2 ℓ ( Z ′ 0 ) + I L ⊗ V 0 − 1 ] − 1 ) 11 V 0 − 1 − I H ) δ ω 1 ( s ) s V 2 ] = α V 2 V 0 − 1 E Ξ [ ( [ ∇ Z 2 ℓ ( Z ′ 0 ) + I L ⊗ V 0 − 1 ] − 1 ) 11 V 0 − 1 − I H ] δ m . (112) \begin{aligned}
\delta\hat m
&=\frac{\alpha}{2}\sum_{s=\pm1}\mathbb{E}_{\Xi}\left[V_0^{-1}\left(\left(\left[\nabla_Z^2\ell\left(Z^{\prime0}\right)+\mathbb{I}_L\otimes V_0^{-1}\right]^{-1}\right)_{11}V_0^{-1}-\mathbb{I}_H\right)\delta\omega_1^{(s)}s\sqrt{V_2}\right]\\
&=\alpha V_2V_0^{-1}\mathbb{E}_{\Xi}\left[\left(\left[\nabla_Z^2\ell\left(Z^{\prime0}\right)+\mathbb{I}_L\otimes V_0^{-1}\right]^{-1}\right)_{11}V_0^{-1}-\mathbb{I}_H\right]\delta m. \tag*{(112)}
\end{aligned} δ m ^ = 2 α s = ± 1 ∑ E Ξ [ V 0 − 1 ( ( [ ∇ Z 2 ℓ ( Z ′0 ) + I L ⊗ V 0 − 1 ] − 1 ) 11 V 0 − 1 − I H ) δ ω 1 ( s ) s V 2 ] = α V 2 V 0 − 1 E Ξ [ ( [ ∇ Z 2 ℓ ( Z ′0 ) + I L ⊗ V 0 − 1 ] − 1 ) 11 V 0 − 1 − I H ] δ m . (112)
Finally, using δ m = V 0 δ m ^ \delta m=V_0\delta\hat m δ m = V 0 δ m ^ , we get the SE map for the perturbation
δ m t + 1 = J s p e c ( α ) δ m t , J s p e c ( α ) = α V 2 V 0 E Ξ [ ( [ ∇ Z 2 ℓ ( Z ′ 0 ) + I L ⊗ V 0 − 1 ] − 1 ) 11 V 0 − 1 − I H ] . (113) \delta m^{t+1}=J_{\mathrm{spec}}(\alpha)\delta m^t,\qquad
J_{\mathrm{spec}}(\alpha)=\alpha V_2V_0\mathbb{E}_{\Xi}\left[\left(\left[\nabla_Z^2\ell\left(Z^{\prime0}\right)+\mathbb{I}_L\otimes V_0^{-1}\right]^{-1}\right)_{11}V_0^{-1}-\mathbb{I}_H\right]. \tag*{(113)} δ m t + 1 = J spec ( α ) δ m t , J spec ( α ) = α V 2 V 0 E Ξ [ ( [ ∇ Z 2 ℓ ( Z ′0 ) + I L ⊗ V 0 − 1 ] − 1 ) 11 V 0 − 1 − I H ] . (113)
The unspecialized solution is stable if the spectral radius of the linear operator δ m t ↦ δ m t + 1 = J ( α ) δ m t \delta m^t\mapsto\delta m^{t+1}=J(\alpha)\delta m^t δ m t ↦ δ m t + 1 = J ( α ) δ m t is less than one. Finding the critical sample complexity for the specialization transition then comes down to studying the largest eigenvalue of the matrix J ( α ) J(\alpha) J ( α ) with the condition
λ max [ J s p e c ( α c s p e c ) ] = 1 , (114) \lambda_{\max}\left[J_{\mathrm{spec}}\left(\alpha_{\mathrm{c}}^{\mathrm{spec}}\right)\right]=1, \tag*{(114)} λ m a x [ J spec ( α c spec ) ] = 1 , (114)
where we noted λ max [ ⋅ ] \lambda_{\max}[\cdot] λ m a x [ ⋅ ] the largest eigenvalue. Evaluating this condition on the PS or PSB solutions gives the PS–SPEC or PSB–SPEC stability respectively.
Stability against permutation symmetry breaking At the PS solution with m ⋅ 2 = 0 m_{\cdot2}=0 m ⋅ 2 = 0 , we perturb towards PSB with q = q 0 + δ q e − e − T q=q_0+\delta q\,e_-e_-^{\mathsf{T}} q = q 0 + δ q e − e − T , where δ q = q ⊥ \delta q=q_\perp δ q = q ⊥ and e − = 1 2 ( 1 , − 1 ) T e_-=\frac{1}{\sqrt{2}}(1,-1)^{\mathsf{T}} e − = 2 1 ( 1 , − 1 ) T . Following similar steps as before leads to the SE map for the perturbation
δ q t + 1 = J p s b ( α ) δ q t , (115) \delta q^{t+1}=J_{\mathrm{psb}}(\alpha)\delta q^t, \tag*{(115)} δ q t + 1 = J psb ( α ) δ q t , (115)
J p s b ( α ) = α E Ξ [ [ ∑ ℓ , k = 1 L ( e − T ( [ ∇ Z 2 ℓ ( Z ′ 0 ) + I L ⊗ V 0 − 1 ] − 1 ) ℓ k V 0 − 1 − δ ℓ k I H ) e − ] 2 ] . (116) J_{\mathrm{psb}}(\alpha)=\alpha\mathbb{E}_{\Xi}\left[\left[\sum_{\ell,k=1}^{L}\left(e_-^{\mathsf{T}}\left(\left[\nabla_Z^2\ell\left(Z^{\prime0}\right)+\mathbb{I}_L\otimes V_0^{-1}\right]^{-1}\right)_{\ell k}V_0^{-1}-\delta_{\ell k}\mathbb{I}_H\right)e_-\right]^2\right]. \tag*{(116)} J psb ( α ) = α E Ξ ℓ , k = 1 ∑ L ( e − T ( [ ∇ Z 2 ℓ ( Z ′0 ) + I L ⊗ V 0 − 1 ] − 1 ) ℓ k V 0 − 1 − δ ℓ k I H ) e − 2 . (116)
Again, the critical sample complexity is recovered through the condition
λ max [ J p s b ( α c p s b ) ] = 1. (117) \lambda_{\max}\left[J_{\mathrm{psb}}\left(\alpha_{\mathrm{c}}^{\mathrm{psb}}\right)\right]=1. \tag*{(117)} λ m a x [ J psb ( α c psb ) ] = 1. (117)
Non-isotropic Gaussian model
In the case of the non-isotropic Gaussian model, we study the stability against specialization to the next largest signal spike. Consider an r r r -SPEC solution ( m r , q r , V r ) (m_r,q_r,V_r) ( m r , q r , V r ) , for which m r , : j = 0 m_{r,:j}=0 m r , : j = 0 for all j > r j>r j > r . We perturb towards alignment with the next feature with m : r + 1 = δ m : r + 1 m_{:r+1}=\delta m_{:r+1} m : r + 1 = δ m : r + 1 . Since θ r + 1 ∼ N ( 0 , ν r + 1 ) \theta_{r+1}\sim\mathcal{N}(0,\nu_{r+1}) θ r + 1 ∼ N ( 0 , ν r + 1 ) is centered and independent of the recovered features, the remaining order parameters have no first-order variation. Denoting by Z r ′ Z'_r Z r ′ the proximal evaluated at ( m r , q r , V r ) (m_r,q_r,V_r) ( m r , q r , V r ) ; following similar steps as before leads to the SE map for the perturbation
δ m : r + 1 t + 1 = J r ( α ) δ m : r + 1 t , (118) \delta m_{:r+1}^{t+1}=J_r(\alpha)\delta m_{:r+1}^{t}, \tag*{(118)} δ m : r + 1 t + 1 = J r ( α ) δ m : r + 1 t , (118)
J r ( α ) = α ν r + 1 E θ , Ξ [ ( [ ∇ Z 2 ℓ ( Z r ′ ) + I L ⊗ V r − 1 ] − 1 ) 11 V r − 1 − I H ] . (119) J_r(\alpha)=\alpha\nu_{r+1}\mathbb{E}_{\theta,\Xi}\left[\left(\left[\nabla_Z^2\ell(Z'_r)+I_L\otimes V_r^{-1}\right]^{-1}\right)_{11}V_r^{-1}-I_H\right]. \tag*{(119)} J r ( α ) = α ν r + 1 E θ , Ξ [ ( [ ∇ Z 2 ℓ ( Z r ′ ) + I L ⊗ V r − 1 ] − 1 ) 11 V r − 1 − I H ] . (119)
the critical sample complexity is recovered through the condition
λ max [ J r ( α c ( r + 1 ) ) ] = 1. (120) \lambda_{\max}\left[J_r\left(\alpha_{\mathrm{c}}^{(r+1)}\right)\right]=1. \tag*{(120)} λ m a x [ J r ( α c ( r + 1 ) ) ] = 1. (120)
Link between statistical transitions and dynamical emergence
We consider the case of the non-isotropic Gaussian model where m = 0 m=0 m = 0 , q = 0 q=0 q = 0 is a saddle point of the loss, by symmetry K ↦ − K K\mapsto-K K ↦ − K . We focus on the first specialization and assume it happens only along the first feature k 1 ∗ k_1^* k 1 ∗ . We introduce the largest curvature C ∈ R + \mathcal{C}\in\mathbb{R}^{+} C ∈ R + of minus the population loss E p o p \mathcal{E}_{\mathrm{pop}} E pop in the direction of the first feature k 1 ∗ k_1^* k 1 ∗ , defined as
C = λ max [ − ( k 1 ∗ ) T ( ∇ K , K 2 E p o p ( 0 ) ) k 1 ∗ ] , E p o p ( K ) = E X , y [ 1 2 D ∥ y − f K ( X ) ∥ 2 2 ] (121) \mathcal{C}=\lambda_{\max}\left[-(k_1^*)^{\mathsf{T}}\left(\nabla_{K,K}^2\mathcal{E}_{\mathrm{pop}}(0)\right)k_1^*\right],\qquad\mathcal{E}_{\mathrm{pop}}(K)=\mathbb{E}_{X,y}\left[\frac{1}{2D}\lVert y-f_K(X)\rVert_2^2\right] \tag*{(121)} C = λ m a x [ − ( k 1 ∗ ) T ( ∇ K , K 2 E pop ( 0 ) ) k 1 ∗ ] , E pop ( K ) = E X , y [ 2 D 1 ∥ y − f K ( X ) ∥ 2 2 ] (121)
where λ max [ ⋅ ] \lambda_{\max}[\cdot] λ m a x [ ⋅ ] is the largest eigenvalue and ∇ K , K 2 \nabla_{K,K}^2 ∇ K , K 2 the Hessian.
Online gradient flow
We consider the gradient-flow limit of unregularized online SGD. At time τ \tau τ the update is
d K d τ = − D ∇ K E p o p ( K ) , (122) \frac{\mathrm{d}K}{\mathrm{d}\tau}=-D\nabla_K\mathcal{E}_{\mathrm{pop}}(K), \tag*{(122)} d τ d K = − D ∇ K E pop ( K ) , (122)
with the weights being independently initialized as k h ( τ = 0 ) ∼ N ( 0 , η 2 I D ) k_h(\tau=0)\sim\mathcal{N}(0,\eta^2I_D) k h ( τ = 0 ) ∼ N ( 0 , η 2 I D ) for any h h h and for η > 0 \eta>0 η > 0 . The normalization D D D in eq. (122) insures that the time variation of the overlap m m m are of order O D ( 1 ) \mathcal{O}_D(1) O D ( 1 ) .
We follow Sagitova et al. [26 ] . They show that the alignment m m m follows the evolution
d m d τ = − ∇ m E p o p , m h ( τ = 0 ) ∼ N ( 0 , D − 1 η 2 I F ) (123) \frac{\mathrm{d}m}{\mathrm{d}\tau}=-\nabla_m\mathcal{E}_{\mathrm{pop}},\qquad m_h(\tau=0)\sim\mathcal{N}(0,D^{-1}\eta^2I_F) \tag*{(123)} d τ d m = − ∇ m E pop , m h ( τ = 0 ) ∼ N ( 0 , D − 1 η 2 I F ) (123)
and that in the limit η → 0 \eta\to0 η → 0 the weights stay in the span of the features k h ∈ span ( k f ∗ ) f = 1 F k_h\in\operatorname{span}(k_f^*)_{f=1}^{F} k h ∈ span ( k f ∗ ) f = 1 F with q = m m T q=mm^{\mathsf{T}} q = m m T . m = 0 m=0 m = 0 is an unstable fixed-point; we perform a linear stability analysis around it. We project m m m onto the direction corresponding to the fastest descent direction, defined as the eigenvector of the maximal eigenvalue in eq. (121) . We write m ˉ ∈ R \bar{m}\in\mathbb{R} m ˉ ∈ R its projection. We have the following exponential escape
∂ τ m ( τ ) = − ∇ m E p o p ( m ( τ ) ) (124) \partial_\tau m(\tau)=-\nabla_m\mathcal{E}_{\mathrm{pop}}(m(\tau)) \tag*{(124)} ∂ τ m ( τ ) = − ∇ m E pop ( m ( τ )) (124)
= − ∇ m , m 2 E p o p ( 0 ) m ( τ ) (125) =-\nabla_{m,m}^2\mathcal{E}_{\mathrm{pop}}(0)m(\tau) \tag*{(125)} = − ∇ m , m 2 E pop ( 0 ) m ( τ ) (125)
= − m ( τ ) K ∗ ∇ K , K 2 E p o p ( 0 ) ( K ∗ ) T (126) =-m(\tau)K^*\nabla_{K,K}^2\mathcal{E}_{\mathrm{pop}}(0)(K^*)^{\mathsf{T}} \tag*{(126)} = − m ( τ ) K ∗ ∇ K , K 2 E pop ( 0 ) ( K ∗ ) T (126)
m ˉ ( τ ) = m ˉ ( 0 ) e C τ (127) \bar{m}(\tau)=\bar{m}(0)e^{\mathcal{C}\tau} \tag*{(127)} m ˉ ( τ ) = m ˉ ( 0 ) e C τ (127)
For any small enough threshold ε > 0 \varepsilon> 0 ε > 0 , independent of η \eta η , we define τ s p e c \tau^{\mathrm{spec}} τ spec the specialization time to be the first τ \tau τ such that ∣ m ˉ ∣ = ε |\bar{m}| = \varepsilon ∣ m ˉ ∣ = ε . We have
ε = ∣ m ˉ ( 0 ) ∣ e C τ s p e c (128) \varepsilon= |\bar{m}(0)|e^{C\tau^{\mathrm{spec}}} \tag*{(128)} ε = ∣ m ˉ ( 0 ) ∣ e C τ spec (128)
τ s p e c = 1 C ( log ε − log ∣ m ˉ ( 0 ) ∣ ) (129) \tau^{\mathrm{spec}} = \frac{1}{C}\left(\log\varepsilon- \log|\bar{m}(0)|\right) \tag*{(129)} τ spec = C 1 ( log ε − log ∣ m ˉ ( 0 ) ∣ ) (129)
We define the rescaled specialization time τ ~ s p e c \widetilde{\tau}^{\mathrm{spec}} τ spec as
τ ~ s p e c = τ s p e c log D / η (130) \widetilde{\tau}^{\mathrm{spec}} = \frac{\tau^{\mathrm{spec}}}{\log\sqrt{D}/\eta} \tag*{(130)} τ spec = log D / η τ spec (130)
We have ∣ m ˉ ( 0 ) ∣ = η m ˉ / D |\bar{m}(0)| = \eta\bar{m}/\sqrt{D} ∣ m ˉ ( 0 ) ∣ = η m ˉ / D with m ˉ \bar{m} m ˉ a random variable independent of η \eta η and D D D . In the limits D → ∞ D \to\infty D → ∞ and η → 0 \eta\to0 η → 0 we obtain that
τ ~ s p e c = 1 C ( log ε log D / η − log m ˉ log D / η + 1 ) → 1 / C (131) \widetilde{\tau}^{\mathrm{spec}} = \frac{1}{C}\left(\frac{\log\varepsilon}{\log\sqrt{D}/\eta} - \frac{\log\bar{m}}{\log\sqrt{D}/\eta} + 1\right) \to1/C \tag*{(131)} τ spec = C 1 ( log D / η log ε − log D / η log m ˉ + 1 ) → 1/ C (131)
that is to say the specialization time is only controlled by the Hessian of the loss at initialization. The random fluctuations due to the initialization and the effect of ε \varepsilon ε vanish.
ERM
We consider the static specialization in sample complexity. We consider the limit of large regularization λ \lambda λ , α ≫ 1 \alpha\gg1 α ≫ 1 with α / λ = Θ ( 1 ) \alpha/\lambda= \Theta(1) α / λ = Θ ( 1 ) . In this limit, the model does not overfit data and E t r a i n = E p o p \mathcal{E}_{\mathrm{train}} = \mathcal{E}_{\mathrm{pop}} E train = E pop . We also have q = m m T q = mm^{\mathsf{T}} q = m m T and D − 1 ∥ K ∥ F 2 = Tr q = ∥ m ∥ F 2 D^{-1}\|K\|_{F}^{2} = \operatorname{Tr}q = \|m\|_{F}^{2} D − 1 ∥ K ∥ F 2 = Tr q = ∥ m ∥ F 2 , that is to say the weights K K K are solely in the space of the ground truth K ∗ K^{*} K ∗ and do not have components that fit noise. We expand the training objective to the 2nd order in m m m .
1 D L t r a i n = α E p o p + λ 2 ∥ m ∥ F 2 (132) \frac{1}{D}\mathcal{L}_{\mathrm{train}} = \alpha\mathcal{E}_{\mathrm{pop}} + \frac{\lambda}{2}\|m\|_{F}^{2} \tag*{(132)} D 1 L train = α E pop + 2 λ ∥ m ∥ F 2 (132)
= α E p o p ( 0 ) + 1 2 ( α ∇ m , m 2 E p o p ( 0 ) + λ I H ⊗ I F ) ⋅ ( m , m ) (133) = \alpha\mathcal{E}_{\mathrm{pop}}(0) + \frac{1}{2}\left(\alpha\nabla_{m,m}^{2}\mathcal{E}_{\mathrm{pop}}(0) + \lambda\mathbb{I}_{H} \otimes\mathbb{I}_{F}\right)\cdot(m,m) \tag*{(133)} = α E pop ( 0 ) + 2 1 ( α ∇ m , m 2 E pop ( 0 ) + λ I H ⊗ I F ) ⋅ ( m , m ) (133)
= α E p o p ( 0 ) + 1 2 ( α K ∗ ∇ K , K 2 E p o p ( 0 ) ( K ∗ ) T + λ I H ⊗ I F ) ⋅ ( m , m ) (134) = \alpha\mathcal{E}_{\mathrm{pop}}(0) + \frac{1}{2}\left(\alpha K^{*}\nabla_{K,K}^{2}\mathcal{E}_{\mathrm{pop}}(0)(K^{*})^{\mathsf{T}} + \lambda\mathbb{I}_{H} \otimes\mathbb{I}_{F}\right)\cdot(m,m) \tag*{(134)} = α E pop ( 0 ) + 2 1 ( α K ∗ ∇ K , K 2 E pop ( 0 ) ( K ∗ ) T + λ I H ⊗ I F ) ⋅ ( m , m ) (134)
We define α s p e c \alpha^{\mathrm{spec}} α spec the smallest sampling ratio such that m = 0 m = 0 m = 0 is no longer a local minimum of L t r a i n \mathcal{L}_{\mathrm{train}} L train . We only consider the specialization along k 1 ∗ k_{1}^{*} k 1 ∗ and project m m m onto k 1 ∗ k_{1}^{*} k 1 ∗ . The stability of the fixed-point m = 0 m = 0 m = 0 is controlled by whether the smallest eigenvalue of the quadratic form eq. (134) is negative. It reads − α C + λ -\alpha C + \lambda − α C + λ . This gives the critical sample complexity
α s p e c = λ C (135) \alpha^{\mathrm{spec}} = \frac{\lambda}{C} \tag*{(135)} α spec = C λ (135)
Last we rescale α \alpha α as
α ~ s p e c = α s p e c λ (136) \widetilde{\alpha}^{\mathrm{spec}} = \frac{\alpha^{\mathrm{spec}}}{\lambda} \tag*{(136)} α spec = λ α spec (136)
and obtain that
α ~ s p e c = τ ~ s p e c = 1 / C . (137) \widetilde{\alpha}^{\mathrm{spec}} = \widetilde{\tau}^{\mathrm{spec}} = 1/C. \tag*{(137)} α spec = τ spec = 1/ C . (137)
The extension to more realistic scenarios, including online SGD and finite regularization λ \lambda λ , could be approached by a perturbation of this analysis; we expect the values of τ ~ s p e c \widetilde{\tau}^{\mathrm{spec}} τ spec and α ~ c s p e c \widetilde{\alpha}_{c}^{\mathrm{spec}} α c spec to be different but the underlying mechanism would stay the same. We provide a numerical comparison of the mapping between the ERM and the online gradient flow in Figure 10 at finite large D D D . We observe that specialization happens around the same τ ~ s p e c \widetilde{\tau}^{\mathrm{spec}} τ spec and α ~ s p e c \widetilde{\alpha}^{\mathrm{spec}} α spec , whose values are well predicted by 1 / C 1/C 1/ C .
Figure 10. Correspondence between α c s p e c \alpha_c^{\mathrm{spec}} α c spec and τ s p e c \tau^{\mathrm{spec}} τ spec : Population loss E p o p \mathcal{E}_{\mathrm{pop}} E pop , test error E \mathcal{E} E and head–feature overlap m h 1 m_{\mathrm{h1}} m h1 for online gradient flow as a function of rescaled time τ ~ \tilde{\tau} τ ~ (ten independent runs) and for empirical risk minimizers as a function of rescaled sample complexity α ~ \tilde{\alpha} α ~ (averaged over five instances). The inverse curvature 1 / C 1/C 1/ C is computed analytically in Sagitova et al. [26 ] . Gaussian model with F = 1 F=1 F = 1 , ν 1 = 8 \nu_1=8 ν 1 = 8 , H = 2 H=2 H = 2 , L = 5 L=5 L = 5 , λ = 3 \lambda=3 λ = 3 , D = 5000 D=5000 D = 5000 , η = 10 − 3 \eta=10^{-3} η = 1 0 − 3 .
Implementation details
Experiments with solvable models
Resolution of the self-consistent equations We obtain solutions for the set of self-consistent equations (6) by iterating the associated state-evolution until convergence. The low-dimensional expectations over random variables ( θ , Ξ ) (\theta,\Xi) ( θ , Ξ ) are evaluated with Monte-Carlo, with the proximal minimization performed numerically for each sample. Different solutions are first identified from uninformed initializations. Once their structure is known, branches can be followed using planted initialization, or by restricting the state-evolution updates on each solution. Their regularized training loss (or zero-temperature free entropy) identifies the global ERM minimum.
Numerical simulations For numerical simulations, we train the attention layer (2) on the regularized ERM objective (3) , using synthetic datasets drawn from the model of § 3 . For each realization, we sample the planted directions and generate N = ⌊ α D ⌋ N=\lfloor\alpha D\rfloor N = ⌊ α D ⌋ training sequences, keeping both fixed throughout optimization. Training is implemented in PyTorch using full-batch L-BFGS with learning rate 0.5, history size of 10 steps, until convergence, starting from random initialization of the weights orthogonal to the planted directions. Weights are sampled from an isotropic Gaussian distribution and projected onto the orthogonal complement of the planted-feature span, removing finite-size initial alignments with the planted directions; the effect of this projection vanishes at large D D D . Final overlaps and training losses are computed directly, while test errors are evaluated on 1000 separately generated sequences sharing the same latent directions. Each parameter setting is repeated over ten seeds, varying both the dataset and initialization. Before averaging empirical head–feature overlaps across seeds, we order symmetry-equivalent solutions consistently.
Experiments with BERT MLMs
Fixed dataset experiment We adapt the BERT masked-language-modeling experiments from Chen et al. [8 ] , which studied the emergence of syntactic attention structure (SAS) in training time, close to the online learning regime. To investigate an equivalent analysis in sample complexity, we train models on fixed datasets of N N N sequences until the overfitting regime. To avoid data augmentation considerations, we also remove dynamic masking. Effective regularization is obtained through early stopping, evaluating the different metrics on checkpoint models with the lowest validation error along training trajectory. Repeating this procedure across dataset sizes and optimization seeds reveals the correspondence between emergence of specialized heads as a function of the number of samples and along training.
Training dataset Training sequences are sampled from the preprocessed BookCorpus and English Wikipedia dataset of the reference experiment. Training datasets are nested subsets of N N N sequences of 128 tokens randomly sampled from the original ∼ 9 M \sim9\mathrm{M} ∼ 9 M sequences dataset, with 2048 disjoint validation sequences shared across runs. Masking selects 15% of tokens, following the original 80/10/10 replacement rule.
Model and training We train BERTS m a l l _{\mathrm{Small}} Small from random initialization, with 4 layers, 8 heads per layer, hidden dimension 512, feed-forward dimension 2048, and dropout probability 0.1. Optimization uses AdamW with learning rate 10 − 4 10^{-4} 1 0 − 4 , weight decay 0.1, and an effective batch size of 256 sequences, obtained by accumulating four minibatches of 64. The learning rate increases linearly over 1000 warmup steps and then decreases linearly on a fixed 10 6 10^{6} 1 0 6 -step horizon. We train for 10000 optimizer steps, saving and evaluating checkpoints every 250 steps. Dataset sizes are N ∈ { 1000 , 3000 , 6000 , 9000 , 12000 , 15000 , … , 60000 } N \in\{1000, 3000, 6000, 9000, 12000, 15000, \ldots, 60000\} N ∈ { 1000 , 3000 , 6000 , 9000 , 12000 , 15000 , … , 60000 } and seeds ∈ { 0 , 1 , 2 , 3 , 4 } \in\{0,1,2,3,4\} ∈ { 0 , 1 , 2 , 3 , 4 } . Seeds vary initialization, minibatch order, and dropout. Given a sequence X ~ μ \widetilde{X}_{\mu} X μ corrupted at positions M μ M_{\mu} M μ from an original sequence X μ X_{\mu} X μ , the MLM loss is
L M L M ( Θ ) = − 1 ∑ μ = 1 N ∣ M μ ∣ ∑ μ = 1 N ∑ i ∈ M μ log p Θ ( x μ i ∣ X ~ μ ) , (138) \mathcal{L}_{\mathrm{MLM}}(\Theta) = -\frac{1}{\sum_{\mu=1}^{N}|M_{\mu}|}\sum_{\mu=1}^{N}\sum_{i\in M_{\mu}}\log p_{\Theta}(x_{\mu i}\mid\widetilde{X}_{\mu}), \tag*{(138)} L MLM ( Θ ) = − ∑ μ = 1 N ∣ M μ ∣ 1 μ = 1 ∑ N i ∈ M μ ∑ log p Θ ( x μ i ∣ X μ ) , (138)
where p Θ ( x μ i ∣ X ~ μ ) p_{\Theta}(x_{\mu i}\mid\widetilde{X}_{\mu}) p Θ ( x μ i ∣ X μ ) is the vocabulary distribution at position i i i predicted by the model with parameters Θ \Theta Θ . The training error E t r a i n \mathcal{E}_{\mathrm{train}} E train therefore corresponds to the latest logged MLM loss in training, while the validation error E \mathcal{E} E is the MLM loss computed on the validation dataset.
Syntactic attention structure SAS is evaluated on a separate dataset of 1000 fixed Wall Street Journal (WSJ) sentences from the Penn Treebank [20 ] , with dependency parents and relation labels supplied in Stanford Dependencies format [27 ] . We follow the implementation from the repository of Chen et al. [8 ] . Token attention is first translated to word attention. Then, for head h h h in layer l l l and attention direction d ∈ { → , ← } d \in\{\to,\leftarrow\} d ∈ { → , ← } , the head-specific probe j ^ h , l , d \hat{j}_{h,l,d} j ^ h , l , d for a target word x i x_i x i is the other word with maximum attention in that direction:
j ^ h , l , d ( x i ) = arg max j ≠ i α i j h , l , d . (139) \hat{j}_{h,l,d}(x_i)=\underset{j\ne i}{\operatorname{arg\,max}}\ \alpha_{ij}^{h,l,d}. \tag*{(139)} j ^ h , l , d ( x i ) = j = i arg max α ij h , l , d . (139)
Here α h , l \alpha^{h,l} α h , l denotes the word-level attention matrix of head h h h in layer l l l , with α i j h , l , → = α i j h , l \alpha_{ij}^{h,l,\to}=\alpha_{ij}^{h,l} α ij h , l , → = α ij h , l and α i j h , l , ← = α j i h , l \alpha_{ij}^{h,l,\leftarrow}=\alpha_{ji}^{h,l} α ij h , l , ← = α j i h , l . Let R \mathcal{R} R denote the set of syntactic relations present in the probe dataset, and D R D_R D R the collection of annotated child–parent pairs ( x i , x j ) (x_i,x_j) ( x i , x j ) carrying relation R R R . The relation-specific UAS is
U A S R = max h , l , d 1 ∣ D R ∣ ∑ ( x i , x j ) ∈ D R 1 { j ^ h , l , d ( x i ) = j } . (140) \mathrm{UAS}_{R}=\max_{h,l,d}\frac{1}{|D_R|}\sum_{(x_i,x_j)\in D_R}\mathbf{1}\{\hat{j}_{h,l,d}(x_i)=j\}. \tag*{(140)} UAS R = h , l , d max ∣ D R ∣ 1 ( x i , x j ) ∈ D R ∑ 1 { j ^ h , l , d ( x i ) = j } . (140)
This measures how accurately best individual heads recover relation R R R . Different relations can select different heads, layers, and attention directions, allowing their specialization to be studied separately. The overall UAS selects the best head, layer, and attention direction across all dependencies:
U A S = max h , l , d 1 ∑ R ∈ R ∣ D R ∣ ∑ R ∈ R ∑ ( x i , x j ) ∈ D R 1 { j ^ h , l , d ( x i ) = j } . (141) \mathrm{UAS}=\max_{h,l,d}\frac{1}{\sum_{R\in\mathcal{R}}|D_R|}\sum_{R\in\mathcal{R}}\sum_{(x_i,x_j)\in D_R}\mathbf{1}\{\hat{j}_{h,l,d}(x_i)=j\}. \tag*{(141)} UAS = h , l , d max ∑ R ∈ R ∣ D R ∣ 1 R ∈ R ∑ ( x i , x j ) ∈ D R ∑ 1 { j ^ h , l , d ( x i ) = j } . (141)
This measures the fraction of correctly recovered parents using a single head, layer, and attention direction. For relation-specific scores, relation labels select the probes, while correctness depends only on predicting the parent. These scores serve as benchmark proxies relating to head–feature overlaps; quantifying alignment between attention structure and syntactic relations structure, a structural latent feature of language datasets.
In Figure 11 we present the training dynamics for B E R T S m a l l \mathrm{BERT}_{\mathrm{Small}} BERT Small at different dataset sizes. We observe the presence of drops in the error corresponding to the acquisition of SAS only at large enough dataset sizes while models trained on small datasets overfit the data early. As UAS plateaus, specialization remains until convergence.
Figure 11. Training dynamics on fixed datasets: Separate runs of B E R T S m a l l \mathrm{BERT}_{\mathrm{Small}} BERT Small models trained on datasets of N ∈ { 5000 , 20000 , 60000 } N \in\{5000, 20000, 60000\} N ∈ { 5000 , 20000 , 60000 } sequences, following the training procedure described in App. § 15 .§ 3 with 15000 optimization steps and checkpoints every 500 steps. Left: Validation MLM loss E \mathcal{E} E at registered checkpoints and logged training loss E t r a i n \mathcal{E}_{\mathrm{train}} E train along training. Right: Evolution of syntactic attention structure, measured by UAS. Larger datasets allow an abrupt emergence of SAS during training. Curves show averages across optimization seeds, with shaded bands indicating one standard deviation.
In Figure 12 we present the results of training B E R T S m a l l \mathrm{BERT}_{\mathrm{Small}} BERT Small with varying learning rates. Head specialization is robust to the optimization dynamics: we observe emergence and a plateau in UAS, independently from the selected early-stopping time. As mentioned in § 7 , early stopping regularizes within the class of optimizers reached during a given optimization dynamics, and introduces a dependency on the learning rate in the critical number of samples for specialization. A further test of the sample-complexity interpretation would explore varying training procedures with a regularized objective and training controlled to convergence.
Figure 12. Influence of the learning rate on specialization: B E R T S m a l l \mathrm{BERT}_{\mathrm{Small}} BERT Small models trained following the procedure described in App. § 15 .§ 3 , with learning rates { 0.5 γ , γ , 2 γ , 4 γ } \{0.5\gamma,\gamma,2\gamma,4\gamma\} { 0.5 γ , γ , 2 γ , 4 γ } , where γ = 10 − 4 \gamma= 10^{-4} γ = 1 0 − 4 . Top: Training dynamics on a fixed dataset of N = 60000 N = 60000 N = 60000 sequences. Bottom: Models trained on fixed datasets of increasing size N N N . Left: Validation MLM loss E \mathcal{E} E at registered checkpoints and logged training loss E t r a i n \mathcal{E}_{\mathrm{train}} E train . Right: Evolution of syntactic attention structure, measured by UAS. Curves show averages across two optimization seeds, with shaded bands indicating one standard deviation.
Figure 13 details relation-refined U A S R \mathrm{UAS}_{\mathrm{R}} UAS R for the statistically most present relations in the dataset, exhibiting a same critical dataset size for emergence of SAS suggesting a coordinated acquisition of syntactic structure. It would be interesting to explore if different capabilities, maybe different types of syntactic rules, are obtained at different sample complexities.
Figure 13. Acquisition of different syntactic relations with increasing dataset size: B E R T S m a l l \mathrm{BERT}_{\mathrm{Small}} BERT Small models are trained on fixed datasets of increasing size N N N following the training procedure described in App. § 15 .§ 3 . Left: Validation MLM loss E \mathcal{E} E at registered checkpoints and logged training loss E t r a i n \mathcal{E}_{\mathrm{train}} E train . Right: Relation-specific attachment scores for the four most frequent relations in the WSJ dataset: case, compound, det, and nsubj. Validation loss and attachment scores are evaluated with early stopping. Curves show seed averages, with shaded bands indicating one standard deviation.
Experiments with sparse attention patterns
We reproduce the experiment of Yüksel et al. [38 ] studying next-token prediction on a synthetic high-order Markov chain, where the prediction depends on three groups of past positions, ordered by decreasing statistical importance. Following their Figure 3, we measure the KL divergence between the student predictor f s t u d e n t f_{\mathrm{student}} f student and ground-truth predictors f A 1 : r ⋆ f_{A_{1:r}^{\star}} f A 1 : r ⋆ retaining only the first r r r groups, and between the student and independently trained transformers f c -gram f_{c\text{-gram}} f c -gram with restricted context length of c c c tokens. We extend their online learning setting to fixed dataset sizes introducing a small ℓ 2 \ell_2 ℓ 2 regularization to stabilize convergence. As the dataset size increases, the converged predictors approach reference predictors using progressively more positional groups. In Figure 14 , we reproduce the experiment as a function of the number of samples, and establish that specialization cascade also occurs in this setting. This tests the successive specialization phase-transitions and simplicity-bias predictions with correlated tokens and autoregressive loss.
Figure 14. Sequential specialization in learning of sparse attention patterns: Next-token prediction on the synthetic Markov-chain task of Yüksel et al. [38 ] (see their Fig. 3 for details). Top: Training dynamics of the full transformer trained on N = 9000 N = 9000 N = 9000 sequences. Bottom: Transformer trained until convergence on fixed datasets of increasing size N N N , with ℓ 2 \ell_2 ℓ 2 regularization λ = 10 − 6 \lambda= 10^{-6} λ = 1 0 − 6 . Left: KL divergence K L ( f A 1 : r ⋆ ∥ f s t u d e n t ) \mathrm{KL}(f_{A_{1:r}^{\star}}\Vert f_{\mathrm{student}}) KL ( f A 1 : r ⋆ ∥ f student ) with the ground-truth predictors A 1 : r ⋆ A_{1:r}^{\star} A 1 : r ⋆ using the first r = 1 , 2 , 3 r = 1, 2, 3 r = 1 , 2 , 3 positional groups. Right: KL divergence K L ( f c -gram ∥ f s t u d e n t ) \mathrm{KL}(f_{c\text{-gram}}\Vert f_{\mathrm{student}}) KL ( f c -gram ∥ f student ) where c c c -gram predictors are independently trained transformers restricted to the last c = 2 , 4 , 6 c = 2, 4, 6 c = 2 , 4 , 6 tokens. Bottom curves average five seeds, with shaded bands indicating one standard deviation.