Manuscript Offprint
arXiv:2610.20337Training Dynamics of Transformers on Unbounded Inputs: Attention Learning Can Lag Output Layer Learning
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
Abstract
The success of transformers is attributed to several factors, including their capacity to express formal languages over variable-length inputs, and ability of the attention mechanism to focus on relevant input features. However, there is limited understanding of the training dynamics of shallow transformers, specifically how to decouple the learning of the attention and the output (feedforward) layer. A natural extension of the theory of one-step gradient feature learning in feedforward networks suggests that one could first learn the attention weights with a single gradient step, and then train the output layer. We show that this fails for a shallow transformer trained to recognize a star-free language from unbounded-length input. We prove that the transformer can be trained to recognize the language with a three-phase gradient descent: the output layer is updated first, followed by an attention update, and the output layer is fine-tuned in the third phase. In contrast, the language cannot be learned by training only the attention or output layer, or by a single attention-layer update followed by finetuning the output layer. We empirically show that “attention learning lagging output layer learning” is beneficial in other language recognition, regression, and in-context learning tasks as well.
1 INTRODUCTION
How do neural architectures learn features and attentions? What is the impact of the learning dynamics on the generalization abilities of the trained model? These are major open questions in deep learning theory. Significant progress has been made to address these questions in feedforward neural networks, both from a broad optimization perspective—for instance, implicit biases of gradient descent (Lyu and Li, 2020)—as well as from the viewpoint of learning specific tasks, like learning parity, sparse polynomial or gaussian mixture classification (Daniely and Malach, 2020; Abbe et al., 2023; Frei et al., 2023). A notable theoretical insight has emerged in this context, sometimes referred to as one-step gradient feature learning (Ba et al., 2022; Shi et al., 2023)—for learning tasks using a shallow feedforward network, it often suffices to perform one step of gradient descent on the input layer to learn the features and then train the output layer till convergence. Decoupling the training of different layers helps to study simplicity bias, lottery tickets, etc., in feedforward networks (Abbe et al., 2023; Shi et al., 2023).
Much less is understood about how attention learning happens in transformers. There are studies on implicit biases and training dynamics (see Relation to prior work), but it is not clear what the ideal way is to theoretically decouple the training of attention and output layers in a shallow transformer, comprising a softmax attention layer followed by a feedforward output layer. For example, a natural extension of the gradient feature learning paradigm in a shallow transformer is to perform a single gradient descent update of the attention weights, followed by training of the output layer. It is not clear if a “one-step attention learning” paradigm is suitable for training shallow transformers or a different multi-phase decoupled training is needed, for example, in context of the prototypical task of learning formal languages (Strobl et al., 2024).
Contributions. We study how attention learning happens in a shallow transformer trained to recognize formal language, where the training consists of words of varying length (potentially unbounded). Despite active research on the theory of attention learning, little is known about the training dynamics of transformers when trained on variable-length inputs. We aim to address if a one-step attention learning paradigm—akin to gradient feature learning in feedforward networks (Shi et al., 2023)—is an appropriate simplification of how shallow transformers learn to recognize a formal language. We have the following key contributions.
Multi-phase gradient descent dynamics in learning the occurrence language. We consider a minimalist example of learning to recognize the occurrence language on the finite alphabet , i.e., the language of all words containing , where is not known apriori (Figure 1a). The occurrence language can be expressed by a shallow transformer with -variate encoding of each bit, a single attention head, and a linear output layer (Proposition 1). Empirically, for this task, gradient descent (GD) first learns the output layer before the attention weights (Figure 1b). Theorem 2 formally shows that it is possible to learn the optimal transformer using multi-phase GD: (Phase 1) one-step GD update of output layer; (Phase 2) one-step GD update of attention weights; (Phase 3) training output layer till convergence. This result indicates that a one-step attention learning works in transformers, but when the attention learning happens after output layer is partly trained (see Figure 1d-e).
Impossibility results for simpler learning approaches. It is natural to question if the single-head transformer can also be trained using a simpler gradient-based rule. Propositions 2 and 3 show that, if either only the output or the attention layer is trained with the other held fixed, then a shallow transformer cannot learn uniformly over the set of languages . The same also holds for transformers with heads (Proposition 4), but arbitrary fixed attention, showing that lazy training fails for this task, unless with a large number of heads. Furthermore, Theorem 1 shows that a two-phase approach of one step of GD update of attention, followed by training the output, cannot learn the language. Thus a naïve extension of gradient feature learning principle does not work in this case.
Finite sample analysis and empirical study on other languages. While the aforementioned results consider GD on population loss, Corollary 1 extends the learnability result to finite sample setting, showing that the three-phase training also works with samples for any fixed tolerance. We also numerically study other regression, language recognition, or in-context learning tasks with shallow transformers, and show that in most cases, the three-phase approach (with one-step GD update of output layer before one-step attention learning) outperforms other decoupled training of attention and output layers. Hence, we hypothesize that this approach is potentially a reasonable theoretical simplification of transformer training dynamics.
Relation to prior work. The expressivity and training dynamics of transformers is an active area of research in deep learning theory. While there is a rich literature on the expressivity of transformers in terms
(a)

(c)
| Training Plan | Phase | Train Loss (mean ± std) | Test Acc. (mean ± std) |
|---|---|---|---|
| attention(A) only | 1 | 1.64 ± 0.08 | 0.50 ± 0.01 |
| output(O) only | 1 | 0.74 ± 0.05 | 0.86 ± 0.01 |
| A(1x)→O | 2 | 0.72 ± 0.26 | 0.76 ± 0.13 |
| O(1x)→A(1x)→O | 3 | (2 ± 1)×10-6 | 1.00 ± 0.00 |
(b)
(d)

(e)
Figure 1: (a) Automaton of the occurrence language with alphabet and unknown . The language can be expressed by a transformer with one attention head and linear output layer (1), which encodes word as , where is -th standard basis vector. The optimal shallow transformer has weights of the output layer , and attention score for symbol is if , and 0 otherwise. (b) A shallow transformer is trained to recognize using gradient descent jointly on both layers. The output gap and attention gap , plotted across training epochs, show that output gap increases before attention gap appears, indicating that attention learning lags output layer learning. (c) Several training plans are considered, which decouple gradient descent on attention layer (A) and output layer (O), sometimes using a single gradient step (1x). “One-step attention learning”, where one attention update is followed by training output layer till loss converges, A(1x)→O, does not correctly learn the language. We later prove that a 3-phase training, O(1x)→A(1x)→O, correctly learns to recognize . (d)-(e) show how our 3-phase plan reaches the ideal gaps in both layers, but training attention/output only, or attention before output do not.
of formal languages, circuit complexity or space/time complexity classes (see surveys in Strobl et al. (2024); Lin and Barceló (2025); Barceló et al. (2025)), the current research on training dynamics of transformers has predominantly focused on finite-dimensional learning problems. There are results on the lazy training regime of shallow transformers (Hron et al., 2020; Arda et al., 2026) or implicit biases towards maximum margin (Tarzanagh et al., 2023), which hold in general data settings. However, fine-grained characterization of the training dynamics requires studying specific data distributions or learning tasks, which we also assume.
Wen et al. (2025); Han and Ghoshdastidar (2026) study the training dynamics of transformers when trained on sparse parity function—a prototypical task for feedforward networks. Marion et al. (2025); Dohmatob (2025) study the joint dynamics of attention and output layer of a shallow transformer for single-location regression, while Wang et al. (2024) derive the joint training dynamics for sparse token averaging. The settings in these works correspond to finite/fixed-dimensional inputs, thereby ignoring the ability of transformers to handle varying input length. Furthermore, the attention-only or joint training dynamics do not reveal the importance of learning different layers. Bietti et al. (2023); Chen et al. (2024) study the dynamics of training induction heads in transformers for next token prediction on bigrams and in-context n-gram Markov chains. Bietti et al. (2023) empirically observe, under joint training, the induction head is learned more slowly than the global bigram model, similar to Figure 1b, and show that the induction head can be learned by sequential steps: first on output matrix, then on two attention key matrices. Chen et al. (2024) also consider a multi-phase training of different layers, involving a parameter-inefficient polynomial regression. Both works, however, restrict the problems to fixed context windows, effectively to fixed-length inputs. Moreover, these works do not explore if attention or output needs to be learned first.
Several empirical works study how transformers learn formal languages (Liu et al., 2023a,b; Butoi et al., 2025), but theoretical characterization of the training dynamics of transformers in learning formal languages is rather recent. Yang et al. (2024) study the gradient flow dynamics of learning word co-occurrence for fixed-length input, showing that the first phase mainly trains the output layer, before the joint training of output and attention happens. Huang et al. (2025) study the joint training dynamics of even-pairs and parity-check languages (the latter with chain of thought), restricting to bounded-length words, and observe a similar slow learning of attention in early phase. These works implicitly suggest that a phenomenon equivalent to one-step gradient feature learning in feedforward networks may not hold for transformers, where attention learning typically happens late. Our work takes a step towards resolving this matter by proving that one-step attention learning mechanism is indeed possible, but needs to follow a step of output layer update, which aligns with the intuition from known joint training dynamics. Such a simplifying characterization of the training dynamics is a key contribution of our work, along with the impossibility of learning via simpler attention-only or attention-first training strategies. Prior works also assume fixed- or bounded-length inputs, which our analysis does not require.
Occurrence language and Training data. Let be a finite alphabet of size . For a symbol , the occurrence language, defined as , is the set of strings that contain . We encode membership by the label function . Consider any non-empty word drawn from a distribution, say , such that the length is , i.e., for , and given , the symbols Uniform( ). Equivalently, after the first symbol, the sequence terminates at each step independently with probability . Setting exactly balances the proportion of positive/negative samples since, for any , it holds that . We use to denote the joint distribution over where and . Throughout this paper, we fix a target symbol , unknown to the learner, and write , when is unambiguous from context. The transformer, described next, is trained by gradient descent on the population loss over .
Shallow transformer architecture. To recognize the language , we consider a transformer with a single attention layer with one head, and a linear output layer. Every is embedded as -th standard basis vector , and a word encodes into , where . Positional encoding is not used since membership is permutation-invariant. We prepend a fixed classification token , which attends to the input positions but not to itself. The prediction is computed from the attention output of this token alone.
Since the model prediction depends only on the output of the classification token, the query and key matrices enter the model only through the vector , whose -th entry is the attention logit that the CLS token assigns to symbol . Likewise, the value matrix and the linear output enter only through their product . We treat as the trainable parameters, and call them the attention and output weights, respectively. The model computes
(1) where the second line groups the attention scores from positions that carry the same symbol by using to denote the number of occurrences of symbol in ; a fixed bias -1 is used. We use to denote the total attention scores placed on symbol .
Loss and expressivity. The transformer is trained to minimize the population (squared) risk over D,
In Corollary 1, some results are extended to a finite sample case, where the empirical risk is minimized.
The following expressivity result, proved in Appendix A.2, shows that there is a choice of for which the loss can be made arbitrarily small.
Proposition 1 (Shallow transformer expresses occurrence language). For any specified , a shallow transformer with and achieves . The result also holds for any such that .
Training. Our main results on training dynamics assume that transformer is trained to minimise the population risk with GD. A gradient step on the parameters is written as , , with parameter-wise step sizes . We subsequently use training plans that decouple GD updates of , that is, each step updates only one of the two parameters, while the other is frozen (i.e., the learning rate for that parameter is 0). Our results in Sections 3 and 4 differ in the initialization of and in the order of training the layers, as explained in the respective results.
3 FAILURE OF ONE- AND TWO-PHASE TRAINING
We first show that training a single layer is insufficient to learn the occurrence language, that is, if either layer is fixed independently of the target, then training the other cannot compensate.
Proposition 2 (Training attention only cannot learn the occurrence language). There exists an absolute constant , such that for every and ,
that is, for any fixed output, there is a target where no attention weight achieves arbitrarily low risk.
Since the bound holds for the infimum over , it applies to any procedure for training the attention weights, not only to gradient descent. A similar result holds with the roles of the two layers exchanged.
Proposition 3 (Training output only cannot learn the occurrence language). There exists an absolute constant , such that for every and ,
that is, for any fixed attention, there is a symbol s, for which no output can achieve an arbitrarily small risk.
Proposition 3 concerns training the output over only one attention head. A natural objection is that fixed attention may suffice with enough heads. In response to this, consider the multi-head extension of (1):
where is the number of heads. One can write the attention weights across heads as and the output weights . With heads, fixed attention does suffice: if each head are initialized to attend to symbol , i.e., satisfies the configuration in Proposition 1, then for any target , when the output weights converge to and for , the transformer achieve arbitrarily small risk. Further, in the limit with random attention weights, training the output layer becomes kernel regression with a deterministic kernel (Hron et al., 2020). The next result shows that substantially fewer than heads, specifically are not enough.
Proposition 4 (Risk lower bound for output-only training with multiple heads). There is an absolute constant , such that when the number of heads , for any and fixed attention ,
The norm constraint is a requirement of our proof technique, and we do not know whether it can be removed. It is, however, not restrictive, since every solution we are aware of has a norm that is constant or decays with . Consider the training plan in Theorem 2 for two cases: if all heads but one are frozen with zero output weights, the single-head solution can be achieved, whose output weights have constant norm . If all heads are trained from identical zero initialization, they remain identical by symmetry, and the parameter will converge to satisfy the configuration in Proposition 1, while will converge to for each head . In this case, the output norm is .
Two-phase training with one-step attention learning. Propositions 2–4 separate the occurrence language from settings in which training a single layer suffices, whether learning the output layer over a fixed representation (Hron et al., 2020; Arda et al., 2026) or learning the features under a fixed output layer (Frei et al., 2023; Han and Ghoshdastidar, 2026; Tarzanagh et al., 2023)—both approaches lead to the risk bounded away from zero for some target. We next consider a two-phase plan: a single gradient step on the attention weights, followed by training the output layer. This scheme is an adaptation of the one-step gradient feature learning in feed-forward networks, where it provably learns certain target classes (Ba et al., 2022; Shi et al., 2023). As we show next, this 2-phase GD training also cannot learn the occurrence language if one starts from uniform attention .
Theorem 1 (Attention-first two-phase GD fails to learn occurrence). There is absolute constant such that the following holds for every , , and . Suppose the transformer is initialized as (uniform attention) and , and one gradient step is used to update the attention weights as
where is unknown but influences the updated attention through the population risk gradient. Then
that is, there is a target for which the optimal output layer on top of the updated attention cannot achieve an arbitrarily small risk.
The proofs of all results in this section are deferred to Appendix A.3-A.6. Together, these impossibility results show that neither layer can be trained alone to learn the occurrence language, and that taking the attention step first does not help. In Section 4, we show that a three-phase training plan (training the output, then the attention, then the output again) does help the transformer to learn the language.
4 LEARNING WITH THREE-PHASE TRAINING
The GD dynamics in Figure 1b show that output weights separate before the attention weights move. This is in line observations of Bietti et al. (2023); Huang et al. (2025) about joint gradient dynamics in other settings. Motivated by this, we study the following three-phase training plan. We initialize , which is agnostic to s, and train as follows:
Phase 1: One GD step on the output with step size and frozen attention: .

Figure 2: Joint GD (left), O-A-O training (middle), and A-O training (right). Attention gap, output gap, and test accuracy for are shown with training and test samples. Joint GD has no phases; for comparison, we start its Phase 2 when the attention starts to move (gap = 0.1, at step 31) and end its Phase 2 when the attention almost saturates (gap = 0.9, at step 127). In the 3-phase plan, the test accuracy reaches 1 by the end of Phase 2. Phase 3 only reduces training loss by fine-tuning output layer.
Phase 2: One GD step on the attention weights with step size and frozen output: .
Phase 3: T steps of GD on the output weights with step size , starting from with the attention fixed at . Formally, and for . We denote the resulting output weights by .
The following theorem shows that this training plan learns the occurrence language for every target symbol up to any specified arbitrarily small risk bound.
Theorem 2 (Three-phase training learns the occurrence language). For every , every target symbol , and every , when the step sizes and steps satisfy: , , , , then the parameters obtained by the above 3-phase training plan satisfy:
We present the complete proof in Appendix A.7, and discuss three implications of the result below.
The role of each phase. Figure 2 compares joint GD, in which both parameters are updated at every step, with the three-phase plan and the attention-first plan. Phase 1 cannot be omitted, otherwise the plan is the attention-first schedule of Theorem 1, in which the attention step receives no guidance from the output layer and may not move towards the target (Figure 2c). Phase 1 also mirrors the early stage of joint GD, where the output separates while the attention weights barely move (Figure 2a). Phase 2 then saturates the attention on the target with a single large step, and Phase 3 trains the output weights towards .
The three-phase training plan differs from joint GD in two ways. First, in joint GD, the output weight on the target symbol can overshoot and then decrease while the attention saturates; freezing the output in Phase 2 removes this effect. Second, in joint GD, attention saturation and output weight convergence occur simultaneously. Our analysis, based on decoupling the two layers, shows that these aspects of joint GD are not necessary for learning. However, our analysis cannot explain this specific behavior of joint GD, which requires analysis of joint training dynamics.
Initialization Although zero initialization ( ) is agnostic to s, it is not standard in practice. We adopt this to simplify the theoretical analysis, as also done in Tarzanagh et al. (2023). Empirically, the same behavior occurs under random initialization (Table 1).
Finite-Sample GD analysis. The population gradient is not accessible in practice. We extend Theorem 2 to finite-sample GD to show that samples suffice to reach a population risk of at most .
Corollary 1 (Three-phase training with finite samples). Consider the same initialization , and the three-phase plan where the gradients of Phases 1 and 2 are computed on the empirical risk of i.i.d. samples from , and the gradients of Phase 3 on the empirical risk of fresh i.i.d. samples. For every , there exists a constant such that the following holds for every , every target symbol , and every . If , , , , and , , then with probability at least over the two draws, the resulting parameters achieve .
The proof is deferred to Appendix A.8. Note that Phase 3 uses a batch of samples independent of those used in Phases 1 and 2. Redrawing samples between training stages is a standard approach in layer-wise training: Ba et al. (2022) finetune the second layer with a new set of samples after one GD step on the first layer, Nichani et al. (2023) also adopt similar sample splitting technique in their layer-wise training plan.
In contrast to the one- or two-phase training plans, the three-phase plan learns the occurrence language for every target symbol with polynomially many samples.
5 EXPERIMENTS
We empirically examine if our three-phase plan learns other language, regression, and in-context learning tasks. We present the setup and discuss the results.
Tasks. We consider six tasks: (i) occurrence; (ii) OR, where a string is positive if it contains at least one of two unknown target symbols; (iii) AND, where a string is positive if it contains both of two unknown target symbols; (iv) even pairs, the language over the binary alphabet of strings where ab and ba occur even number of times (Huang et al., 2025); (v) in-context bigram learning (ICL bigram), a simplified version of Bietti et al. (2023) where the first attention layer is fixed, so that each position locks onto its preceding token; and (vi) single-location regression (SLR) (Marion et al., 2025). For occurrence and OR, we use the single-head model in (1), and for AND its multi-head extension (2) with trainable bias and four heads, since one head cannot express it. For others, we use one-layer, single-head models with similar parameters to our attention and output (see Appendix B.1).
Training plans. We compare joint GD, as a baseline, with five other training plans: (i) attention only (A), corresponds to Proposition 2; (ii) output only (O), corresponds to Proposition 3; (iii) A(1x)→O, matches the plan in Theorem 1; (iv): O(1x)→A(1x)→O, following the phases in Theorem 2; and (v) O(1x)→A(1x): one output step followed by one attention step with a larger step size. The last plan isolates the role of the final output phase. All plans are run from a random initialization, with O(1x)→A(1x)→O additionally from the fixed initialization in Section 4.
We use , training samples, and samples for testing, with the following two exceptions: for even pairs, we train and test on strings of length at most 10 (Huang et al., 2025); for SLR, we fix input length (Marion et al., 2025). All tasks are trained with Mean Squared Error (MSE), except even pairs and ICL bigram, which use the logistic and cross-entropy loss. Other setups can be found in Appendix B.1. We report the train loss and the test accuracy (test loss for SLR) as mean over 50 seeds.
Results. Table 1 shows the performance of various training plans and Figure 3 visualizes corresponding learning progress. We make the following observations.
Which training plans learn each task? Joint GD learns all six tasks, with accuracy at least 0.99 on the five classification tasks and test loss 0.01 on SLR. The three-phase plan matches it on five of them, from both the random and the zero initialization: it reaches accuracy 1.00 on occurrence, OR, even pairs, and ICL bigram, and test loss 0.01 on SLR. No one- or two-phase plan achieves this across the five tasks.
The O(1x)→A(1x) plan shows the contribution of the final phase. On occurrence and ICL bigram, it reaches perfect accuracy, but the training loss remains high. On these tasks, two phases suffice to classify, and the third is needed to reduce the loss. On the other tasks,
Table 1: Train loss and test accuracy (loss for SLR), with mean over 50 seeds. Standard deviations are reported in Appendix B.4. Values below are reported with their upper bounds; those that match or surpass the joint GD baseline are bold. For AND, all attention-training phases have multiple steps instead of one.
| Training plan | Occurrence | OR | AND | Even-Pair | ICL bigram | SLR | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Train Loss | Test Acc. | Train Loss | Test Acc. | Train Loss | Test Acc. | Train Loss | Test Acc. | Train Loss | Test Acc. | Train Loss | Test Loss | ||
| Coupled with rand init. | Joint GD | 1.00 | 1.00 | 0.04 | 0.99 | 0.01 | 1.00 | 1.00 | 0.01 | 0.01 | |||
| Decoupled 1/2/3-phase with random init. | Attention (A) only | 1.64 | 0.50 | 1.67 | 0.50 | 0.24 | 0.94 | 0.69 | 0.51 | 3.90 | 0.02 | 0.50 | 0.50 |
| Output (O) only | 0.74 | 0.86 | 0.68 | 0.85 | 0.79 | 0.75 | 0.63 | 0.50 | 2.70 | 0.16 | 0.48 | 0.48 | |
| A(1x)→O | 0.72 | 0.76 | 0.69 | 0.75 | 0.30 | 0.91 | 0.62 | 0.50 | 2.58 | 0.26 | 0.41 | 0.43 | |
| O(1x)→A(1x) | 0.47 | 1.00 | 0.64 | 0.78 | 0.52 | 0.87 | 0.52 | 0.50 | 3.20 | 1.00 | 0.28 | 0.28 | |
| O(1x)→A(1x)→O | 1.00 | 1.00 | 0.27 | 0.93 | 0.08 | 1.00 | 1.00 | 0.01 | 0.01 | ||||
| Sec 4: 3-phase, zero init. | O(1x)→A(1x)→O | 1.00 | 1.00 | 0.90 | 0.68 | 0.08 | 1.00 | 1.00 | 0.01 | 0.01 | |||
two phases are not enough, even for classification.
AND is the exception. From the random initialization, the three-phase plan only reaches an accuracy of 0.93, below joint GD (0.99), and attention-only training matches it (0.94). The three-phase plan with zero initialization performs worse than with random initialization, since all heads remain identical throughout training and cannot express the language. We return to further discussions of AND in Section 6.
Learning progress of joint GD and the phased plans. The final train loss and test accuracy / loss show that the three-phase plan can learn other formal languages, but they do not show how the output and attention weights evolve during the learning process. We therefore ask two further questions. First, does joint GD exhibit the same order of learning on these tasks as on the occurrence language, with the output weights separating before the attention weights move? Second, how closely do the trajectories of different phased plans follow that of joint GD?
Figure 3 addresses both questions. First, on AND, ICL bigram, and SLR, joint GD follows the same order as on occurrence and OR: the attention gap stays near zero while the output gap grows, and only begins to rise when the output separates significantly. even pairs is slightly different: under joint GD, the output only leads at a very short period, and the attention grows as fast as the output during the remaining training time, and the attention saturates before the output does. However, this still satisfies the principle that attention lags output learning at the start of learning.
For the second question, the three-phase plan yields the same final gaps as joint GD on even pairs, ICL bigram, and SLR. On ICL bigram and SLR, the trajectories follow a similar path as joint GD. On even pairs, the paths differ: the first output step of the three-phase plan already brings the gap close to its ideal value, whereas under joint GD the output gap grows slowly throughout. On AND, joint GD overshoots the ideal output gap while the attention saturates, as on the occurrence language, whereas the output gap of the three-phase plan remains below the ideal value, consistent with its lower accuracy in Table 1.
The other plans show how the order matters. In A(1x)→O, the attention step leaves the attention gap near zero on ICL bigram and SLR, and the subsequent output training cannot compensate. On AND, in contrast, the attention gap grows even when the attention is trained first or alone, possibly because the anti-symmetric initialization ensures that some heads favor a target symbol from the start. Finally, on even pairs, ICL bigram and SLR, output-only training aligns the output with the ideal direction, yet Table 1 shows that it does not learn the task: correct output alone is insufficient without correct attention.
6 DISCUSSIONS
In this work, we study the (decoupled) training dynamics of a shallow transformer that recognizes a star-free language—the occurrence language—from inputs of unbounded length. We prove that one-step attention learning succeeds when it lags output layer learning. The natural two-phase adaptation of gradient feature learning—a single attention update followed by training the output layer—provably fails for some target symbol, as does training either layer alone (Propositions 2–4, Theorem 1). However, a three-phase training plan—involving one-step attention learning, sandwiched between two phases of output layer training—suffices to learn the occurrence language (Theorem 2, Corollary 1). The underlying mechanism is simple: the gradient of the attention is driven by the separation of the output, so the attention receives no signal about the target symbol until the output layer is informative.

Figure 3: Attention and output gaps on four tasks. Mean ± standard deviation over 50 runs; dotted lines mark the ideal gaps (see Appendix B.2). Phases are defined as in Figure 2; single-layer plans end after Phase 1 and A→O after Phase 2. For AND, we plot the head with the largest gap for each plan (all heads: Appendix B.3). For even pairs and SLR, the output gap is and , with the max-margin and the ground-truth direction. Since depends on the attention weights, the output gap on even pairs can change in Phase 2 although the output is frozen. O→A and the zero initialization are omitted, as they coincide with the first two phases of O→A→O and with the random initialization, respectively. The trajectories on OR resemble those on occurrence in Figure 2 and are deferred to Appendix B.5.
We expect this mechanism to be relevant beyond the specific problem studied in this paper. Our experiments already show that, in many cases, attention learning lags output learning, and the accuracy rises only once the attention begins to saturate. This may help explain the “abrupt learning” observed in transformers (Singh et al., 2024; Gopalani and Hu, 2025). Our impossibility results also suggest that parameter-efficient methods where only the attention or the output layer is finetuned can be fundamentally limited, and that the common theoretical assumption of a faster-learning output layer (Tian et al., 2023; Chen et al., 2024) may reflect a necessary order of learning. A broad open problem is to establish these connections for deeper models and richer tasks. Our multi-phased training paradigm could complement existing works on joint training dynamics of shallow Transformers (Yang et al., 2024; Huang et al., 2025) to investigate this question. We also note specific questions to build upon the presented results.
Finite sample complexity and realistic transformer. The focus of the present study was on the interplay of (decoupled) attention and output layer training. To derive this, we made two key simplifications—focused on population training risk and parameterized the transformer by . Parameterization in terms of key, query, value matrices leads to an overparametrized system in this case and, as shown in Tarzanagh et al. (2023), leads to different dynamics and implicit biases of GD. While the finite sample analysis in Corollary 1 shows that samples suffice, we do not know if such a sample complexity is necessary for the occurrence language. Furthermore, we assume a batch-GD-style split of training data across phases, and the complexity could differ considerably depending on use of full batch GD or stochastic GD (SGD)—a topic that is currently investigated for parity learning (Abbe et al., 2023).
Attention-first training with multiple heads. Table 1 shows that the AND task is the one case where the three-phase plan does not match joint GD, and where training the attention alone does equally well. A possible explanation is from the multi-head model we use for this task. With four heads and a random output layer, the output weights for some heads may already separate a target symbol at initialization, so that their attention receives a useful gradient without a preceding output step. This mirrors prior work on feedforward networks (Ba et al., 2022; Shi et al., 2023), where wider networks can make feature-first learning sufficient. It suggests that the lower bounds for single-layer and attention-first training weaken as the number of heads increases, and that the training order matters most for narrow and shallow models. How many heads are needed for attention-only or attention-first training to succeed is an open question.
Learnability and the expressivity hierarchy for transformers. The expressive power of transformers over formal languages is well studied: depending on the attention model, depth, and position embeddings, they recognize the star-free languages and beyond (Strobl et al., 2024; Barceló et al., 2024). However, expressivity does not guarantee learnability, and our work is only a first step towards a theory of transformer learnability. We establish lower bounds and a convergence guarantee for a single language, and show empirically that the three-phase plan extends to a few other star-free languages. These languages also form a very limited subset of the star-free class: occurrence, OR, and AND are piecewise testable, among the simplest star-free languages, and even pairs compares only the first and last symbols. Characterizing which formal languages are learnable or not learnable by transformers with GD remains wide open. A multi-phase training leads to simple decoupled dynamics and could be potentially useful to answer this question.
AI use statement
In this work, we used generative AI tools to assist in the writing of proofs and provide feedback on research methodology or experiments. We have not used generative AI tools to generate synthetic datasets, help develop theoretical models or conceptual frameworks, formulate mathematical claims, provide critical ingredients for proving mathematical claims, propose or refine hypotheses, implement methods, support data analysis, or interpret results. Cleaning and reformating datasets, and assisting with translation, are not applicable to this work.
Additionally, we used generative AI tools to improve scientific figures, suggest experimental parameters, edit software code, and identify relevant literature.
We have reviewed all AI-assisted work. LLM-generated code was verified and refactored by human authors; we use LLM to restructure the proof and check line by line afterward. We take responsibility for the final content of this work, including text, claims, or artifacts produced with the aid of generative AI.
Acknowledgment
This work has been supported by the German Research Foundation (DFG) through the Research Training Group GRK 2428 ConVeY.
REFERENCES
Emmanuel Abbe, Enric Boix Adserà, and Theodor Misiakiewicz. Sgd learning on neural networks: leap complexity and saddle-to-saddle dynamics. In Gergely Neu and Lorenzo Rosasco, editors, The Thirty Sixth Annual Conference on Learning Theory, COLT 2023, 12-15 July 2023, Bangalore, India, volume 195 of Proceedings of Machine Learning Research, pages 2552–2623. PMLR, 2023.
Enes Arda, Semih Cayci, and Atilla Eryilmaz. Finite-time analysis of gradient descent for shallow transformers. CoRR, abs/2601.16514, 2026. doi: 10.48550/ARXIV.2601.16514. URL https://doi.org/10.48550/arXiv.2601.16514.
Jimmy Ba, Murat A. Erdogdu, Taiji Suzuki, Zhichao Wang, Denny Wu, and Greg Yang. High-dimensional asymptotics of feature learning: How one gradient step improves the representation. In Sanmi Koyejo, S. Mohamed, A. Agarwal, Danielle Belgrave, K. Cho, and A. Oh, editors, Advances in Neural Information Processing Systems 35: Annual Conference on Neural Information Processing Systems 2022, NeurIPS 2022, New Orleans, LA, USA, November 28 - December 9, 2022, 2022.
Pablo Barceló, Alexander Kozachinskiy, Anthony Widjaja Lin, and Vladimir V. Podolskii. Logical languages accepted by transformer encoders with hard attention. In The Twelfth International Conference on Learning Representations, ICLR 2024, Vienna, Austria, May 7-11, 2024. OpenReview.net, 2024.
Pablo Barceló, David Chiang, George Cybenko, Lena Strobl, and Andy Yang. Theory of neural language models (dagstuhl seminar 25282). Dagstuhl Reports, 15(7):22–52, 2025.
Alberto Bietti, Vivien Cabannes, Diane Bouchacourt, Hervé Jégou, and Léon Bottou. Birth of a transformer: A memory viewpoint. In Alice Oh, Tristan Naumann, Amir Globerson, Kate Saenko, Moritz Hardt, and Sergey Levine, editors, Advances in Neural Information Processing Systems 36: Annual Conference on Neural Information Processing Systems 2023, NeurIPS 2023, New Orleans, LA, USA, December 10 - 16, 2023, 2023.
Alexandra Butoi, Ghazal Khalighinejad, Anej Svete, Josef Valvoda, Ryan Cotterell, and Brian DuSell. Training neural networks as recognizers of formal languages. In The Thirteenth International Conference on Learning Representations, ICLR 2025, Singapore, April 24-28, 2025. OpenReview.net, 2025. URL https://openreview.net/forum?id=aWLQTbFfGv.
Siyu Chen, Heejune Sheen, Tianhao Wang, and Zhuo-ran Yang. Unveiling induction heads: Provable training dynamics and feature learning in transformers. In Amir Globersons, Lester Mackey, Danielle Belgrave, Angela Fan, Ulrich Paquet, Jakub M. Tomczak, and Cheng Zhang, editors, Advances in Neural Information Processing Systems 37: Annual Conference on Neural Information Processing Systems 2024, NeurIPS 2024, Vancouver, BC, Canada, December 10 - 15, 2024, 2024.
Amit Daniely and Eran Malach. Learning parities with neural networks. In Hugo Larochelle, Marc'Aurelio Ranzato, Raia Hadsell, Maria-Florina Balcan, and Hsuan-Tien Lin, editors, Advances in Neural Information Processing Systems 33: Annual Conference on Neural Information Processing Systems 2020, NeurIPS 2020, December 6-12, 2020, virtual, 2020.
Elvis Dohmatob. Understanding softmax attention layers: Exact mean-field analysis on a toy problem. In Danielle Belgrave, Cheng Zhang, Laura N. Montoya, Hsuan-Tien Lin, Razvan Pascanu, Piotr Koniusz, Marzyeh Ghassemi, Nancy Chen, Iván Vladimir Meza Ruíz, and Arturo Loaiza-Bonilla, editors, Advances in Neural Information Processing Systems 38: Annual Conference on Neural Information Processing Systems 2025, NeurIPS 2025,
San Diego, CA, USA, December 2-7, 2025 / Mexico City, Mexico, November 30 - December 5, 2025, 2025.
Spencer Frei, Niladri S. Chatterji, and Peter L. Bartlett. Random feature amplification: Feature learning and generalization in neural networks. J. Mach. Learn. Res., 24:303:1–303:49, 2023.
Pulkit Gopalani and Wei Hu. What happens during the loss plateau? understanding abrupt learning in transformers. In Advances in Neural Information Processing Systems 38: Annual Conference on Neural Information Processing Systems 2025, NeurIPS 2025, San Diego, CA, USA, December 2-7, 2025 / Mexico City, Mexico, November 30 - December 5, 2025, 2025.
Yaomengxi Han and Debarghya Ghoshdastidar. Transformers provably learn sparse xor with polylogarithmic parameters, 2026. URL https://arxiv.org/abs/2502.07553.
Jiri Hron, Yasaman Bahri, Jascha Sohl-Dickstein, and Roman Novak. Infinite attention: NNGP and NTK for deep attention networks. In Proceedings of the 37th International Conference on Machine Learning, ICML 2020, 13-18 July 2020, Virtual Event, volume 119 of Proceedings of Machine Learning Research, pages 4376–4386. PMLR, 2020.
Ruiquan Huang, Yingbin Liang, and Jing Yang. How transformers learn regular language recognition: A theoretical study on training dynamics and implicit bias. In Forty-second International Conference on Machine Learning, ICML 2025, Vancouver, BC, Canada, July 13-19, 2025, volume 267 of Proceedings of Machine Learning Research. PMLR / OpenReview.net, 2025.
Anthony W. Lin and Pablo Barceló. The role of logic and automata in understanding transformers. In Pierre Ganty and Alessio Mansutti, editors, Reachability Problems - 19th International Conference, RP 2025, Madrid, Spain, October 1-3, 2025, Proceedings, volume 16230 of Lecture Notes in Computer Science, pages 17–30. Springer, 2025.
Bingbin Liu, Jordan T. Ash, Surbhi Goel, Akshay Krishnamurthy, and Cyril Zhang. Transformers learn shortcuts to automata. In The Eleventh International Conference on Learning Representations, ICLR 2023, Kigali, Rwanda, May 1-5, 2023. OpenReview.net, 2023a.
Bingbin Liu, Jordan T. Ash, Surbhi Goel, Akshay Krishnamurthy, and Cyril Zhang. Exposing attention glitches with flip-flop language modeling. In Alice Oh, Tristan Naumann, Amir Globerson, Kate Saenko, Moritz Hardt, and Sergey Levine, editors, Advances in Neural Information Processing Systems
36: Annual Conference on Neural Information Processing Systems 2023, NeurIPS 2023, New Orleans, LA, USA, December 10 - 16, 2023, 2023b.
Kaifeng Lyu and Jian Li. Gradient descent maximizes the margin of homogeneous neural networks. In 8th International Conference on Learning Representations, ICLR 2020, Addis Ababa, Ethiopia, April 26-30, 2020. OpenReview.net, 2020.
Pierre Marion, Raphaël Berthier, Gérard Biau, and Claire Boyer. Attention layers provably solve single-location regression. In The Thirteenth International Conference on Learning Representations, ICLR 2025, Singapore, April 24-28, 2025. OpenReview.net, 2025. URL https://openreview.net/forum?id=DVlPp7Jd7P.
Eshaan Nichani, Alex Damian, and Jason D. Lee. Provable guarantees for nonlinear feature learning in three-layer neural networks. In Alice Oh, Tristan Naumann, Amir Globerson, Kate Saenko, Moritz Hardt, and Sergey Levine, editors, Advances in Neural Information Processing Systems 36: Annual Conference on Neural Information Processing Systems 2023, NeurIPS 2023, New Orleans, LA, USA, December 10 - 16, 2023, 2023.
Zhenmei Shi, Junyi Wei, and Yingyu Liang. Provable guarantees for neural networks via gradient feature learning. In Alice Oh, Tristan Naumann, Amir Globerson, Kate Saenko, Moritz Hardt, and Sergey Levine, editors, Advances in Neural Information Processing Systems 36: Annual Conference on Neural Information Processing Systems 2023, NeurIPS 2023, New Orleans, LA, USA, December 10 - 16, 2023, 2023.
Aaditya K. Singh, Ted Moskovitz, Felix Hill, Stephanie C. Y. Chan, and Andrew M. Saxe. What needs to go right for an induction head? A mechanistic study of in-context learning circuits and their formation. In Forty-first International Conference on Machine Learning, ICML 2024, Vienna, Austria, July 21-27, 2024, volume 235 of Proceedings of Machine Learning Research, pages 45637–45662. PMLR / OpenReview.net, 2024.
Lena Strobl, William Merrill, Gail Weiss, David Chiang, and Dana Angluin. What formal languages can transformers express? A survey. Trans. Assoc. Comput. Linguistics, 12:543–561, 2024. doi:10.1162/TACL_A_00663.
Davoud Ataee Tarzanagh, Yingcong Li, Christos Thrampoulidis, and Samet Oymak. Transformers as support vector machines. In NeurIPS 2023 Workshop on Mathematics of Modern Machine Learning, 2023.
Yuandong Tian, Yiping Wang, Beidi Chen, and Simon S. Du. Scan and snap: Understanding training dynamics and token composition in 1-layer transformer. In Advances in Neural Information Processing Systems 36: Annual Conference on Neural Information Processing Systems 2023, NeurIPS 2023, New Orleans, LA, USA, December 10 - 16, 2023, 2023.
Joel A. Tropp. An introduction to matrix concentration inequalities. CoRR, abs/1501.01571, 2015. doi: 10.48550/ARXIV.1501.01571. URL https://doi.org/10.48550/arXiv.1501.01571.
Zixuan Wang, Stanley Wei, Daniel Hsu, and Jason D. Lee. Transformers provably learn sparse token selection while fully-connected nets cannot. In Ruslan Salakhutdinov, Zico Kolter, Katherine A. Heller, Adrian Weller, Nuria Oliver, Jonathan Scarlett, and Felix Berkenkamp, editors, Forty-first International Conference on Machine Learning, ICML 2024, Vienna, Austria, July 21-27, 2024, volume 235 of Proceedings of Machine Learning Research, pages 51854–51912. PMLR / OpenReview.net, 2024.
Kaiyue Wen, Huaqing Zhang, Hongzhou Lin, and Jingzhao Zhang. From sparse dependence to sparse attention: Unveiling how chain-of-thought enhances transformer sample efficiency. In The Thirteenth International Conference on Learning Representations, ICLR 2025, Singapore, April 24-28, 2025. OpenReview.net, 2025. URL https://openreview.net/forum?id=AmEgWDhmTr.
Hongru Yang, Bhavya Kailkhura, Zhangyang Wang, and Yingbin Liang. Training dynamics of transformers to recognize word co-occurrence via gradient flow analysis. In Amir Globersons, Lester Mackey, Danielle Belgrave, Angela Fan, Ulrich Paquet, Jakub M. Tomczak, and Cheng Zhang, editors, Advances in Neural Information Processing Systems 37: Annual Conference on Neural Information Processing Systems 2024, NeurIPS 2024, Vancouver, BC, Canada, December 10 - 15, 2024, 2024.
A PROOFS FOR THE MAIN RESULTS
A.1 Notations and Preliminaries
We introduce some notations, and provide a few calculations that is useful for the remainder of the proofs. The general per-sample gradients of with respect to each parameter for each index is listed as follows:
We write the expectations of first and the second conditional moments of at initialisation :
(3)
(4)
(5)
For the background positions , we have:
A.2 Proof of Proposition 1
Proof. Since and for every , we have . One can verify that for every , and hence, the negative examples do not contribute to the loss. For the positive examples , we separately consider words of length shorter or longer than . Since length is a geometric random variable, . Since the squared loss remains bounded by 2 for the choice of , the contribution of long words to the risk is bounded by .
For short words, with , the attention is bounded from below as , and from above since due to softmax. Hence, the loss for any short word is bounded as . Hence, short words also contribute to at most risk, and overall .
A.3 Proof of Proposition 2
Proof. Let the target index be and discuss the loss based on its value. When , it follows that for any input and any attention weights . In this case, the expected risk is lower bounded by .
When , we lower bound the risk incurred on negative samples of length together with their positive counterparts. For a given of length , consider all positive samples obtained by inserting copies of into . write , we first compute the ratio of the two probability masses:
Therefore, for each negative sample whose length satisfies , it holds that .
For each negative sample , write the output as , then for each of the positive counterpart , we have . Now we distinguish two cases:
-
: then , and the error on the negative sample is .
-
If : since , the convex combination for every , so , giving on every positive counterpart, regardless of or .
In either case, the probability mass of samples with an error greater than is at least . Summing over the window where the negative samples has length , we get:
where the last inequality follows from the monotonicity of the bound on the even and odd sequences of , minimized at and respectively.
A.4 Proof of Proposition 3
Proof. We consider the target symbol as . First, consider any , we can lower bound the expected risk by summing up the error on all samples made from only the set symbols:
Otherwise, when , we consider the prediction for every negative sample whose length satisfies and its corresponding positive counterparts where we insert one into . We first compute the ratio between the two masses, which gives:
For each negative sample , write the output as . And for each counterpart . Now we distinguish two cases:
-
: then , and the error on the negative sample is at least .
-
: since for any , we have , and , therefore the error on each is at least .
In either case, the probability mass of samples with an error greater than is at least . Summing over the window where the negative samples has length , we have:
□
A.5 Proof of Proposition 4
We begin by selecting the target index that receives a low attention score. We first prove that such an index exists:
Lemma 1 (Existence of Index with Low Attention). For any fixed attention weights , there exists , such that .
Proof. By the definition of softmax, for each string and each head , for every , hence:
Taking expectation over and summing over all heads gives . Therefore, there exists an index such that .
We choose that satisfies Lemma 1 as the target index. Consider any negative string whose length satisfies , it follows that . Let be the set of positive strings which after removing all will result in , we have . Further, we can consider the ratio between the two masses, which simplifies into:
For any , we can write the output as , where . Since and , we have:
where the last step is from Cauchy-Schwarz inequality over the heads.
For each negative string and each , we define a coupling weight . First, it directly follows that . Second, . Since in the length window we considered for , it holds that , hence the total coupling mass is lower bounded by:
We write . For any , we have . Plug in , we get . Since , we get for all , so . Using the other side of the inequality, since and , we have , which gives us . Combining both sides, we have , which is an absolute constant independent of .
Define . Since , we have:
using Lemma 1 in the last step. Finally, by Jensen's inequality, we have:
For every pair , and . Denote and , we have . Since is convex, combining Jensen's inequality and Eq. 10, we have:
Because and as established above, the weighted sum is bounded above by the corresponding disjoint contribution to , hence we can bound the risk by:
Equivalently, when the number of heads , the loss is lower bounded by . Since we know the output norm is bounded by , we have that when , the loss is lower bounded by .
A.6 Proof of Theorem 1
Proof. First, we prove that for whatever we obtained after the first step, if then the population risk is already lower bounded by a constant. Here is an arbitrary vector. Consider all positive samples with only , then:
Hence in the rest of the analysis, we will only consider the case where . Now we prove that after the first gradient step, we can find an index such that after the update, . Consider the following sum of the gradients:
So there exists such that and . Consider the sum of gradients of across all indices:
hence it follows regardless of the learning rate. Therefore, . At the same time, , which results in . We will shorthand in the remaining analysis. Now we consider a negative string with length , where , and the set of its positive counterparts where each is obtained by inserting exactly one symbol into . From (9) we have .
For each counter part , write . Consider the two following cases:
-
. In this case, the probability that the maximizer appears in string is , under which case we have .
-
. In this case, consider the r.v. , and we rewrite . We further derive the first and the second moments of :
Hence, the first and the second moments of can be written as:
Using the Paley-Zygmund inequality, we have:
Since , we have . Under which case we have .
For each , let .
Conditional on and , the symbols of are i.i.d. uniform on . The two cases before show that . Fix any final output vector with , and write . For every , either , in which case , or . In the latter case, for every , we have , so .
Consequently, it follows that . The sets are disjoint across negative strings . Hence, with , .
For the last inequality, when , , and . Combining this bound with the earlier case , which gives , proves the theorem with .
A.7 Proof of Theorem 2
Proof. Throughout this proof, denotes the output weights after Phase 1, the attention weights after Phase 2, and the output weights after steps of Phase 3, so that and . We first prove the following lemma.
Lemma 2 (Induction on Symmetry). For any target index , if at the current step we have and for every pair of background indices , then after one step of population GD, the updated parameters satisfy , and .
Proof. For any fixed target index , let denote the transposition swapping while keeping other indices fixed. For any string , we write . It follows that for every . Moreover, since , swapping and will not change the acceptance of the string, i.e., .
Next, define the corresponding action on parameters: for , let denote the parameter vector obtained by swapping with and with , leaving all other coordinates fixed. It follows that for every .
Combining these three facts, the population loss is invariant under this joint relabeling:
Therefore, for every pair of weights , it holds that . Since the current parameters satisfy and , then , and the identities above rewrites as . Plugging these equalities into the GD update rule we have . Same equality holds for as well.
With this lemma, and the symmetrical initialisation for and , the parameter can be reduced to 4 scalars, and for the target, and , as the common weight for the background indices. We also shorthand as the aggregated softmax-attention score for symbol , note that sample-wise there is no symmetry for when , but on expectation level we have which is shared by all background indices . We also shorthand and .
First Phase In the first step, we calculate the gradient for and in closed forms:
Hence, the updated parameter is , for every . The separation of target and the background output weights grows from to . We choose the learning rate of the first phase to be and therefore the separation will be controlled within a constant range .
Second Phase In the second phase, we calculate the gradient for and in closed forms:
Consider , we have for every , therefore for positive words and , hence we get an upper bound for the target gradient (which holds for negative words too since ):
At uniform attention, the moments in (3) and (4) give for every . Hence we have and . Combining both bounds, the attention gap after the second step satisfies
For a positive string with and ,
Since , we obtain
Third Phase During the third step, the attention is fixed at , so is a convex quadratic function w.r.t. with Hessian . Let for , so that and . Let and .
On , the risk is minimized at with:
And the expected risk at this point will be:
Moreover, we have and .
At any step in the third phase, the symmetry is preserved for the , , and the among all indices , as a result of Lemma 2. Since minimizes the risk over , its gradient is orthogonal to and hence zero. Therefore, for every ,
and the GD iterates with satisfy . By Lemma 2, all iterates lie in , so only the restriction of to matters. Take an orthonormal basis of , where span the subspace . We can then block-diagonalize in this basis as with , where acts on span . Each component of has closed forms:
where we used that and . Hence for , and
using . Since also , each step contracts the error by a factor of at most .
At the beginning of Phase 3, output starts from , with and , so . Therefore when plugging in . After steps we have and hence .
A.8 Proof of Corollary 1
Proof. We use denotes the first batch, and for any function of a sample we write for its average over this batch. In Phases 1 and 2, , so .
With respect to the first draw of samples, we consider the following variables. For any sample and , we define , . Note that none of these quantities depend on the trained parameters but their randomness come from the raw strings that are drawn.
Lemma 3 (Concentration on the first batch). For every , there exists a constant such that, when , with probability at least , the following event holds:
-
for every ;
-
-
for every .
Proof. All of , , take values in . We can bound their second moments by:
Hence, we can use as a common upper bound for the three terms above. And we also have for all . By Bernstein's inequality, for each statement in the event , the failure probability of the each term can be bounded by:
Taking the union bound of all the statements, choosing with large enough (depending on ) makes the combined failure at most .
First Phase. When , the output is on every string, so and the updated output weight becomes . By the moment of the attention scores specified in (6), (7), (8), and , we have , for every . With Lemma 3 and , we have:
Second Phase. For a sample and , we define , Then the empirical gradient w.r.t. can be written as , hence for every background symbol :
Since the gap and the output weights depend on the same batch of samples, we will not apply a concentration inequality directly to . Instead, we bound sample by sample, in terms of and .
We first consider a lowe bound for . For negative samples, we have , then and . If , then by (11), and by (12). Hence for every sample, regardless of positive or negative, and by Lemma 3, when happens:
Then we bound from above. For positive samples, , then , and
since the first term is negative and the second is bounded by (13). For negative samples , then , , and . For both positive and negative samples, we have , and by Lemma 3, we have .
Combining both bounds with (14), on the event , the empirical attention gap is bounded by:
Third phase. Conditioned on event happens with the first batch, we fix . All probabilities below are over the fresh batch , which is independent of . From here on, denotes the attention weights under , , and we denote the expected as well as the empirical hessians of as and . We write and for the empirical risk on the fresh batch. In contrast to the third phase of population GD, we do not analyze the convergence of to the risk minimizer. Instead, we compare the iterates with the fixed reference point .
We first prove that the reference point has negligible risk. Let . For negative samples, . For positive samples, when and , we have
Note that this bound does not depend on how the attention is distributed among the non-target symbols. Define the random variable and . Since , we can bound the expectation of by:
and by Markov's inequality, we have with probability at least .
Now we compare population and empirical risk through . For every and every string , we have , and the loss can be bounded from above and below by:
from the inequalities and . In particular, .
The empirical risk is a convex quadratic with Hessian , so it is 1-smooth. Let and let denote the GD iterates with . By the descent lemma and convexity, for every ,
and is non-increasing in . Summing over yields
By (11) and (13), and , hence . Together with , (19) gives
We next consider the concentration on the hessian with the following lemma:
Lemma 4. Let and assume . Then, with probability at least ,
Proof. Let and define the independent positive semidefinite matrices
Then , so , and . By the matrix Chernoff inequality (Tropp, 2015), we have:
On the complementary event, , that is, , proving the claim.
On the events of Step 1 and Lemma 4, which hold simultaneously with probability at least , we combine (17), Lemma 4, (18) and (20):
We bound the three terms by each. The first term, we can set the training step ; for the second term, we set , then . For the third term, since , by (16) we know if . By (15), this will hold if , which is implied by for a suitable constant . Hence with . A union bound over the event and the two events above gives a total probability at least .
B ADDITIONAL EXPERIMENTS
B.1 Experiment Setup
To produce the experiment results, we adopt the following initialization, losses, step sizes, and step counts:
Models. For even pairs and SLR, we use the one-layer, single-head models of Huang et al. (2025) and Marion et al. (2025), with parameters and , respectively, where is the embedding dimension. In both cases the first parameter plays the role of our attention weights and the second that of our output weights. For ICL bigram, we use a single attention layer with one-hot token embeddings and parameters . Given the query token , position receives the attention logit , which depends on its preceding token through the fixed first layer. The model outputs the logits over the next token and is trained with the cross-entropy loss. Here, and play the roles of our attention and output weights, respectively.
Initialization. Table 2 lists the initializations. AND differs in three respects. First, we draw with i.i.d. entries and set , which prevents head collapse. Second, in the plans , , and , the attention phase consists of 1250 GD steps instead of one, since a single step did not suffice for the heads to attend to different targets.
Table 2: Initializations. The fixed initialization is used only for O→A→O; Gaussian entries are i.i.d.
| Task | Fixed | Random |
|---|---|---|
| Occurrence, OR | ||
| AND | see text | |
| Even pairs | ||
| ICL-bigram | ||
| SLR |
Step sizes and counts. Every plan is built from the same three ingredients: a base step size for multi-step phases and for joint GD, and the step sizes and of the single output and attention steps. Table 3 gives the schedule of each plan and Table 4 gives the values per task.
For squared-loss experiments, we minimize and report MSE without the factor 1/2 used in the theoretical analysis. An experimental learning rate therefore corresponds to under the theoretical loss normalization.
Table 3: Schedule of each training plan. “A: ” means one GD step on the attention weights with step size ; “O: ” means 2500 GD steps on the output weights with step size .
| Plan | Phase 1 | Phase 2 | Phase 3 |
|---|---|---|---|
| A only | A: | - | - |
| O only | O: | - | - |
| A: | O: | - | |
| O: | A: | - | |
| O: | A: | O: | |
| Joint GD | A and O jointly: | ||
Table 4: Step sizes per task. For AND, the attention phase uses multiple steps with the base step size (see text).
| Task | |||
|---|---|---|---|
| Occurrence | 1 | 50/3 | 500 |
| OR | 1 | 12.5 | 500 |
| AND | 0.25 | 8 | - |
| Even pairs | 1 | 100 | 1000 |
| SLR | 0.03 | 3 | 100 |
| ICL bigram | 50 | 625 | 25,000 |
For AND, every single attention step is replaced by a multi-step phase with step size : A→O uses 1250 attention steps followed by 1250 output steps, O(1x)→A uses one output step followed by 1250 attention steps, and O(1x)→A→O uses 1250 attention steps in the second phase and 1250 output steps in the third.
B.2 Attention and Output Gaps
OR. With target set , the attention gap is . The output gap is .
AND. For each head , let be the target that head favours. Its attention gap is . Heads are ranked by their final gap, separately in every run.
even pairs. Let be the attention output, where are the attention weights under . The attention measure is the linear separability of over all strings. It is the accuracy of the max-margin linear classifier through the origin, computed with a squared-hinge SVM with . The output gap is . Since is recomputed from the current attention, this gap can change while is frozen.
ICL bigram. For a sequence with query , let be the position after the query key, i.e., the position with . The attention gap is the average over the training sequences of , with weights . The output gap is , using the Frobenius inner product. Here and are and the identity with each column centered over the classes.
SLR. With the relevant location of a sample, the attention gap is the average over the training samples of . The output gap is with the ground-truth direction .
Compute resources. All experiments were run on an Apple MacBook Air with an M2 chip (8 CPU cores) and 8 GB of unified memory, running macOS 14.4. No GPU was used; all training is full-batch GD on the CPU.

Figure 4: The learning progress of the AND task for each head, with average trajectory and std (shade). The heads are ranked by the gap they reach at the end, per head and per run.
B.3 Learning progress for AND task across all heads.
Figure 4 shows the evolution of the per-head attention gap for the AND task. Under all training plans, at most two of the four heads develop a positive gap, with the gaps of Heads 3 and 4 staying near zero or becoming negative. The plans differ mostly in the second head. Under joint GD, both Head 1 and Head 2 reach a gap close to the ideal value, so the two heads attend to the two target symbols. Under the three-phase plan, Head 1 saturates closely in the same way, but the gap of Head 2 reaches only about 0.4 on average, with a large variance across runs: in many runs, the second target symbol receives little more attention than the non-target symbols. A→O and attention-only training show the same pattern, with one head close to saturation and a weaker second head. This explains why the phased plans do not match joint GD on AND in Table 1: recognizing the language requires attending to both target symbols, and only joint GD reliably achieves this.
B.4 Complete results with standard deviation.
Table 5: Train loss and test accuracy (loss for SLR) as mean over 50 seeds, with the standard deviation in parentheses. Values are shown in upper bounds; those that match or surpass joint GD are bold. The red entries are deterministic runs because the training and test sets are the entire instance space.
| Training plan | Occurrence | OR | AND | Even-Pair | ICL bigram | SLR | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Train Loss | Test Acc. | Train Loss | Test Acc. | Train Loss | Test Acc. | Train Loss | Test Acc. | Train Loss | Test Acc. | Train Loss | Test Loss | ||
| Coupled with rand init. | Joint GD | 1.00(0.00) | (10) | 1.00(0.00) | 0.04(0.06) | 0.99 | 0.01 | 1.00(0.00) | (10) | 1.00(0.00) | 0.01 | 0.01 | |
| Decoupled 1/2/3-phase with random init. | Attention (A) only | 1.64(0.08) | 0.50(0.01) | 1.67(0.06) | 0.50(0.01) | 0.24(0.18) | 0.94(0.07) | 0.69 | 0.51(0.02) | 3.90(0.00) | 0.02(0.01) | 0.50(0.02) | 0.50(0.02) |
| Output (O) only | 0.74(0.05) | 0.86(0.01) | 0.68(0.04) | 0.85(0.02) | 0.79(0.03) | 0.75(0.02) | 0.63(0.00) | 0.50(0.00) | 2.70(0.04) | 0.16(0.01) | 0.48(0.01) | 0.48(0.01) | |
| A(1x)→O | 0.72(0.26) | 0.76(0.13) | 0.69(0.21) | 0.75(0.11) | 0.30(0.19) | 0.91(0.09) | 0.62(0.02) | 0.50(0.11) | 2.58(0.86) | 0.26(0.22) | 0.41(0.14) | 0.43(0.14) | |
| O(1x)→A(1x) | 0.47(0.07) | 1.00(0.00) | 0.64(0.07) | 0.78(0.19) | 0.52(0.19) | 0.87(0.07) | 0.52 | 0.50 | 3.20(0.02) | 1.00(0.00) | 0.28(0.03) | 0.28(0.03) | |
| O(1x)→A(1x)→O | (10) | 1.00(0.00) | (10) | 1.00(0.00) | 0.27(0.13) | 0.93(0.06) | 0.08 | 1.00(0.00) | (10) | 1.00(0.00) | 0.01 | 0.01 | |
| Sec. 4: 3-phase, zero init. | O(1x)→A(1x)→O | (10) | 1.00(0.00) | (10) | 1.00(0.00) | 0.90(0.02) | 0.68(0.02) | 0.08(0.00) | 1.00(0.00) | (10) | 1.00(0.00) | 0.01 | 0.01 |
B.5 Learning progress on occurrence and OR
Figure 5 shows the trajectories on occurrence and OR for all training plans. Both tasks behave as in Figure 2: under joint GD, the output gap grows first, overshoots while the attention saturates, and then settles at its ideal value, and the three-phase plan reaches the same final gaps. When the attention is trained first or alone, its gap moves in the wrong direction, and the output weights then grow far beyond their ideal value.

Figure 5: Attention and output gaps on occurrence and OR. Notation and phases are as in Figure 3.