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 [19 ] —as well as from the viewpoint of learning specific tasks, like learning parity, sparse polynomial or gaussian mixture classification [9 , 1 , 11 ] . A notable theoretical insight has emerged in this context, sometimes referred to as one-step gradient feature learning [3 , 22 ] —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 [1 , 22 ] .
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 [24 ] .
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 [22 ] —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 A s = Σ ∗ s Σ ∗ A_s = \Sigma^*s\Sigma^* A s = Σ ∗ s Σ ∗ on the finite alphabet Σ = { 1 , … , d } \Sigma= \{1,\ldots,d\} Σ = { 1 , … , d } , i.e., the language of all words containing s s s , where s ∈ Σ s \in\Sigma s ∈ Σ is not known apriori (Figure 1 a). The occurrence language can be expressed by a shallow transformer with d d d -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 1 b). 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 1 d-Figure 1 e).
Figure 1. (a) Automaton of the occurrence language A s = Σ ∗ s Σ ∗ A_s = \Sigma^*s\Sigma^* A s = Σ ∗ s Σ ∗ with alphabet Σ = { 1 , … , d } \Sigma= \{1,\ldots,d\} Σ = { 1 , … , d } and unknown s ∈ Σ s \in\Sigma s ∈ Σ . The language can be expressed by a transformer with one attention head and linear output layer (1), which encodes word w = ( w 1 , … , w m ) w = (w_1,\ldots,w_m) w = ( w 1 , … , w m ) as ( e w 1 , … , e w m ) (e_{w_1},\ldots,e_{w_m}) ( e w 1 , … , e w m ) , where e i ∈ R d e_i \in\mathbb{R}^d e i ∈ R d is the i i i -th standard basis vector. The optimal shallow transformer has weights of the output layer β = 2 e s ∈ R d \beta= 2e_s \in\mathbb{R}^d β = 2 e s ∈ R d , and attention score for symbol i ∈ Σ i \in\Sigma i ∈ Σ is γ i = 1 \gamma_i = 1 γ i = 1 if i = s i=s i = s , and 0 otherwise. (b) A shallow transformer is trained to recognize A s A_s A s using gradient descent jointly on both layers. The output gap ( β s − max i ≠ s β i ) / 2 (\beta_s - \max_{i\ne s}\beta_i)/2 ( β s − max i = s β i ) /2 and attention gap ( γ s − max i ≠ s γ i ) (\gamma_s - \max_{i\ne s}\gamma_i) ( γ s − max i = s γ i ) , 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)→ \to → O, does not correctly learn the language. We later prove that a 3-phase training, O(1x)→ \to → A(1x)→ \to → O$, correctly learns to recognize A s A_s A s . (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.
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 d d d languages { A s : s ∈ Σ } \{A_s : s \in\Sigma\} { A s : s ∈ Σ } . The same also holds for transformers with O ( d ) O(\sqrt{d}) O ( d ) 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"ive 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 O ( d ln d ) O(d\ln d) O ( d ln d ) 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 of formal languages, circuit complexity, or space/time complexity classes (see surveys in Strobl et al. [24 ] ; Lin and Barceló [16 ] ; Barceló et al. [5 ] ), 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. [14 ] ; Arda et al. [2 ] ) or implicit biases towards maximum margin (Tarzanagh et al. [25 ] ), 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. [29 ] ; Han and Ghoshdastidar [13 ] study the training dynamics of transformers when trained on sparse parity function—a prototypical task
for feedforward networks. Marion et al. [20 ] ; Dohmatob [10 ] study the joint dynamics of attention and output layer of a shallow transformer for single-location regression, while Wang et al. [28 ] 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. [6 ] ; Chen et al. [8 ] study the dynamics of training induction heads in transformers for next token prediction on bigrams and in-context n n n -gram Markov chains. Bietti et al. [6 ] empirically observe, under joint training, the induction head is learned more slowly than the global bigram model, similar to Figure 1 b, 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. [8 ] 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. [30 ] 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. [15 ] 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.
Problem Formulation
This section describes the occurrence language recognition task, the training data distribution, the transformer model, and its ability to express the language.
Occurrence language and Training data. Let Σ = { 1 , 2 , … , d } \Sigma= \{1,2,\ldots,d\} Σ = { 1 , 2 , … , d } be a finite alphabet of size d ≥ 2 d \ge2 d ≥ 2 . For a symbol s ∈ Σ s \in\Sigma s ∈ Σ , the occurrence language, defined as A s : = Σ ∗ s Σ ∗ A_s := \Sigma^*s\Sigma^* A s := Σ ∗ s Σ ∗ , is the set of strings that contain s s s . We encode membership by the label function χ s ( w ) : = 2 ⋅ 1 { s occurs in w } − 1 ∈ { + 1 } \chi_s(w) := 2\cdot1\{s\text{ occurs in }w\} - 1 \in\{+1\} χ s ( w ) := 2 ⋅ 1 { s occurs in w } − 1 ∈ { + 1 } . Consider any non-empty word w = ( w 1 , … , w m ) ∈ Σ ∗ w = (w_1,\ldots,w_m) \in\Sigma^* w = ( w 1 , … , w m ) ∈ Σ ∗ drawn from a distribution, say ρ \rho ρ , such that the length is m ∼ Geometric ( p ) m \sim\operatorname{Geometric}(p) m ∼ Geometric ( p ) , i.e., P ( m = k ) = p ( 1 − p ) k − 1 \mathbb{P}(m = k) = p(1-p)^{k-1} P ( m = k ) = p ( 1 − p ) k − 1 for k ≥ 1 k \ge1 k ≥ 1 , and given m m m , the symbols w 1 , … , w m ∼ i . i . d . Uniform ( Σ ) w_1,\ldots,w_m \overset{\mathrm{i.i.d.}}{\sim} \operatorname{Uniform}(\Sigma) w 1 , … , w m ∼ i.i.d. Uniform ( Σ ) . Equivalently, after the first symbol, the sequence terminates at each step independently with probability p p p . Setting p = 1 d − 1 p = \frac{1}{d-1} p = d − 1 1 exactly balances the proportion of positive/negative samples since, for any s ∈ Σ s \in\Sigma s ∈ Σ , it holds that P w ∼ ρ ( χ s ( w ) = − 1 ) = ∑ m = 1 ∞ P ( ∣ w ∣ = m ) ⋅ ( 1 d ) m = 1 2 \mathbb{P}_{w\sim\rho}(\chi_s(w) = -1) = \sum_{m=1}^{\infty}\mathbb{P}(|w|=m)\cdot\left(\frac{1}{d}\right)^m = \frac{1}{2} P w ∼ ρ ( χ s ( w ) = − 1 ) = ∑ m = 1 ∞ P ( ∣ w ∣ = m ) ⋅ ( d 1 ) m = 2 1 . We use D s D_s D s to denote the joint distribution over ( w , y ) (w,y) ( w , y ) where w ∼ ρ w\sim\rho w ∼ ρ and y = χ s ( w ) ∈ { + 1 } y=\chi_s(w)\in\{+1\} y = χ s ( w ) ∈ { + 1 } . Throughout this paper, we fix a target symbol s ∈ Σ s\in\Sigma s ∈ Σ , unknown to the learner, and write D ≡ D s D \equiv D_s D ≡ D s , χ ≡ χ s \chi\equiv\chi_s χ ≡ χ s when s s s is unambiguous from context. The transformer, described next, is trained by gradient descent on the population loss over D D D .
Shallow transformer architecture. To recognize the language A s A_s A s , we consider a transformer with a single attention layer with one head, and a linear output layer. Every i ∈ Σ i\in\Sigma i ∈ Σ is embedded as i i i -th standard basis vector e i ∈ R d e_i\in\mathbb{R}^d e i ∈ R d , and a word w = ( w 1 , … , w m ) ∈ Σ ∗ w=(w_1,\ldots,w_m)\in\Sigma^* w = ( w 1 , … , w m ) ∈ Σ ∗ encodes into ( x 1 , … , x m ) (x_1,\ldots,x_m) ( x 1 , … , x m ) , where x t = e w t x_t=e_{w_t} x t = e w t . Positional encoding is not used since membership χ s ( w ) \chi_s(w) χ s ( w ) is permutation-invariant. We prepend a fixed classification token x C L S x_{\mathrm{CLS}} x CLS , which attends to the m m m 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 α : = W K ⊤ W Q x C L S ∈ R d \alpha:= W_K^\top W_Q x_{\mathrm{CLS}}\in\mathbb{R}^d α := W K ⊤ W Q x CLS ∈ R d , whose i i i -th entry is the attention logit that the CLS token assigns to symbol i i i . Likewise, the value matrix and the linear output enter only through their product β ∈ R d \beta\in\mathbb{R}^d β ∈ R d . We treat ( α , β ) (\alpha,\beta) ( α , β ) as the trainable parameters, and call them the attention and output weights, respectively. The model computes
f α , β ( w ) = β ⊤ ( ∑ t = 1 m exp ( α ⊤ x t ) ∑ r = 1 m exp ( α ⊤ x r ) ⋅ x t ) − 1 = ∑ i = 1 d β i ⋅ C i ( w ) exp ( α i ) ∑ j = 1 d C j ( w ) exp ( α j ) − 1 (1) f_{\alpha,\beta}(w) = \beta^\top\left(\sum_{t=1}^{m}\frac{\exp(\alpha^\top x_t)}{\sum_{r=1}^{m}\exp(\alpha^\top x_r)}\cdot x_t\right)-1
= \sum_{i=1}^{d}\beta_i\cdot\frac{C_i(w)\exp(\alpha_i)}{\sum_{j=1}^{d}C_j(w)\exp(\alpha_j)}-1 \tag*{(1)} f α , β ( w ) = β ⊤ ( t = 1 ∑ m ∑ r = 1 m exp ( α ⊤ x r ) exp ( α ⊤ x t ) ⋅ x t ) − 1 = i = 1 ∑ d β i ⋅ ∑ j = 1 d C j ( w ) exp ( α j ) C i ( w ) exp ( α i ) − 1 (1)
where the second line groups the attention scores from positions that carry the same symbol by using C i ( w ) : = ∑ j = 1 m 1 { w j = i } C_i(w) := \sum_{j=1}^{m} 1\{w_j = i\} C i ( w ) := ∑ j = 1 m 1 { w j = i } to denote the number of occurrences of symbol i i i in w w w ; a fixed bias − 1 -1 − 1 is used. We use γ i ( w ) : = C i ( w ) exp ( α i ) ∑ j = 1 d C j ( w ) exp ( α j ) \gamma_i(w) := \frac{C_i(w)\exp(\alpha_i)}{\sum_{j=1}^{d} C_j(w)\exp(\alpha_j)} γ i ( w ) := ∑ j = 1 d C j ( w ) e x p ( α j ) C i ( w ) e x p ( α i ) to denote the total attention scores placed on symbol i ∈ [ d ] i \in[d] i ∈ [ d ] .
Loss and expressivity. The transformer is trained to minimize the population (squared) risk over D D D ,
L ( α , β ) = E ( w , y ) ∼ D [ 1 2 ( f α , β ( w ) − y ) 2 ] . \mathcal{L}(\alpha,\beta) = \mathbb{E}_{(w,y)\sim D}\left[\frac{1}{2}\left(f_{\alpha,\beta}(w)-y\right)^2\right]. L ( α , β ) = E ( w , y ) ∼ D [ 2 1 ( f α , β ( w ) − y ) 2 ] .
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 α , β \alpha,\beta α , β for which the loss can be made arbitrarily small.
Proposition 1 (Shallow transformer expresses occurrence language). For any specified ϵ ∈ ( 0 , 1 ) \epsilon\in(0,1) ϵ ∈ ( 0 , 1 ) , a shallow transformer with β = 2 e s \beta= 2e_s β = 2 e s and α = ln ( 4 d / ϵ 2 ) e s \alpha= \ln(4d/\epsilon^2)e_s α = ln ( 4 d / ϵ 2 ) e s achieves L ( α , β ) ≤ ϵ \mathcal{L}(\alpha,\beta) \le\epsilon L ( α , β ) ≤ ϵ . The result also holds for any α \alpha α such that α s − max j ≠ s α j ≥ ln ( 4 d / ϵ 2 ) \alpha_s - \max_{j\ne s}\alpha_j \ge\ln(4d/\epsilon^2) α s − max j = s α j ≥ ln ( 4 d / ϵ 2 ) .
Training. Our main results on training dynamics assume that transformer is trained to minimise the population risk L \mathcal{L} L with GD. A gradient step on the parameters is written as α ′ = α − η ∇ α L ( α , β ) \alpha' = \alpha- \eta\nabla_\alpha\mathcal{L}(\alpha,\beta) α ′ = α − η ∇ α L ( α , β ) , β ′ = β − η ′ ∇ β L ( α , β ) \beta' = \beta- \eta'\nabla_\beta\mathcal{L}(\alpha,\beta) β ′ = β − η ′ ∇ β L ( α , β ) , with parameter-wise step sizes η , η ′ ≥ 0 \eta,\eta' \ge0 η , η ′ ≥ 0 . We subsequently use training plans that decouple GD updates of α , β \alpha,\beta α , β , 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 ( α , β ) (\alpha,\beta) ( α , β ) and in the order of training the layers, as explained in the respective results.
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 c 1 > 0 c_1 > 0 c 1 > 0 , such that for every d ≥ 3 d \ge3 d ≥ 3 and β ~ ∈ R d \tilde{\beta} \in\mathbb{R}^d β ~ ∈ R d ,
max s ∈ [ d ] inf α ∈ R d L s ( α , β ~ ) ≥ c 1 , \max_{s\in[d]}\inf_{\alpha\in\mathbb{R}^d}\mathcal{L}_s(\alpha,\tilde{\beta}) \ge c_1, s ∈ [ d ] max α ∈ R d inf L s ( α , β ~ ) ≥ c 1 , that is, for any fixed output, there is a target s ∈ Σ s \in\Sigma s ∈ Σ where no attention weight achieves arbitrarily low risk.
Since the bound holds for the infimum over α ∈ R d \alpha\in\mathbb{R}^d α ∈ R d , 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.
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 c 2 > 0 c_2 > 0 c 2 > 0 , such that for every d ≥ 3 d \ge3 d ≥ 3 and α ~ ∈ R d \tilde{\alpha} \in\mathbb{R}^d α ~ ∈ R d ,
max s ∈ [ d ] inf β ∈ R d L s ( α ~ , β ) ≥ c 2 , \max_{s\in[d]}\inf_{\beta\in\mathbb{R}^d}\mathcal{L}_s(\tilde{\alpha},\beta) \ge c_2, s ∈ [ d ] max β ∈ R d inf L s ( α ~ , β ) ≥ c 2 , that is, for any fixed attention, there is a symbol s s 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):
f α , β ( w ) = ∑ h ∈ [ H ] ∑ i ∈ [ d ] β i ( h ) C i ( w ) exp ( α i ( h ) ) ∑ j = 1 d C j ( w ) exp ( α j ( h ) ) − 1 , (2) f_{\alpha,\beta}(w) = \sum_{h\in[H]}\sum_{i\in[d]}\beta_i^{(h)}\frac{C_i(w)\exp\left(\alpha_i^{(h)}\right)}{\sum_{j=1}^{d}C_j(w)\exp\left(\alpha_j^{(h)}\right)} - 1, \tag*{(2)} f α , β ( w ) = h ∈ [ H ] ∑ i ∈ [ d ] ∑ β i ( h ) ∑ j = 1 d C j ( w ) exp ( α j ( h ) ) C i ( w ) exp ( α i ( h ) ) − 1 , (2)
where H H H is the number of heads. One can write the attention weights across heads as A = ( α ( 1 ) , … , α ( H ) ) ∈ R d × H \mathcal{A} = \left(\alpha^{(1)},\ldots,\alpha^{(H)}\right) \in\mathbb{R}^{d\times H} A = ( α ( 1 ) , … , α ( H ) ) ∈ R d × H and the output weights B = ( β ( 1 ) , … , β ( H ) ) ∈ R d × H \mathcal{B} = \left(\beta^{(1)},\ldots,\beta^{(H)}\right) \in\mathbb{R}^{d\times H} B = ( β ( 1 ) , … , β ( H ) ) ∈ R d × H . With H = d H=d H = d heads, fixed attention does suffice: if each head h ∈ [ H ] h \in[H] h ∈ [ H ] is initialized to attend to symbol i i i , i.e., α ( h ) \alpha^{(h)} α ( h ) satisfies the configuration in Proposition 1, then for any target s s s , when the output weights converge to β ( s ) = 2 e s \beta^{(s)} = 2e_s β ( s ) = 2 e s and β ( h ) = 0 d \beta^{(h)} = 0_d β ( h ) = 0 d for h ≠ s h \ne s h = s , the transformer achieves arbitrarily small risk. Further, in the limit H → ∞ H \to\infty H → ∞ with random attention weights, training the output layer becomes kernel regression with a deterministic kernel [14 ] . The next result shows that substantially fewer than d d d heads, specifically O ( d ) O(\sqrt{d}) O ( d ) are not enough.
Proposition 4 (Risk lower bound for output-only training with multiple heads). There is an absolute constant c ∈ ( 0 , 1 ) c \in(0,1) c ∈ ( 0 , 1 ) , such that when the number of heads H ≤ c d H \le c\sqrt{d} H ≤ c d , for any d ≥ 3 d \ge3 d ≥ 3 and fixed attention A ~ \tilde{\mathcal{A}} A ~ ,
max s ∈ [ d ] min ∥ B ∥ F ≤ d 1 / 4 L s ( A ~ , B ) ≥ c . \max_{s\in[d]}\min_{\|\mathcal{B}\|_F\le d^{1/4}}\mathcal{L}_s(\tilde{\mathcal{A}},\mathcal{B}) \ge c. s ∈ [ d ] max ∥ B ∥ F ≤ d 1/4 min L s ( A ~ , B ) ≥ c .
The norm constraint ∥ B ∥ F ≤ d 1 / 4 \|\mathcal{B}\|_F \le d^{1/4} ∥ B ∥ F ≤ d 1/4 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 H H H . 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 ∥ B ∥ F = 2 \|\mathcal{B}\|_F = 2 ∥ B ∥ F = 2 . If all H H H heads are trained from identical zero initialization, they remain identical by symmetry, and the parameter α ( h ) \alpha^{(h)} α ( h ) will converge to satisfy the configuration in Proposition 1, while β ( h ) \beta^{(h)} β ( h ) will converge to 2 H e s \frac{2}{H}e_s H 2 e s for each head h ∈ [ H ] h \in[H] h ∈ [ H ] . In this case, the output norm is ∥ B ∥ F = 2 / H \|\mathcal{B}\|_F = 2/\sqrt{H} ∥ B ∥ F = 2/ H . 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 [14 , 2 ] or learning the features under a fixed output layer [11 , 13 , 25 ] —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 [3 , 22 ] . As we show next, this 2-phase GD training also cannot learn the occurrence language if one starts from uniform attention α = 0 d \alpha= 0_d α = 0 d .
Theorem 1 (Attention-first two-phase GD fails to learn occurrence). There is absolute constant c 3 > 0 c_3 > 0 c 3 > 0 such that the following holds for every d ≥ 9 d \ge9 d ≥ 9 , β ~ ∈ R d \widetilde{\beta} \in\mathbb{R}^d β ∈ R d , and η > 0 \eta> 0 η > 0 . Suppose the transformer is initialized as α = 0 d \alpha= 0_d α = 0 d (uniform attention) and β = β ~ \beta= \widetilde{\beta} β = β , and one gradient step is used to update the attention weights as
α s ′ : = − η ∇ α L s ( 0 d , β ~ ) , \alpha'_s := -\eta\nabla_\alpha L_s(0_d,\widetilde{\beta}), α s ′ := − η ∇ α L s ( 0 d , β ) , where s ∈ Σ s \in\Sigma s ∈ Σ is unknown but influences the updated attention α s ′ \alpha'_s α s ′ through the population risk gradient. Then
max s ∈ [ d ] inf β ∈ R d L s ( α s ′ , β ) ≥ c 3 , \max_{s \in[d]} \inf_{\beta\in\mathbb{R}^d} L_s(\alpha'_s,\beta) \ge c_3, s ∈ [ d ] max β ∈ R d inf L s ( α s ′ , β ) ≥ c 3 , that is, there is a target s ∈ Σ s \in\Sigma s ∈ Σ for which the optimal output layer on top of the updated attention α s ′ \alpha'_s α s ′ 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.
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. [6 ] ; Huang et al. [15 ] about joint gradient dynamics in other settings. Motivated by this, we study the following three-phase training plan. We initialize α = β = 0 d \alpha= \beta= 0_d α = β = 0 d , which is agnostic to s s s , and train as follows:
Phase 1: One GD step on the output with step size η 1 \eta_1 η 1 and frozen attention: β ′ = − η 1 ∇ β L s ( 0 d , 0 d ) \beta' = -\eta_1 \nabla_\beta L_s(0_d,0_d) β ′ = − η 1 ∇ β L s ( 0 d , 0 d ) .
Phase 2: One GD step on the attention weights with step size η 2 \eta_2 η 2 and frozen output: α ′ = − η 2 ∇ α L s ( 0 d , β ′ ) \alpha' = -\eta_2 \nabla_\alpha L_s(0_d,\beta') α ′ = − η 2 ∇ α L s ( 0 d , β ′ ) .
Phase 3: T T T steps of GD on the output weights with step size η 3 \eta_3 η 3 , starting from β ′ \beta' β ′ with the attention fixed at α ′ \alpha' α ′ . Formally, β ( 0 ) = β ′ \beta(0) = \beta' β ( 0 ) = β ′ and β ( t + 1 ) = β ( t ) − η 3 ∇ β L s ( α ′ , β ( t ) ) \beta(t+1) = \beta(t) - \eta_3 \nabla_\beta L_s(\alpha',\beta(t)) β ( t + 1 ) = β ( t ) − η 3 ∇ β L s ( α ′ , β ( t )) for t = 0 , … , T − 1 t = 0,\ldots,T-1 t = 0 , … , T − 1 . We denote the resulting output weights by β ′ ′ : = β ( T ) \beta'' := \beta(T) β ′′ := β ( T ) .
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 d ≥ 3 d \ge3 d ≥ 3 , every target symbol s ∈ [ d ] s \in[d] s ∈ [ d ] , and every ϵ ∈ ( 0 , 1 ) \epsilon\in(0,1) ϵ ∈ ( 0 , 1 ) , when the step sizes and steps satisfy: 0 < η 1 < d − 1 2 0 < \eta_1 < \frac{d-1}{2} 0 < η 1 < 2 d − 1 , η 2 > 20 ( d − 1 ) 2 η 1 ln 8 d ϵ \eta_2 > \frac{20(d-1)^2}{\eta_1} \ln\frac{8d}{\epsilon} η 2 > η 1 20 ( d − 1 ) 2 ln ϵ 8 d , η 3 = 1 \eta_3 = 1 η 3 = 1 , T ≥ 4 d ln 16 d ϵ T \ge4d \ln\frac{16d}{\epsilon} T ≥ 4 d ln ϵ 16 d , then the parameters ( α ′ , β ′ ′ ) (\alpha',\beta'') ( α ′ , β ′′ ) obtained by the above 3-phase training plan satisfy:
L s ( α ′ , β ′ ′ ) ≤ ϵ . L_s(\alpha',\beta'') \le\epsilon. L s ( α ′ , β ′′ ) ≤ ϵ .
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 2 e s 2e_s 2 e s .
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 (α = β = 0 d \alpha= \beta= \mathbf{0}_d α = β = 0 d ) is agnostic to s s s , it is not standard in practice. We adopt this to simplify the theoretical analysis, as also done in Tarzanagh et al. [25 ] . Empirically, the same behavior occurs under random initialization (Table 1 ).
Table 1. Train loss and test accuracy (loss for SLR), with mean over 50 seeds. Standard deviations are reported in Appendix § 15 .§ 5 . Values below 10 − 3 10^{-3} 1 0 − 3 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.
Finite-Sample GD analysis. The population gradient is not accessible in practice. We extend Theorem 2 to finite-sample GD to show that O ( d ln d + ( ln d ) / ε ) O(d\ln d + (\ln d)/\varepsilon) O ( d ln d + ( ln d ) / ε ) samples suffice to reach a population risk of at most ε \varepsilon ε .
Corollary 1 (Three-phase training with finite samples). Consider the same initialization α = β = 0 d \alpha= \beta= \mathbf{0}_d α = β = 0 d , and the three-phase plan where the gradients of Phases 1 and 2 are computed on the empirical risk of N 1 N_1 N 1 i.i.d. samples from D D D , and the gradients of Phase 3 on the empirical risk of N 3 N_3 N 3 fresh i.i.d. samples. For every c > 0 c > 0 c > 0 , there exists a constant C > 0 C > 0 C > 0 such that the following holds for every d ≥ 3 d \ge3 d ≥ 3 , every target symbol s ∈ [ d ] s \in[d] s ∈ [ d ] , and every ε ∈ ( 0 , 1 ) \varepsilon\in(0,1) ε ∈ ( 0 , 1 ) . If 0 < η 1 ≤ d 0 < \eta_1 \le\sqrt{d} 0 < η 1 ≤ d , η 2 ≥ C d 2 η 1 ln d ε \eta_2 \ge\frac{Cd^2}{\eta_1}\ln\frac{d}{\varepsilon} η 2 ≥ η 1 C d 2 ln ε d , η 3 = 1 \eta_3 = 1 η 3 = 1 , T = ⌈ 72 ε ⌉ T = \left\lceil\frac{72}{\varepsilon}\right\rceil T = ⌈ ε 72 ⌉ , and N 1 ≥ C d ln d N_1 \ge Cd\ln d N 1 ≥ C d ln d , N 3 ≥ C ln d ε N_3 \ge\frac{C\ln d}{\varepsilon} N 3 ≥ ε C l n d , then with probability at least 1 − 3 d − c 1-3d^{-c} 1 − 3 d − c over the two draws, the resulting parameters ( α ^ , β ^ ′ ′ ) (\hat{\alpha},\hat{\beta}^{\prime\prime}) ( α ^ , β ^ ′′ ) achieve L s ( α ^ , β ^ ) ≤ ε L_s(\hat{\alpha},\hat{\beta}) \le\varepsilon L s ( α ^ , β ^ ) ≤ ε .
The proof is deferred to Appendix § 10 .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. [3 ] finetune the second layer with a new set of samples after one GD step on the first layer, Nichani et al. [21 ] 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.
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 { a , b } \{a,b\} { a , b } of strings where a b ab ab and b a ba ba occur even number of times (Huang et al., [15 ] ); (v) in-context bigram learning (ICL bigram), a simplified version of Bietti et al. [6 ] 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., [20 ] ). 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 § 15 .§ 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 § 5 .
We use d = 50 d = 50 d = 50 , N = 5 d 2 N = 5d^2 N = 5 d 2 training samples, and d 2 d^2 d 2 samples for testing, with the following two exceptions: for even pairs, we train and test on N = 2046 N = 2046 N = 2046 strings of length at most 10 (Huang et al., [15 ] ); for SLR, we fix input length L = 10 L = 10 L = 10 (Marion et al., [20 ] ). 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 § 15 .§ 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.
Figure 3. Attention and output gaps on four tasks. Mean ± \pm ± standard deviation over 50 runs; dotted lines mark the ideal gaps (see Appendix § 15 .§ 3 ). Phases are defined as in Figure 2 ; single-layer plans end after Phase 1 and A→ \to → O after Phase 2. For AND, we plot the head with the largest gap for each plan (all heads: Appendix § 15 .§ 4 ). For even pairs and SLR, the output gap is cos ( u , w ∗ ) \cos(u,w^*) cos ( u , w ∗ ) and cos ( v , v ∗ ) \cos(v,v^*) cos ( v , v ∗ ) , with w ∗ w^* w ∗ the max-margin and v ∗ v^* v ∗ the ground-truth direction. Since w ∗ w^* w ∗ depends on the attention weights, the output gap on even pairs can change in Phase 2 although the output is frozen. O→ \to → A and the zero initialization are omitted, as they coincide with the first two phases of O→ \to → A→ \to → O and with the random initialization, respectively. The trajectories on OR resemble those on occurrence in Figure 2 and are deferred to Appendix § 15 .§ 6 .
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, 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 § 7 .
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 ( 1 x ) → O A(1x)\to O A ( 1 x ) → 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.
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 flow 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.
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 [23 , 12 ] . 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 [26 , 8 ] 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 [30 , 15 ] to investigate this question. We also note specific questions to build upon the presented results.
The focus of the present study was on the interplay of (decoupled) attention ans output layer training. To derive this, we made two key simplifications—focused on population training risk and parameterized the transformer by ( α , β ) (\alpha,\beta) ( α , β ) . Parameterization in terms of key, query, value matrices leads to an overparametrized system in this case and, as shown in Tarzanagh et al. [25 ] , leads to different dynamics and implicit biases of GD. While the finite sample analysis in Corollary 1 shows that O ( d ln d ) O(d\ln d) O ( d ln d ) 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 [1 ] .
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 [3 , 22 ] , 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.
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 [24 , 4 ] . 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 reformatting 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.
Proofs for the Main Results
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 ℓ ( w ) \ell(w) ℓ ( w ) with respect to each parameter for each index i ∈ [ d ] i \in[d] i ∈ [ d ] is listed as follows:
∂ ℓ ( w ) ∂ β i = ( y ^ ( w ) − y ( w ) ) ⋅ γ i \frac{\partial\ell(w)}{\partial\beta_i} = \bigl(\hat{y}(w)-y(w)\bigr)\cdot\gamma_i ∂ β i ∂ ℓ ( w ) = ( y ^ ( w ) − y ( w ) ) ⋅ γ i
∂ ℓ ( w ) ∂ α i = ( y ^ ( w ) − y ( w ) ) ⋅ ( β i γ i ( 1 − γ i ) − ∑ j ≠ i β j γ i γ j ) \frac{\partial\ell(w)}{\partial\alpha_i} = \bigl(\hat{y}(w)-y(w)\bigr)\cdot\left(\beta_i\gamma_i(1-\gamma_i)-\sum_{j\ne i}\beta_j\gamma_i\gamma_j\right) ∂ α i ∂ ℓ ( w ) = ( y ^ ( w ) − y ( w ) ) ⋅ β i γ i ( 1 − γ i ) − j = i ∑ β j γ i γ j
We write the expectations of first and the second conditional moments of γ s \gamma_s γ s at initialisation α = 0 d \alpha=\mathbf{0}_d α = 0 d :
E [ γ s ∣ y = 1 ] = ∑ m = 1 ∞ P ( ∣ w ∣ = m ∣ y = 1 ) ⋅ ∑ n = 1 m P ( C s ( w ) = n ∣ ∣ w ∣ = m , y = 1 ) ⋅ n m = ∑ m = 1 ∞ P ( ∣ w ∣ = m ) ⋅ P ( y = 1 ∣ ∣ w ∣ = m ) P ( y = 1 ) ⋅ ∑ n = 1 m P ( ∣ w ∣ = m ) ⋅ P ( C s ( w ) = n ∣ ∣ w ∣ = m ) P ( ∣ w ∣ = m ) ⋅ P ( y = 1 ∣ ∣ w ∣ = m ) ⋅ n m = 2 ∑ m = 1 ∞ P ( ∣ w ∣ = m ) ⋅ E n ∼ bin ( m , 1 d ) [ n m ] = 2 d (3) \begin{aligned}
\mathbb{E}[\gamma_s\mid y=1]
&=\sum_{m=1}^{\infty}\mathbb{P}(|w|=m\mid y=1)\cdot\sum_{n=1}^{m}\mathbb{P}(C_s(w)=n\mid|w|=m,y=1)\cdot\frac{n}{m}\\
&=\sum_{m=1}^{\infty}\frac{\mathbb{P}(|w|=m)\cdot\mathbb{P}(y=1\mid|w|=m)}{\mathbb{P}(y=1)}\cdot\sum_{n=1}^{m}\frac{\mathbb{P}(|w|=m)\cdot\mathbb{P}(C_s(w)=n\mid|w|=m)}{\mathbb{P}(|w|=m)\cdot\mathbb{P}(y=1\mid|w|=m)}\cdot\frac{n}{m}\\
&=2\sum_{m=1}^{\infty}\mathbb{P}(|w|=m)\cdot\mathbb{E}_{n\sim\operatorname{bin}(m,\frac{1}{d})}\left[\frac{n}{m}\right]=\frac{2}{d} \tag*{(3)}
\end{aligned} E [ γ s ∣ y = 1 ] = m = 1 ∑ ∞ P ( ∣ w ∣ = m ∣ y = 1 ) ⋅ n = 1 ∑ m P ( C s ( w ) = n ∣ ∣ w ∣ = m , y = 1 ) ⋅ m n = m = 1 ∑ ∞ P ( y = 1 ) P ( ∣ w ∣ = m ) ⋅ P ( y = 1 ∣ ∣ w ∣ = m ) ⋅ n = 1 ∑ m P ( ∣ w ∣ = m ) ⋅ P ( y = 1 ∣ ∣ w ∣ = m ) P ( ∣ w ∣ = m ) ⋅ P ( C s ( w ) = n ∣ ∣ w ∣ = m ) ⋅ m n = 2 m = 1 ∑ ∞ P ( ∣ w ∣ = m ) ⋅ E n ∼ bin ( m , d 1 ) [ m n ] = d 2 (3)
E [ γ s 2 ∣ y = 1 ] = 2 ∑ m = 1 ∞ ( 1 − p ) m − 1 p ⋅ E n ∼ bin ( m , 1 d ) [ ( n m ) 2 ] = 2 ∑ m = 1 ∞ ( 1 − p ) m − 1 p ⋅ m − 1 + d m d 2 = 2 ∑ m = 1 ∞ ( 1 − p ) m − 1 p ⋅ ( 1 d 2 − 1 m d 2 + 1 m d ) = 2 [ 1 d 2 + ( 1 d − 1 d 2 ) ∑ m = 1 ∞ ( 1 − p ) m − 1 p ⋅ 1 m ] = 2 [ 1 d 2 + ( d − 1 ) ⋅ p d 2 ⋅ ( 1 − p ) ⋅ − ln ( p ) ] = 2 [ 1 d 2 + ( d − 1 ) ⋅ ln ( d − 1 ) d 2 ( d − 2 ) ] (4) \begin{aligned}
\mathbb{E}[\gamma_s^2\mid y=1]
&=2\sum_{m=1}^{\infty}(1-p)^{m-1}p\cdot\mathbb{E}_{n\sim\operatorname{bin}(m,\frac{1}{d})}\left[\left(\frac{n}{m}\right)^2\right]\\
&=2\sum_{m=1}^{\infty}(1-p)^{m-1}p\cdot\frac{m-1+d}{md^2}
=2\sum_{m=1}^{\infty}(1-p)^{m-1}p\cdot\left(\frac{1}{d^2}-\frac{1}{md^2}+\frac{1}{md}\right)\\
&=2\left[\frac{1}{d^2}+\left(\frac{1}{d}-\frac{1}{d^2}\right)\sum_{m=1}^{\infty}(1-p)^{m-1}p\cdot\frac{1}{m}\right]\\
&=2\left[\frac{1}{d^2}+\frac{(d-1)\cdot p}{d^2\cdot(1-p)}\cdot-\ln(p)\right]
=2\left[\frac{1}{d^2}+\frac{(d-1)\cdot\ln(d-1)}{d^2(d-2)}\right] \tag*{(4)}
\end{aligned} E [ γ s 2 ∣ y = 1 ] = 2 m = 1 ∑ ∞ ( 1 − p ) m − 1 p ⋅ E n ∼ bin ( m , d 1 ) [ ( m n ) 2 ] = 2 m = 1 ∑ ∞ ( 1 − p ) m − 1 p ⋅ m d 2 m − 1 + d = 2 m = 1 ∑ ∞ ( 1 − p ) m − 1 p ⋅ ( d 2 1 − m d 2 1 + m d 1 ) = 2 [ d 2 1 + ( d 1 − d 2 1 ) m = 1 ∑ ∞ ( 1 − p ) m − 1 p ⋅ m 1 ] = 2 [ d 2 1 + d 2 ⋅ ( 1 − p ) ( d − 1 ) ⋅ p ⋅ − ln ( p ) ] = 2 [ d 2 1 + d 2 ( d − 2 ) ( d − 1 ) ⋅ ln ( d − 1 ) ] (4)
{#eq:5}
For the background positions j ≠ s j\ne s j = s , we have:
E [ γ j ∣ y = 1 ] = 1 d − 1 ( 1 − 2 d ) , E [ γ j ∣ y = − 1 ] = 1 d − 1 (5) \mathbb{E}[\gamma_j\mid y=1]=\frac{1}{d-1}\left(1-\frac{2}{d}\right),\qquad\mathbb{E}[\gamma_j\mid y=-1]=\frac{1}{d-1} \tag*{(5)} E [ γ j ∣ y = 1 ] = d − 1 1 ( 1 − d 2 ) , E [ γ j ∣ y = − 1 ] = d − 1 1 (5)
E [ γ j 2 ∣ y = 1 ] = ∑ m = 1 ∞ P ( ∣ w ∣ = m ∣ y = 1 ) ∑ n = 1 m P ( C s ( w ) = n ∣ y = 1 , ∣ w ∣ = m ) ⋅ E l ∼ bin ( m − n , 1 d − 1 ) [ ( l m ) 2 ] = ∑ m = 1 ∞ P ( ∣ w ∣ = m ∣ y = 1 ) ∑ n = 1 m P ( C s ( w ) = n ∣ y = 1 , ∣ w ∣ = m ) ⋅ [ ( m − n ) ( m − n − 1 ) ⋅ 1 ( d − 1 ) 2 + ( m − n ) ⋅ 1 d − 1 m 2 ] ≤ ∑ m = 1 ∞ P ( ∣ w ∣ = m ∣ y = 1 ) ⋅ [ 1 ( d − 1 ) 2 + 1 m ( d − 1 ) ] = ∑ m = 1 ∞ ( 1 − p ) m − 1 p ⋅ ( 1 − ( d − 1 d ) m ) 1 2 ⋅ [ 1 ( d − 1 ) 2 + 1 m ( d − 1 ) ] ≤ 2 ∑ m = 1 ∞ ( 1 − p ) m − 1 p ⋅ [ 1 ( d − 1 ) 2 + 1 m ( d − 1 ) ] = 2 ( d − 1 ) 2 ∑ m = 1 ∞ ( 1 − p ) m − 1 p + 2 p ( 1 − p ) ( d − 1 ) ⋅ ∑ m = 1 ∞ ( 1 − p ) m ⋅ 1 m = 2 ( d − 1 ) 2 + 2 p ( 1 − p ) ( d − 1 ) ⋅ − ln ( 1 − ( 1 − p ) ) = 2 ( d − 1 ) 2 + 2 ln ( d − 1 ) ( d − 1 ) ( d − 2 ) (6) \begin{aligned}
\mathbb{E}[\gamma_j^2\mid y=1] &= \sum_{m=1}^{\infty}\mathbb{P}(|w|=m\mid y=1)\sum_{n=1}^{m}\mathbb{P}(C_s(w)=n\mid y=1,|w|=m)\cdot\mathbb{E}_{l\sim\operatorname{bin}(m-n,\frac{1}{d-1})}\left[\left(\frac{l}{m}\right)^2\right]\\
&= \sum_{m=1}^{\infty}\mathbb{P}(|w|=m\mid y=1)\sum_{n=1}^{m}\mathbb{P}(C_s(w)=n\mid y=1,|w|=m)\\
&\qquad\cdot\left[\frac{(m-n)(m-n-1)\cdot\frac{1}{(d-1)^2}+(m-n)\cdot\frac{1}{d-1}}{m^2}\right]\\
&\leq\sum_{m=1}^{\infty}\mathbb{P}(|w|=m\mid y=1)\cdot\left[\frac{1}{(d-1)^2}+\frac{1}{m(d-1)}\right]\\
&= \sum_{m=1}^{\infty}\frac{(1-p)^{m-1}p\cdot\left(1-\left(\frac{d-1}{d}\right)^m\right)}{\frac{1}{2}}\cdot\left[\frac{1}{(d-1)^2}+\frac{1}{m(d-1)}\right]\\
&\leq2\sum_{m=1}^{\infty}(1-p)^{m-1}p\cdot\left[\frac{1}{(d-1)^2}+\frac{1}{m(d-1)}\right]\\
&= \frac{2}{(d-1)^2}\sum_{m=1}^{\infty}(1-p)^{m-1}p+\frac{2p}{(1-p)(d-1)}\cdot\sum_{m=1}^{\infty}(1-p)^m\cdot\frac{1}{m}\\
&= \frac{2}{(d-1)^2}+\frac{2p}{(1-p)(d-1)}\cdot-\ln(1-(1-p))=\frac{2}{(d-1)^2}+\frac{2\ln(d-1)}{(d-1)(d-2)} \tag*{(6)}
\end{aligned} E [ γ j 2 ∣ y = 1 ] = m = 1 ∑ ∞ P ( ∣ w ∣ = m ∣ y = 1 ) n = 1 ∑ m P ( C s ( w ) = n ∣ y = 1 , ∣ w ∣ = m ) ⋅ E l ∼ bin ( m − n , d − 1 1 ) [ ( m l ) 2 ] = m = 1 ∑ ∞ P ( ∣ w ∣ = m ∣ y = 1 ) n = 1 ∑ m P ( C s ( w ) = n ∣ y = 1 , ∣ w ∣ = m ) ⋅ [ m 2 ( m − n ) ( m − n − 1 ) ⋅ ( d − 1 ) 2 1 + ( m − n ) ⋅ d − 1 1 ] ≤ m = 1 ∑ ∞ P ( ∣ w ∣ = m ∣ y = 1 ) ⋅ [ ( d − 1 ) 2 1 + m ( d − 1 ) 1 ] = m = 1 ∑ ∞ 2 1 ( 1 − p ) m − 1 p ⋅ ( 1 − ( d d − 1 ) m ) ⋅ [ ( d − 1 ) 2 1 + m ( d − 1 ) 1 ] ≤ 2 m = 1 ∑ ∞ ( 1 − p ) m − 1 p ⋅ [ ( d − 1 ) 2 1 + m ( d − 1 ) 1 ] = ( d − 1 ) 2 2 m = 1 ∑ ∞ ( 1 − p ) m − 1 p + ( 1 − p ) ( d − 1 ) 2 p ⋅ m = 1 ∑ ∞ ( 1 − p ) m ⋅ m 1 = ( d − 1 ) 2 2 + ( 1 − p ) ( d − 1 ) 2 p ⋅ − ln ( 1 − ( 1 − p )) = ( d − 1 ) 2 2 + ( d − 1 ) ( d − 2 ) 2 ln ( d − 1 ) (6)
E [ γ j 2 ∣ y = − 1 ] = ∑ m = 1 ∞ P ( ∣ w ∣ = m ∣ y = − 1 ) ∑ n = 0 m P ( C j ( w ) = n ∣ ∣ w ∣ = m , y = − 1 ) ⋅ ( n m ) 2 = ∑ m = 1 ∞ P ( ∣ w ∣ = m ∣ y = − 1 ) ⋅ E n ∼ bin ( m , 1 d − 1 ) [ ( n m ) 2 ] = ∑ m = 1 ∞ ( 1 − p ) m − 1 ⋅ p ⋅ ( d − 1 d ) m 1 2 ⋅ [ m ( m − 1 ) ⋅ 1 ( d − 1 ) 2 + m ⋅ 1 d − 1 m 2 ] ≤ ∑ m = 1 ∞ 2 ⋅ ( 1 − p ) m − 1 ⋅ p ⋅ ( d − 1 d ) m ⋅ [ 1 ( d − 1 ) 2 + 1 d − 1 ⋅ 1 m ] = 2 p ⋅ ( d − 1 ) d ( d − 1 ) 2 ∑ m = 0 ∞ [ ( 1 − p ) ⋅ ( d − 1 d ) ] m + 2 p ( 1 − p ) ( d − 1 ) ∑ m = 1 ∞ [ ( 1 − p ) ⋅ ( d − 1 d ) ] m ⋅ 1 m = 2 p d ( d − 1 ) ⋅ 1 1 − ( 1 − p ) ( d − 1 ) d + 2 p ( 1 − p ) ( d − 1 ) ⋅ − ln ( 1 − ( 1 − p ) ⋅ d − 1 d ) = 1 ( d − 1 ) 2 + 2 ln ( d 2 ) ( d − 1 ) ( d − 2 ) (7) \begin{aligned}
\mathbb{E}[\gamma_j^2\mid y=-1] &= \sum_{m=1}^{\infty}\mathbb{P}(|w|=m\mid y=-1)\sum_{n=0}^{m}\mathbb{P}(C_j(w)=n\mid|w|=m,y=-1)\cdot\left(\frac{n}{m}\right)^2\\
&= \sum_{m=1}^{\infty}\mathbb{P}(|w|=m\mid y=-1)\cdot\mathbb{E}_{n\sim\operatorname{bin}(m,\frac{1}{d-1})}\left[\left(\frac{n}{m}\right)^2\right]\\
&= \sum_{m=1}^{\infty}\frac{(1-p)^{m-1}\cdot p\cdot\left(\frac{d-1}{d}\right)^m}{\frac{1}{2}}\cdot\left[\frac{m(m-1)\cdot\frac{1}{(d-1)^2}+m\cdot\frac{1}{d-1}}{m^2}\right]\\
&\leq\sum_{m=1}^{\infty}2\cdot(1-p)^{m-1}\cdot p\cdot\left(\frac{d-1}{d}\right)^m\cdot\left[\frac{1}{(d-1)^2}+\frac{1}{d-1}\cdot\frac{1}{m}\right]\\
&= \frac{2p\cdot(d-1)}{d(d-1)^2}\sum_{m=0}^{\infty}\left[(1-p)\cdot\left(\frac{d-1}{d}\right)\right]^m+\frac{2p}{(1-p)(d-1)}\sum_{m=1}^{\infty}\left[(1-p)\cdot\left(\frac{d-1}{d}\right)\right]^m\cdot\frac{1}{m}\\
&= \frac{2p}{d(d-1)}\cdot\frac{1}{1-\frac{(1-p)(d-1)}{d}}+\frac{2p}{(1-p)(d-1)}\cdot-\ln\left(1-(1-p)\cdot\frac{d-1}{d}\right)\\
&= \frac{1}{(d-1)^2}+\frac{2\ln\left(\frac{d}{2}\right)}{(d-1)(d-2)} \tag*{(7)}
\end{aligned} E [ γ j 2 ∣ y = − 1 ] = m = 1 ∑ ∞ P ( ∣ w ∣ = m ∣ y = − 1 ) n = 0 ∑ m P ( C j ( w ) = n ∣ ∣ w ∣ = m , y = − 1 ) ⋅ ( m n ) 2 = m = 1 ∑ ∞ P ( ∣ w ∣ = m ∣ y = − 1 ) ⋅ E n ∼ bin ( m , d − 1 1 ) [ ( m n ) 2 ] = m = 1 ∑ ∞ 2 1 ( 1 − p ) m − 1 ⋅ p ⋅ ( d d − 1 ) m ⋅ [ m 2 m ( m − 1 ) ⋅ ( d − 1 ) 2 1 + m ⋅ d − 1 1 ] ≤ m = 1 ∑ ∞ 2 ⋅ ( 1 − p ) m − 1 ⋅ p ⋅ ( d d − 1 ) m ⋅ [ ( d − 1 ) 2 1 + d − 1 1 ⋅ m 1 ] = d ( d − 1 ) 2 2 p ⋅ ( d − 1 ) m = 0 ∑ ∞ [ ( 1 − p ) ⋅ ( d d − 1 ) ] m + ( 1 − p ) ( d − 1 ) 2 p m = 1 ∑ ∞ [ ( 1 − p ) ⋅ ( d d − 1 ) ] m ⋅ m 1 = d ( d − 1 ) 2 p ⋅ 1 − d ( 1 − p ) ( d − 1 ) 1 + ( 1 − p ) ( d − 1 ) 2 p ⋅ − ln ( 1 − ( 1 − p ) ⋅ d d − 1 ) = ( d − 1 ) 2 1 + ( d − 1 ) ( d − 2 ) 2 ln ( 2 d ) (7)
Proof of Proposition 1
Proof. Since β s = 2 \beta_s=2 β s = 2 and β j = 0 \beta_j=0 β j = 0 for every j ≠ s j\ne s j = s , we have f α , β ( w ) = 2 γ s ( w ) − 1 f_{\alpha,\beta}(w)=2\gamma_s(w)-1 f α , β ( w ) = 2 γ s ( w ) − 1 . One can verify that f α , β ( w ) = − 1 f_{\alpha,\beta}(w)=-1 f α , β ( w ) = − 1 for every w ∉ A s w\notin A_s w ∈ / A s , and hence, the negative examples do not contribute to the loss. For the positive examples w ∈ A s w\in A_s w ∈ A s , we separately consider words of length shorter or longer than M = 2 d ε M=\frac{2d}{\varepsilon} M = ε 2 d . Since length ∣ w ∣ \lvert w\rvert ∣ w ∣ is a geometric random variable, P ( w , y ) ∼ D ( ∣ w ∣ > M ) = ( 1 − 1 d − 1 ) M < e − 2 / ε \mathbb{P}_{(w,y)\sim D}(\lvert w\rvert>M)=\left(1-\frac{1}{d-1}\right)^M<e^{-2/\varepsilon} P ( w , y ) ∼ D (∣ w ∣ > M ) = ( 1 − d − 1 1 ) M < e − 2/ ε . Since the squared loss remains bounded by 2 2 2 for the choice of f α , β ( w ) = 2 γ s ( w ) − 1 f_{\alpha,\beta}(w)=2\gamma_s(w)-1 f α , β ( w ) = 2 γ s ( w ) − 1 , the contribution of long words to the risk L ( α , β ) \mathcal{L}(\alpha,\beta) L ( α , β ) is bounded by 2 e − 2 / ε < ε / 2 2e^{-2/\varepsilon}<\varepsilon/2 2 e − 2/ ε < ε /2 .
For short words, ∣ w ∣ ≤ M = 2 d / ε \lvert w\rvert\le M=2d/\varepsilon ∣ w ∣ ≤ M = 2 d / ε with C s ( w ) ≥ 1 C_s(w)\ge1 C s ( w ) ≥ 1 , the attention is bounded from below as γ s ( w ) ≥ 4 d ⋅ C s ( w ) 4 d ⋅ C s ( w ) + ε 2 ( m − C s ( w ) ) ≥ 4 d 4 d + 2 d ε = 2 2 + ε \gamma_s(w)\ge\frac{4d\cdot C_s(w)}{4d\cdot C_s(w)+\varepsilon^2(m-C_s(w))}\ge\frac{4d}{4d+2d\varepsilon}=\frac{2}{2+\varepsilon} γ s ( w ) ≥ 4 d ⋅ C s ( w ) + ε 2 ( m − C s ( w )) 4 d ⋅ C s ( w ) ≥ 4 d + 2 d ε 4 d = 2 + ε 2 , and from above since γ s ( w ) ≤ 1 \gamma_s(w)\le1 γ s ( w ) ≤ 1 due to softmax. Hence, the loss for any short word w ∈ A s w\in A_s w ∈ A s is bounded as 1 2 ( f α , β ( w ) − 1 ) 2 ≤ 2 ε 2 ( 2 + ε ) 2 < ε 2 \frac{1}{2}(f_{\alpha,\beta}(w)-1)^2\le\frac{2\varepsilon^2}{(2+\varepsilon)^2}<\frac{\varepsilon}{2} 2 1 ( f α , β ( w ) − 1 ) 2 ≤ ( 2 + ε ) 2 2 ε 2 < 2 ε . Hence, short words also contribute to at most ε / 2 \varepsilon/2 ε /2 risk, and overall L ( α , β ) ≤ ε \mathcal{L}(\alpha,\beta)\le\varepsilon L ( α , β ) ≤ ε .
Proof of Proposition 2
Proof. Let the target index be s = arg min i ∈ [ d ] β ~ i s=\arg\min_{i\in[d]}\widetilde{\beta}_i s = arg min i ∈ [ d ] β i and discuss the loss based on its value. When β ~ s ≥ 1 \widetilde{\beta}_s\ge1 β s ≥ 1 , it follows that y ^ ( w ) = ∑ i = 1 d β ~ i γ i ( w ) − 1 ≥ min i ∈ [ d ] β ~ i − 1 ≥ 0 \hat{y}(w)=\sum_{i=1}^{d}\widetilde{\beta}_i\gamma_i(w)-1\ge\min_{i\in[d]}\widetilde{\beta}_i-1\ge0 y ^ ( w ) = ∑ i = 1 d β i γ i ( w ) − 1 ≥ min i ∈ [ d ] β i − 1 ≥ 0 for any input w w w and any attention weights α \alpha α . In this case, the expected risk is lower bounded by P ( y = − 1 ) × 1 2 × ( 0 + 1 ) 2 = 1 4 \mathbb{P}(y=-1)\times\frac{1}{2}\times(0+1)^2=\frac{1}{4} P ( y = − 1 ) × 2 1 × ( 0 + 1 ) 2 = 4 1 .
When β ~ s < 1 \widetilde{\beta}_s<1 β s < 1 , we lower bound the risk incurred on negative samples z z z of length m m m together with their positive counterparts. For a given z z z of length m m m , consider all positive samples z ′ z' z ′ obtained by inserting n ≥ 1 n\ge1 n ≥ 1 copies of s s s into z z z . write R ( d ) : = d 2 − d d 2 − 2 d + 2 > 1 R(d):=\frac{d^2-d}{d^2-2d+2}>1 R ( d ) := d 2 − 2 d + 2 d 2 − d > 1 , we first compute the ratio of the two probability masses:
∑ z ′ ρ ( z ′ ) ρ ( z ) = ∑ n ≥ 1 ( m + n n ) ( 1 − p ) m + n − 1 p ( 1 d ) m + n ( 1 − p ) m − 1 p ( 1 d ) m = ∑ n = 0 ∞ ( m + n n ) ( 1 − p ) n ( 1 d ) n − 1 = R ( d ) m + 1 − 1 ≥ ( m + 1 ) ( R ( d ) − 1 ) \begin{aligned}
\frac{\sum_{z'}\rho(z')}{\rho(z)}
=\frac{\sum_{n\ge1}\binom{m+n}{n}(1-p)^{m+n-1}p\left(\frac{1}{d}\right)^{m+n}}{(1-p)^{m-1}p\left(\frac{1}{d}\right)^m} \\
&=\sum_{n=0}^{\infty}\binom{m+n}{n}(1-p)^n\left(\frac{1}{d}\right)^n-1 \\
&=R(d)^{m+1}-1\ge(m+1)(R(d)-1)
\end{aligned} ρ ( z ) ∑ z ′ ρ ( z ′ ) = ( 1 − p ) m − 1 p ( d 1 ) m ∑ n ≥ 1 ( n m + n ) ( 1 − p ) m + n − 1 p ( d 1 ) m + n = n = 0 ∑ ∞ ( n m + n ) ( 1 − p ) n ( d 1 ) n − 1 = R ( d ) m + 1 − 1 ≥ ( m + 1 ) ( R ( d ) − 1 )
Therefore, for each negative sample z z z whose length satisfies m ≥ d + 1 2 m\ge\frac{d+1}{2} m ≥ 2 d + 1 , it holds that ∑ z ′ ρ ( z ′ ) ρ ( z ) ≥ 1 2 \frac{\sum_{z'}\rho(z')}{\rho(z)}\ge\frac{1}{2} ρ ( z ) ∑ z ′ ρ ( z ′ ) ≥ 2 1 .
For each negative sample z z z , write the output as y ^ ( z ) = G ( z ) − 1 = ∑ i ≠ s β ~ i γ i ( z ) − 1 \hat{y}(z)=G(z)-1=\sum_{i\ne s}\widetilde{\beta}_i\gamma_i(z)-1 y ^ ( z ) = G ( z ) − 1 = ∑ i = s β i γ i ( z ) − 1 , then for each of the positive counterpart z ′ z' z ′ , we have y ^ ( z ′ ) = β ~ s γ s ( z ′ ) + G ( z ) ⋅ ( 1 − γ s ( z ′ ) ) − 1 \hat{y}(z')=\widetilde{\beta}_s\gamma_s(z')+G(z)\cdot(1-\gamma_s(z'))-1 y ^ ( z ′ ) = β s γ s ( z ′ ) + G ( z ) ⋅ ( 1 − γ s ( z ′ )) − 1 . Now we distinguish two cases:
If G ( z ) < 1 G(z)<1 G ( z ) < 1 : since β ~ s < 1 \widetilde{\beta}_s<1 β s < 1 , the convex combination β ~ s γ s ( z ′ ) + G ( z ) ⋅ ( 1 − γ s ( z ′ ) ) < 1 \widetilde{\beta}_s\gamma_s(z')+G(z)\cdot(1-\gamma_s(z'))<1 β s γ s ( z ′ ) + G ( z ) ⋅ ( 1 − γ s ( z ′ )) < 1 for every γ s ( z ′ ) ∈ [ 0 , 1 ] \gamma_s(z')\in[0,1] γ s ( z ′ ) ∈ [ 0 , 1 ] , so y ^ ( z ′ ) < 0 \hat{y}(z')<0 y ^ ( z ′ ) < 0 , giving 1 2 ( y ^ ( z ′ ) − 1 ) 2 > 1 2 \frac{1}{2}(\hat{y}(z')-1)^2>\frac{1}{2} 2 1 ( y ^ ( z ′ ) − 1 ) 2 > 2 1 on every positive counterpart, regardless of n n n or α \alpha α .
In either case, the probability mass of samples with an error greater than 1 2 \frac{1}{2} 2 1 is at least min { ρ ( z ) , ∑ z ′ ρ ( z ′ ) } \min\{\rho(z),\sum_{z'}\rho(z')\} min { ρ ( z ) , ∑ z ′ ρ ( z ′ )} . Summing over the window where the negative samples has length m ≥ ⌈ d + 1 2 ⌉ m\ge\left\lceil\frac{d+1}{2}\right\rceil m ≥ ⌈ 2 d + 1 ⌉ , we get:
L ( α , β ~ ) ≥ ∑ ∣ z ∣ ≥ ⌈ d + 1 2 ⌉ χ s ( z ) = − 1 1 2 ⋅ min { ρ ( z ) , ∑ z ′ ρ ( z ′ ) } ≥ ∑ ∣ z ∣ ≥ ⌈ d + 1 2 ⌉ χ s ( z ) = − 1 1 2 ⋅ 1 2 ⋅ ρ ( z ) = 1 8 ( 1 − 2 d ) ⌈ d + 1 2 ⌉ − 1 ≥ 1 32 , \mathcal{L}(\alpha,\widetilde{\beta})\ge\sum_{\substack{\lvert z\rvert\ge\left\lceil\frac{d+1}{2}\right\rceil\\ \chi_s(z)=-1}}\frac{1}{2}\cdot\min\left\{\rho(z),\sum_{z'}\rho(z')\right\}\ge\sum_{\substack{\lvert z\rvert\ge\left\lceil\frac{d+1}{2}\right\rceil\\ \chi_s(z)=-1}}\frac{1}{2}\cdot\frac{1}{2}\cdot\rho(z)=\frac{1}{8}\left(1-\frac{2}{d}\right)^{\left\lceil\frac{d+1}{2}\right\rceil-1}\ge\frac{1}{32}, L ( α , β ) ≥ ∣ z ∣ ≥ ⌈ 2 d + 1 ⌉ χ s ( z ) = − 1 ∑ 2 1 ⋅ min { ρ ( z ) , z ′ ∑ ρ ( z ′ ) } ≥ ∣ z ∣ ≥ ⌈ 2 d + 1 ⌉ χ s ( z ) = − 1 ∑ 2 1 ⋅ 2 1 ⋅ ρ ( z ) = 8 1 ( 1 − d 2 ) ⌈ 2 d + 1 ⌉ − 1 ≥ 32 1 ,
where the last inequality follows from the monotonicity of the bound on the even and odd sequences of d d d , minimized at d = 4 d=4 d = 4 and d = 3 d=3 d = 3 respectively.
Proof of Proposition 3
Proof. We consider the target symbol as s = arg min i ∈ [ d ] α ~ i s=\arg\min_{i\in[d]}\tilde{\alpha}_i s = arg min i ∈ [ d ] α ~ i . First, consider any β s ≥ d + 1 \beta_s\ge d+1 β s ≥ d + 1 , we can lower bound the expected risk by summing up the error on all samples made from only the set symbols:
L s ( α ~ , β ) ≥ 1 2 ( β s − 2 ) 2 ⋅ ∑ m = 1 ∞ ( 1 − p ) m − 1 p ( 1 d ) m ≥ d 2 8 [ ( d − 1 ) 2 + 1 ] ≥ 1 8 . \mathcal{L}_s(\tilde{\alpha},\beta)\ge\frac{1}{2}(\beta_s-2)^2\cdot\sum_{m=1}^{\infty}(1-p)^{m-1}p\left(\frac{1}{d}\right)^m\ge\frac{d^2}{8[(d-1)^2+1]}\ge\frac{1}{8}. L s ( α ~ , β ) ≥ 2 1 ( β s − 2 ) 2 ⋅ m = 1 ∑ ∞ ( 1 − p ) m − 1 p ( d 1 ) m ≥ 8 [( d − 1 ) 2 + 1 ] d 2 ≥ 8 1 .
Otherwise, when β s < d + 1 \beta_s<d+1 β s < d + 1 , we consider the prediction for every negative sample z z z whose length satisfies m = ∣ z ∣ > d m=|z|>d m = ∣ z ∣ > d and its corresponding positive counterparts where we insert one s s s into z z z . We first compute the ratio between the two masses, which gives:
∑ z ′ ρ ( z ′ ) ρ ( z ) = ( m + 1 ) ( 1 − p ) m p ( 1 d ) m + 1 ( 1 − p ) m − 1 p ( 1 d ) m = ( m + 1 ) ( 1 − p ) d ≥ 1 2 . (8) \frac{\sum_{z'}\rho(z')}{\rho(z)}=\frac{(m+1)(1-p)^mp\left(\frac{1}{d}\right)^{m+1}}{(1-p)^{m-1}p\left(\frac{1}{d}\right)^m}=\frac{(m+1)(1-p)}{d}\ge\frac{1}{2}. \tag*{(8)} ρ ( z ) ∑ z ′ ρ ( z ′ ) = ( 1 − p ) m − 1 p ( d 1 ) m ( m + 1 ) ( 1 − p ) m p ( d 1 ) m + 1 = d ( m + 1 ) ( 1 − p ) ≥ 2 1 . (8)
For each negative sample z z z , write the output as y ^ ( z ) = G ( z ) − 1 = ∑ i ≠ s β i γ i ( z ) − 1 \hat{y}(z)=G(z)-1=\sum_{i\ne s}\beta_i\gamma_i(z)-1 y ^ ( z ) = G ( z ) − 1 = ∑ i = s β i γ i ( z ) − 1 . And for each counterpart z ′ z' z ′ , y ^ ( z ′ ) = G ( z ) ⋅ ( 1 − γ s ( z ′ ) ) + β s ⋅ γ s ( z ′ ) − 1 \hat{y}(z')=G(z)\cdot(1-\gamma_s(z'))+\beta_s\cdot\gamma_s(z')-1 y ^ ( z ′ ) = G ( z ) ⋅ ( 1 − γ s ( z ′ )) + β s ⋅ γ s ( z ′ ) − 1 . Now we distinguish two cases:
G ( z ) > 1 2 G(z)>\frac{1}{2} G ( z ) > 2 1 : then y ^ ( z ) > − 1 2 \hat{y}(z)>-\frac{1}{2} y ^ ( z ) > − 2 1 , and the error on the negative sample is at least 1 8 \frac{1}{8} 8 1 .
G ( z ) ≤ 1 2 G(z)\le\frac{1}{2} G ( z ) ≤ 2 1 : since exp ( α s ) < exp ( α i ) \exp(\alpha_s)<\exp(\alpha_i) exp ( α s ) < exp ( α i ) for any i ≠ s i\ne s i = s , we have γ s ( z ′ ) ≤ 1 1 + d \gamma_s(z')\le\frac{1}{1+d} γ s ( z ′ ) ≤ 1 + d 1 , and y ^ ( z ′ ) ≤ 1 2 \hat{y}(z')\le\frac{1}{2} y ^ ( z ′ ) ≤ 2 1 , therefore the error on each z ′ z' z ′ is at least 1 8 \frac{1}{8} 8 1 .
In either case, the probability mass of samples with an error greater than 1 8 \frac{1}{8} 8 1 is at least min { ρ ( z ) , ∑ z ′ ρ ( z ′ ) } \min\{\rho(z),\sum_{z'}\rho(z')\} min { ρ ( z ) , ∑ z ′ ρ ( z ′ )} . Summing over the window where the negative samples has length m ≥ d + 1 m\ge d+1 m ≥ d + 1 , we have:
L ( α ~ , β ) ≥ ∑ ∣ z ∣ ≥ d + 1 χ s ( z ) = − 1 1 8 ⋅ min { ρ ( z ) , ∑ z ′ ρ ( z ′ ) } ≥ ∑ ∣ z ∣ ≥ d + 1 χ s ( z ) = − 1 1 16 ⋅ ρ ( z ) = 1 16 ⋅ 1 2 ( 1 − 2 d ) d = 1 32 ( 1 − 2 d ) d ≥ 1 864 . \mathcal{L}(\tilde{\alpha},\beta)\ge\sum_{\substack{|z|\ge d+1\\ \chi_s(z)=-1}}\frac{1}{8}\cdot\min\{\rho(z),\sum_{z'}\rho(z')\}\ge\sum_{\substack{|z|\ge d+1\\ \chi_s(z)=-1}}\frac{1}{16}\cdot\rho(z)=\frac{1}{16}\cdot\frac{1}{2}\left(1-\frac{2}{d}\right)^d=\frac{1}{32}\left(1-\frac{2}{d}\right)^d\ge\frac{1}{864}. L ( α ~ , β ) ≥ ∣ z ∣ ≥ d + 1 χ s ( z ) = − 1 ∑ 8 1 ⋅ min { ρ ( z ) , z ′ ∑ ρ ( z ′ )} ≥ ∣ z ∣ ≥ d + 1 χ s ( z ) = − 1 ∑ 16 1 ⋅ ρ ( z ) = 16 1 ⋅ 2 1 ( 1 − d 2 ) d = 32 1 ( 1 − d 2 ) d ≥ 864 1 .
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 α ( 1 ) , … , α ( H ) ∈ R d \alpha^{(1)},\ldots,\alpha^{(H)}\in\mathbb{R}^d α ( 1 ) , … , α ( H ) ∈ R d , there exists s ∈ [ d ] s\in[d] s ∈ [ d ] , such that
∑ h = 1 H E [ ( γ s ( h ) ( w ) ) 2 ] ≤ H d . \sum_{h=1}^{H}\mathbb{E}\left[\left(\gamma_s^{(h)}(w)\right)^2\right]\le\frac{H}{d}. h = 1 ∑ H E [ ( γ s ( h ) ( w ) ) 2 ] ≤ d H .
Proof. By the definition of softmax, for each string w w w and each head h h h , γ i ( h ) ( w ) ∈ [ 0 , 1 ] \gamma_i^{(h)}(w)\in[0,1] γ i ( h ) ( w ) ∈ [ 0 , 1 ] for every i ∈ [ d ] i\in[d] i ∈ [ d ] , hence:
∑ i = 1 d ( γ i ( h ) ( w ) ) 2 ≤ ( ∑ i = 1 d γ i ( h ) ( w ) ) 2 = 1. \sum_{i=1}^{d}\left(\gamma_i^{(h)}(w)\right)^2\le\left(\sum_{i=1}^{d}\gamma_i^{(h)}(w)\right)^2=1. i = 1 ∑ d ( γ i ( h ) ( w ) ) 2 ≤ ( i = 1 ∑ d γ i ( h ) ( w ) ) 2 = 1.
Taking expectation over w w w and summing over all heads gives ∑ h = 1 H ∑ i = 1 d E [ ( γ i ( h ) ( w ) ) 2 ] ≤ H \sum_{h=1}^{H}\sum_{i=1}^{d}\mathbb{E}\left[\left(\gamma_i^{(h)}(w)\right)^2\right]\le H ∑ h = 1 H ∑ i = 1 d E [ ( γ i ( h ) ( w ) ) 2 ] ≤ H . Therefore, there exists an index s ∈ [ d ] s\in[d] s ∈ [ d ] such that ∑ h = 1 H E [ ( γ s ( h ) ( w ) ) 2 ] ≤ H d \sum_{h=1}^{H}\mathbb{E}\left[\left(\gamma_s^{(h)}(w)\right)^2\right]\le\frac{H}{d} ∑ h = 1 H E [ ( γ s ( h ) ( w ) ) 2 ] ≤ d H .
We choose s s s that satisfies Lemma 1 as the target index. Consider any negative string z z z whose length m m m satisfies ⌈ d 2 ⌉ ≤ m ≤ d − 1 \left\lceil\frac{d}{2}\right\rceil\le m\le d-1 ⌈ 2 d ⌉ ≤ m ≤ d − 1 , it follows that ρ ( z ) = ( 1 − p ) m − 1 p ( 1 d ) m \rho(z)=(1-p)^{m-1}p\left(\frac{1}{d}\right)^m ρ ( z ) = ( 1 − p ) m − 1 p ( d 1 ) m . Let P ( z ) \mathcal{P}(z) P ( z ) be the set of positive strings which after removing all s s s will result in z z z , we have ρ ( P ( z ) ) = ∑ n = 1 ∞ ( m + n n ) ( 1 − p ) m + n − 1 p ⋅ ( 1 d ) m + n \rho(\mathcal{P}(z)) = \sum_{n=1}^{\infty} \binom{m+n}{n}(1-p)^{m+n-1}p\cdot\left(\frac{1}{d}\right)^{m+n} ρ ( P ( z )) = ∑ n = 1 ∞ ( n m + n ) ( 1 − p ) m + n − 1 p ⋅ ( d 1 ) m + n . Further, we can consider the ratio between the two masses, which simplifies into:
ρ ( P ( z ) ) ρ ( z ) = ∑ n = 1 ∞ ( m + n n ) ( 1 − p ) n ( 1 d ) n = ( d − 2 d 2 − 2 d + 2 + 1 ) m + 1 − 1 ≥ 1 2 . \frac{\rho(\mathcal{P}(z))}{\rho(z)}=\sum_{n=1}^{\infty}\binom{m+n}{n}(1-p)^n\left(\frac{1}{d}\right)^n=\left(\frac{d-2}{d^2-2d+2}+1\right)^{m+1}-1\geq\frac{1}{2}. ρ ( z ) ρ ( P ( z )) = n = 1 ∑ ∞ ( n m + n ) ( 1 − p ) n ( d 1 ) n = ( d 2 − 2 d + 2 d − 2 + 1 ) m + 1 − 1 ≥ 2 1 .
For any z ′ ∈ P ( z ) z' \in\mathcal{P}(z) z ′ ∈ P ( z ) , we can write the output as f ( z ′ ) = ∑ h = 1 H [ ( 1 − γ s ( h ) ( z ′ ) ) g ( h ) ( z ′ ) + β s ( h ) ⋅ γ s ( h ) ( z ′ ) ] − 1 f(z')=\sum_{h=1}^{H}\left[\left(1-\gamma_s^{(h)}(z')\right)g^{(h)}(z')+\beta_s^{(h)}\cdot\gamma_s^{(h)}(z')\right]-1 f ( z ′ ) = ∑ h = 1 H [ ( 1 − γ s ( h ) ( z ′ ) ) g ( h ) ( z ′ ) + β s ( h ) ⋅ γ s ( h ) ( z ′ ) ] − 1 , where g ( h ) ( z ) = ∑ i ≠ s β i ( h ) γ i ( h ) ( z ) g^{(h)}(z)=\sum_{i\neq s}\beta_i^{(h)}\gamma_i^{(h)}(z) g ( h ) ( z ) = ∑ i = s β i ( h ) γ i ( h ) ( z ) . Since ∣ g ( h ) ( z ) ∣ ≤ ∥ β ( h ) ∥ 2 ∥ γ ( h ) ( z ) ∥ 2 ≤ ∥ β ( h ) ∥ 2 \lvert g^{(h)}(z)\rvert\leq\|\beta^{(h)}\|_2\|\gamma^{(h)}(z)\|_2\leq\|\beta^{(h)}\|_2 ∣ g ( h ) ( z )∣ ≤ ∥ β ( h ) ∥ 2 ∥ γ ( h ) ( z ) ∥ 2 ≤ ∥ β ( h ) ∥ 2 and ∣ β s ( h ) ∣ ≤ ∥ β ( h ) ∥ 2 \lvert\beta_s^{(h)}\rvert\leq\|\beta^{(h)}\|_2 ∣ β s ( h ) ∣ ≤ ∥ β ( h ) ∥ 2 , we have:
∣ f ( z ′ ) − f ( z ) ∣ = ∣ ∑ h = 1 H γ s ( h ) ( z ′ ) ( β s ( h ) − g ( h ) ( z ) ) ∣ ≤ 2 ∑ h = 1 H γ s ( h ) ( z ′ ) ∥ β ( h ) ∥ 2 ≤ 2 ∥ B ∥ F ( ∑ h = 1 H ( γ s ( h ) ( z ′ ) ) 2 ) 1 / 2 , \lvert f(z')-f(z)\rvert=\left\lvert\sum_{h=1}^{H}\gamma_s^{(h)}(z')\left(\beta_s^{(h)}-g^{(h)}(z)\right)\right\rvert\leq2\sum_{h=1}^{H}\gamma_s^{(h)}(z')\|\beta^{(h)}\|_2\leq2\|\mathbf{B}\|_F\left(\sum_{h=1}^{H}\left(\gamma_s^{(h)}(z')\right)^2\right)^{1/2}, ∣ f ( z ′ ) − f ( z )∣ = h = 1 ∑ H γ s ( h ) ( z ′ ) ( β s ( h ) − g ( h ) ( z ) ) ≤ 2 h = 1 ∑ H γ s ( h ) ( z ′ ) ∥ β ( h ) ∥ 2 ≤ 2∥ B ∥ F ( h = 1 ∑ H ( γ s ( h ) ( z ′ ) ) 2 ) 1/2 ,
where the last step is from Cauchy-Schwarz inequality over the H H H heads.
For each negative string z z z and each z ′ ∈ P ( z ) z'\in\mathcal{P}(z) z ′ ∈ P ( z ) , we define a coupling weight ν ( z , z ′ ) : = min ( ρ ( z ) , ρ ( P ( z ) ) ) ⋅ ρ ( z ′ ) ρ ( P ( z ) ) \nu(z,z'):=\min\left(\rho(z),\rho(\mathcal{P}(z))\right)\cdot\frac{\rho(z')}{\rho(\mathcal{P}(z))} ν ( z , z ′ ) := min ( ρ ( z ) , ρ ( P ( z )) ) ⋅ ρ ( P ( z )) ρ ( z ′ ) . First, it directly follows that ν ( z , z ′ ) ≤ ρ ( z ′ ) \nu(z,z')\leq\rho(z') ν ( z , z ′ ) ≤ ρ ( z ′ ) . Second, ∑ z ′ ∈ P ( z ) ν ( z , z ′ ) < ρ ( z ) \sum_{z'\in\mathcal{P}(z)}\nu(z,z')<\rho(z) ∑ z ′ ∈ P ( z ) ν ( z , z ′ ) < ρ ( z ) . Since ρ ( P ( z ) ) ρ ( z ) ≥ 1 2 \frac{\rho(\mathcal{P}(z))}{\rho(z)}\geq\frac{1}{2} ρ ( z ) ρ ( P ( z )) ≥ 2 1 in the length window we considered for z z z , it holds that min ( ρ ( z ) , ρ ( P ( z ) ) ) ≥ 1 2 ρ ( z ) \min(\rho(z),\rho(\mathcal{P}(z)))\geq\frac{1}{2}\rho(z) min ( ρ ( z ) , ρ ( P ( z ))) ≥ 2 1 ρ ( z ) , hence the total coupling mass is lower bounded by:
∑ ⌈ d / 2 ⌉ ≤ ∣ z ∣ ≤ d − 1 ∑ z ′ ∈ P ( z ) ν ( z , z ′ ) = ∑ z min ( ρ ( z ) , ρ ( P ( z ) ) ) ≥ 1 2 ∑ ⌈ d / 2 ⌉ ≤ ∣ z ∣ ≤ d − 1 ρ ( z ) = 1 2 ∑ m = ⌈ d / 2 ⌉ d ( 1 − p ) m − 1 p ( d − 1 d ) m = 1 4 [ ( 1 − 2 d ) ⌈ d / 2 ⌉ − 1 − ( 1 − 2 d ) d − 1 ] : = M \begin{aligned}
\sum_{\lceil d/2\rceil\leq|z|\leq d-1}\sum_{z'\in\mathcal{P}(z)}\nu(z,z')=\sum_z\min(\rho(z),\rho(\mathcal{P}(z)))\geq\frac{1}{2}\sum_{\lceil d/2\rceil\leq|z|\leq d-1}\rho(z)=\frac{1}{2}\sum_{m=\lceil d/2\rceil}^{d}(1-p)^{m-1}p\left(\frac{d-1}{d}\right)^m \\
&=\frac{1}{4}\left[\left(1-\frac{2}{d}\right)^{\lceil d/2\rceil-1}-\left(1-\frac{2}{d}\right)^{d-1}\right]:=M
\end{aligned} ⌈ d /2 ⌉ ≤ ∣ z ∣ ≤ d − 1 ∑ z ′ ∈ P ( z ) ∑ ν ( z , z ′ ) = z ∑ min ( ρ ( z ) , ρ ( P ( z ))) ≥ 2 1 ⌈ d /2 ⌉ ≤ ∣ z ∣ ≤ d − 1 ∑ ρ ( z ) = 2 1 m = ⌈ d /2 ⌉ ∑ d ( 1 − p ) m − 1 p ( d d − 1 ) m = 4 1 [ ( 1 − d 2 ) ⌈ d /2 ⌉ − 1 − ( 1 − d 2 ) d − 1 ] := M
We write x = 1 − 2 d x=1-\frac{2}{d} x = 1 − d 2 . For any 0 < t < 1 0<t<1 0 < t < 1 , we have exp ( − t 1 − t ) ≤ 1 − t ≤ exp ( − t ) \exp\left(-\frac{t}{1-t}\right)\leq1-t\leq\exp(-t) exp ( − 1 − t t ) ≤ 1 − t ≤ exp ( − t ) . Plug in t = 2 / d t=2/d t = 2/ d , we get x ≥ exp ( − 2 d − 2 ) x\geq\exp\left(-\frac{2}{d-2}\right) x ≥ exp ( − d − 2 2 ) . Since ⌈ d / 2 ⌉ − 1 ≤ d 2 \lceil d/2\rceil-1\leq\frac{d}{2} ⌈ d /2 ⌉ − 1 ≤ 2 d , we get 2 ⋅ ⌈ d / 2 ⌉ − 1 d − 2 ≤ d d − 2 ≤ 3 2\cdot\frac{\lceil d/2\rceil-1}{d-2}\leq\frac{d}{d-2}\leq3 2 ⋅ d − 2 ⌈ d /2 ⌉ − 1 ≤ d − 2 d ≤ 3 for all d ≥ 3 d\geq3 d ≥ 3 , so x ⌈ d / 2 ⌉ − 1 ≥ exp ( − 2 ⌈ d / 2 ⌉ − 1 d − 2 ) ≥ exp ( − 3 ) x^{\lceil d/2\rceil-1}\geq\exp\left(-2\frac{\lceil d/2\rceil-1}{d-2}\right)\geq\exp(-3) x ⌈ d /2 ⌉ − 1 ≥ exp ( − 2 d − 2 ⌈ d /2 ⌉ − 1 ) ≥ exp ( − 3 ) . Using the other side of the inequality, since x ≤ exp ( − 2 d ) x\leq\exp\left(-\frac{2}{d}\right) x ≤ exp ( − d 2 ) and ⌊ d / 2 ⌋ ≥ d − 1 2 \lfloor d/2\rfloor\geq\frac{d-1}{2} ⌊ d /2 ⌋ ≥ 2 d − 1 , we have x ⌊ d / 2 ⌋ ≤ exp ( − 2 ⌊ d / 2 ⌋ d ) ≤ exp ( − d − 1 d ) ≤ exp ( − 2 3 ) x^{\lfloor d/2\rfloor}\leq\exp\left(-\frac{2\lfloor d/2\rfloor}{d}\right)\leq\exp\left(-\frac{d-1}{d}\right)\leq\exp\left(-\frac{2}{3}\right) x ⌊ d /2 ⌋ ≤ exp ( − d 2 ⌊ d /2 ⌋ ) ≤ exp ( − d d − 1 ) ≤ exp ( − 3 2 ) , which gives us 1 − x ⌊ d / 2 ⌋ ≥ 1 − exp ( − 2 3 ) 1-x^{\lfloor d/2\rfloor}\geq1-\exp\left(-\frac{2}{3}\right) 1 − x ⌊ d /2 ⌋ ≥ 1 − exp ( − 3 2 ) . Combining both sides, we have M ≥ 1 4 exp ( − 3 ) ( 1 − exp ( − 2 3 ) ) > 0 M\geq\frac{1}{4}\exp(-3)\left(1-\exp\left(-\frac{2}{3}\right)\right)>0 M ≥ 4 1 exp ( − 3 ) ( 1 − exp ( − 3 2 ) ) > 0 , which is an absolute constant independent of d d d .
Define E p a i r [ ⋅ ] : = 1 M ∑ z , z ′ ν ( z , z ′ ) × ( ⋅ ) \mathbb{E}_{\mathrm{pair}}[\cdot]:=\frac{1}{M}\sum_{z,z'}\nu(z,z')\times(\cdot) E pair [ ⋅ ] := M 1 ∑ z , z ′ ν ( z , z ′ ) × ( ⋅ ) . Since ν ( z , z ′ ) ≤ ρ ( z ′ ) \nu(z,z')\leq\rho(z') ν ( z , z ′ ) ≤ ρ ( z ′ ) , we have:
E p a i r [ ∑ h = 1 H ( γ s ( h ) ( z ′ ) ) 2 ] ≤ 1 M ∑ h = 1 H E ρ [ ( γ s ( h ) ( w ) ) 2 ] ≤ H d M , \mathbb{E}_{\mathrm{pair}}\left[\sum_{h=1}^{H}\left(\gamma_s^{(h)}(z')\right)^2\right]\leq\frac{1}{M}\sum_{h=1}^{H}\mathbb{E}_{\rho}\left[\left(\gamma_s^{(h)}(w)\right)^2\right]\leq\frac{H}{dM}, E pair [ h = 1 ∑ H ( γ s ( h ) ( z ′ ) ) 2 ] ≤ M 1 h = 1 ∑ H E ρ [ ( γ s ( h ) ( w ) ) 2 ] ≤ d M H ,
using Lemma 1 in the last step. Finally, by Jensen’s inequality, we have:
E p a i r ∣ f ( z ′ ) − f ( z ) ∣ ≤ 2 ∥ B ∥ F H d M . (9) \mathbb{E}_{\mathrm{pair}}\lvert f(z')-f(z)\rvert\leq2\|\mathbf{B}\|_F\sqrt{\frac{H}{dM}}. \tag*{(9)} E pair ∣ f ( z ′ ) − f ( z )∣ ≤ 2∥ B ∥ F d M H . (9)
For every pair ( z , z ′ ) (z,z') ( z , z ′ ) , y ( z ) = − 1 y(z)=-1 y ( z ) = − 1 and y ( z ′ ) = 1 y(z')=1 y ( z ′ ) = 1 . Denote e z : = f ( z ) + 1 e_z:=f(z)+1 e z := f ( z ) + 1 and e z ′ : = f ( z ′ ) − 1 e_{z'}:=f(z')-1 e z ′ := f ( z ′ ) − 1 , we have e z 2 + e z ′ 2 ≥ 1 2 ( 2 − ∣ f ( z ′ ) − f ( z ) ∣ ) + 2 e_z^2+e_{z'}^2\geq\frac{1}{2}(2-\lvert f(z')-f(z)\rvert)_+^2 e z 2 + e z ′ 2 ≥ 2 1 ( 2 − ∣ f ( z ′ ) − f ( z )∣ ) + 2 . Since u ↦ ( 2 − u ) + 2 u\mapsto(2-u)_+^2 u ↦ ( 2 − u ) + 2 is convex, combining Jensen’s inequality and Eq. (9) , we have:
E p a i r [ e z 2 + e z ′ 2 ] ≥ 1 2 ( 2 − 2 ∥ B ∥ F H d M ) + 2 . \mathbb{E}_{\mathrm{pair}}\left[e_z^2+e_{z'}^2\right]\geq\frac{1}{2}\left(2-2\|\mathbf{B}\|_F\sqrt{\frac{H}{dM}}\right)_+^2. E pair [ e z 2 + e z ′ 2 ] ≥ 2 1 ( 2 − 2∥ B ∥ F d M H ) + 2 .
Because ∑ z ′ ∈ P ( z ) ν ( z , z ′ ) ≤ ρ ( z ) \sum_{z'\in\mathcal{P}(z)}\nu(z,z')\leq\rho(z) ∑ z ′ ∈ P ( z ) ν ( z , z ′ ) ≤ ρ ( z ) and ν ( z , z ′ ) ≤ ρ ( z ′ ) \nu(z,z')\leq\rho(z') ν ( z , z ′ ) ≤ ρ ( z ′ ) as established above, the weighted sum ∑ z , z ′ ν ( z , z ′ ) ( e z 2 + e z ′ 2 ) \sum_{z,z'}\nu(z,z')(e_z^2+e_{z'}^2) ∑ z , z ′ ν ( z , z ′ ) ( e z 2 + e z ′ 2 ) is bounded above by the corresponding disjoint contribution to E ρ [ ( f ( w ) − y ( w ) ) 2 ] \mathbb{E}_{\rho}\left[(f(w)-y(w))^2\right] E ρ [ ( f ( w ) − y ( w ) ) 2 ] , hence we can bound the risk by:
L D ( f ) = 1 2 ⋅ E D [ ( f ( w ) − y ( w ) ) 2 ] ≥ 1 2 M ⋅ E p a i r [ e z 2 + e z ′ 2 ] ≥ M 4 ( 2 − 2 ∥ B ∥ F H d M ) + 2 . \mathcal{L}_{\mathcal{D}}(f)=\frac{1}{2}\cdot\mathbb{E}_{\mathcal{D}}\left[(f(w)-y(w))^{2}\right]\ge\frac{1}{2}M\cdot\mathbb{E}_{\mathrm{pair}}\left[e_{z}^{2}+e_{z'}^{2}\right]\ge\frac{M}{4}\left(2-2\lVert\mathcal{B}\rVert_{F}\sqrt{\frac{H}{dM}}\right)_{+}^{2}. L D ( f ) = 2 1 ⋅ E D [ ( f ( w ) − y ( w ) ) 2 ] ≥ 2 1 M ⋅ E pair [ e z 2 + e z ′ 2 ] ≥ 4 M ( 2 − 2 ∥ B ∥ F d M H ) + 2 .
Equivalently, when the number of heads H ≤ d M 4 ∥ B ∥ F 2 H\le\frac{dM}{4\lVert\mathcal{B}\rVert_{F}^{2}} H ≤ 4 ∥ B ∥ F 2 d M , the loss is lower bounded by M 4 \frac{M}{4} 4 M . Since we know the output norm is bounded by ∥ B ∥ F 2 ≤ d \lVert\mathcal{B}\rVert_{F}^{2}\le\sqrt{d} ∥ B ∥ F 2 ≤ d , we have that when H ≤ M 4 d H\le\frac{M}{4}\sqrt{d} H ≤ 4 M d , the loss is lower bounded by M 4 \frac{M}{4} 4 M .
Proof of Theorem 1
Proof. First, we prove that for whatever α ′ \alpha' α ′ we obtained after the first step, if β s ≥ d 4 \beta_s\ge\frac{d}{4} β s ≥ 4 d then the population risk is already lower bounded by a constant. Here β ∈ R d \beta\in\mathbb{R}^{d} β ∈ R d is an arbitrary vector. Consider all positive samples with only s s s , then:
L ( α ′ , β ) ≥ ∑ m = 1 ∞ 1 2 ( d 4 − 2 ) 2 ⋅ ( 1 − p ) m − 1 p ( 1 d ) m = ( d − 8 ) 2 32 [ ( d − 1 ) 2 + 1 ] ≥ 1 2080 . \mathcal{L}(\alpha',\beta)\ge\sum_{m=1}^{\infty}\frac{1}{2}\left(\frac{d}{4}-2\right)^{2}\cdot(1-p)^{m-1}p\left(\frac{1}{d}\right)^{m}=\frac{(d-8)^{2}}{32\left[(d-1)^{2}+1\right]}\ge\frac{1}{2080}. L ( α ′ , β ) ≥ m = 1 ∑ ∞ 2 1 ( 4 d − 2 ) 2 ⋅ ( 1 − p ) m − 1 p ( d 1 ) m = 32 [ ( d − 1 ) 2 + 1 ] ( d − 8 ) 2 ≥ 2080 1 .
Hence in the rest of the analysis, we will only consider the case where β s ≤ d 4 \beta_s\le\frac{d}{4} β s ≤ 4 d . Now we prove that after the first gradient step, we can find an index s s s such that after the update, α s ′ ≤ 0 \alpha'_s\le0 α s ′ ≤ 0 . Consider the following sum of the gradients:
∑ i = 1 d ∂ L i ∂ α i = ∑ i = 1 d E [ ( y ^ ( w ) − χ i ( w ) ) ⋅ γ i ( β i − ∑ j = 1 d β j γ j ) ] = ∑ i = 1 d E [ ( ∑ j = 1 d β j γ j − 1 − 2 ⋅ 1 { C i ( w ) > 0 } + 1 ) γ i ( β i − ∑ j = 1 d β j γ j ) ] = E [ ∑ i = 1 d β i γ i ⋅ ( ∑ j = 1 d β j γ j ) − 2 ∑ i = 1 d β i γ i − ∑ i = 1 d γ i ( ∑ j = 1 d β j γ j ) 2 + 2 ∑ i = 1 d γ i ( ∑ j = 1 d β j γ j ) ] = E [ ( ∑ i = 1 d β i γ i ) 2 − 2 ∑ i = 1 d β i γ i − ( ∑ j = 1 d β j γ j ) 2 + 2 ∑ j = 1 d β j γ j ] = 0 \begin{aligned}
\sum_{i=1}^{d}\frac{\partial\mathcal{L}_i}{\partial\alpha_i}=\sum_{i=1}^{d}\mathbb{E}\left[\left(\hat{y}(w)-\chi_i(w)\right)\cdot\gamma_i\left(\beta_i-\sum_{j=1}^{d}\beta_j\gamma_j\right)\right] \\
&=\sum_{i=1}^{d}\mathbb{E}\left[\left(\sum_{j=1}^{d}\beta_j\gamma_j-1-2\cdot\mathbf{1}\{C_i(w)>0\}+1\right)\gamma_i\left(\beta_i-\sum_{j=1}^{d}\beta_j\gamma_j\right)\right] \\
&=\mathbb{E}\left[\sum_{i=1}^{d}\beta_i\gamma_i\cdot\left(\sum_{j=1}^{d}\beta_j\gamma_j\right)-2\sum_{i=1}^{d}\beta_i\gamma_i-\sum_{i=1}^{d}\gamma_i\left(\sum_{j=1}^{d}\beta_j\gamma_j\right)^{2}+2\sum_{i=1}^{d}\gamma_i\left(\sum_{j=1}^{d}\beta_j\gamma_j\right)\right] \\
&=\mathbb{E}\left[\left(\sum_{i=1}^{d}\beta_i\gamma_i\right)^{2}-2\sum_{i=1}^{d}\beta_i\gamma_i-\left(\sum_{j=1}^{d}\beta_j\gamma_j\right)^{2}+2\sum_{j=1}^{d}\beta_j\gamma_j\right]=0
\end{aligned} i = 1 ∑ d ∂ α i ∂ L i = i = 1 ∑ d E [ ( y ^ ( w ) − χ i ( w ) ) ⋅ γ i ( β i − j = 1 ∑ d β j γ j ) ] = i = 1 ∑ d E [ ( j = 1 ∑ d β j γ j − 1 − 2 ⋅ 1 { C i ( w ) > 0 } + 1 ) γ i ( β i − j = 1 ∑ d β j γ j ) ] = E i = 1 ∑ d β i γ i ⋅ ( j = 1 ∑ d β j γ j ) − 2 i = 1 ∑ d β i γ i − i = 1 ∑ d γ i ( j = 1 ∑ d β j γ j ) 2 + 2 i = 1 ∑ d γ i ( j = 1 ∑ d β j γ j ) = E ( i = 1 ∑ d β i γ i ) 2 − 2 i = 1 ∑ d β i γ i − ( j = 1 ∑ d β j γ j ) 2 + 2 j = 1 ∑ d β j γ j = 0
So there exists s ∈ [ d ] s\in[d] s ∈ [ d ] such that ∂ L ∂ α s ≥ 0 \frac{\partial\mathcal{L}}{\partial\alpha_s}\ge0 ∂ α s ∂ L ≥ 0 and α s ′ ≤ 0 \alpha'_s\le0 α s ′ ≤ 0 . Consider the sum of gradients of L s \mathcal{L}_s L s across all indices:
∑ i = 1 d ∂ L s ∂ α i = ∑ i = 1 d E [ ( y ^ − y ) ⋅ γ i ⋅ ( β i − ∑ j = 1 d β j γ j ) ] = E [ ( y ^ − y ) ⋅ ∑ i = 1 d γ i ⋅ ( β i − ∑ j = 1 d β j γ j ) ] = 0 , \sum_{i=1}^{d}\frac{\partial\mathcal{L}_s}{\partial\alpha_i}=\sum_{i=1}^{d}\mathbb{E}\left[\left(\hat{y}-y\right)\cdot\gamma_i\cdot\left(\beta_i-\sum_{j=1}^{d}\beta_j\gamma_j\right)\right]=\mathbb{E}\left[(\hat{y}-y)\cdot\sum_{i=1}^{d}\gamma_i\cdot\left(\beta_i-\sum_{j=1}^{d}\beta_j\gamma_j\right)\right]=0, i = 1 ∑ d ∂ α i ∂ L s = i = 1 ∑ d E [ ( y ^ − y ) ⋅ γ i ⋅ ( β i − j = 1 ∑ d β j γ j ) ] = E [ ( y ^ − y ) ⋅ i = 1 ∑ d γ i ⋅ ( β i − j = 1 ∑ d β j γ j ) ] = 0 ,
hence it follows ∑ i = 1 d α i ′ = 0 \sum_{i=1}^{d}\alpha'_i=0 ∑ i = 1 d α i ′ = 0 regardless of the learning rate. Therefore, ∑ i = 1 d exp ( α i ′ ) ≥ d ⋅ ( ∏ i = 1 d exp ( α i ′ ) ) 1 d = d \sum_{i=1}^{d}\exp(\alpha'_i)\ge d\cdot\left(\prod_{i=1}^{d}\exp(\alpha'_i)\right)^{\frac{1}{d}}=d ∑ i = 1 d exp ( α i ′ ) ≥ d ⋅ ( ∏ i = 1 d exp ( α i ′ ) ) d 1 = d . At the same time, α s ′ ≤ 0 \alpha'_s\le0 α s ′ ≤ 0 , which results in exp ( α s ′ ) ≤ 1 \exp(\alpha'_s)\le1 exp ( α s ′ ) ≤ 1 . We will shorthand a i : = exp ( α i ′ ) a_i:=\exp(\alpha'_i) a i := exp ( α i ′ ) in the remaining analysis.
Now we consider a negative string z z z with length m m m , where m ≥ d m\ge d m ≥ d , and the set of its positive counterparts Z Z Z where each z ′ ∈ Z z'\in Z z ′ ∈ Z is obtained by inserting exactly one symbol s s s into z z z . From (9) we have ρ ( z ′ ) ρ ( z ) ≥ 1 2 \frac{\rho(z')}{\rho(z)}\ge\frac{1}{2} ρ ( z ) ρ ( z ′ ) ≥ 2 1 .
For each counter part z ′ z' z ′ , write γ s ( z ′ ) = a s ∑ i ≠ s C i ( z ′ ) a i + a s \gamma_s(z')=\frac{a_s}{\sum_{i\ne s}C_i(z')a_i+a_s} γ s ( z ′ ) = ∑ i = s C i ( z ′ ) a i + a s a s . Consider the two following cases:
max i ≠ s a i ≥ d 2 \max_{i\ne s}a_i\ge\frac{d}{2} max i = s a i ≥ 2 d . In this case, the probability that the maximizer i i i appears in string z z z is 1 − ( 1 − 1 d − 1 ) m ≥ 1 − ( 1 − 1 d − 1 ) d 2 ≥ 1 − exp ( − 1 2 ) ≥ 1 8 1-\left(1-\frac{1}{d-1}\right)^m\ge1-\left(1-\frac{1}{d-1}\right)^{\frac{d}{2}}\ge1-\exp\left(-\frac{1}{2}\right)\ge\frac{1}{8} 1 − ( 1 − d − 1 1 ) m ≥ 1 − ( 1 − d − 1 1 ) 2 d ≥ 1 − exp ( − 2 1 ) ≥ 8 1 , under which case we have γ s ( z ′ ) ≤ 1 d 2 + 1 = 2 d + 2 < 4 d \gamma_s(z')\le\frac{1}{\frac{d}{2}+1}=\frac{2}{d+2}<\frac{4}{d} γ s ( z ′ ) ≤ 2 d + 1 1 = d + 2 2 < d 4
max i ≠ s a i < d 2 \max_{i\ne s} a_i < \frac{d}{2} max i = s a i < 2 d . In this case, consider the r.v. ξ ∼ Unif ( { a i : i ≠ s } ) \xi\sim\operatorname{Unif}(\{a_i:i\ne s\}) ξ ∼ Unif ({ a i : i = s }) , and we rewrite ∑ i ≠ s C i ( z ) a i = ∑ t = 1 m ξ t = : S \sum_{i\ne s} C_i(z)a_i = \sum_{t=1}^{m}\xi_t=:S ∑ i = s C i ( z ) a i = ∑ t = 1 m ξ t =: S .
We further derive the first and the second moments of ξ \xi ξ :
E [ ξ ] = 1 d − 1 ∑ i ≠ s a i ≥ 1 d − 1 ⋅ ( d − 1 ) = 1 , E [ ξ 2 ] ≤ max i ≠ s a i E [ ξ ] ≤ d 2 ⋅ E [ ξ ] . \mathbb{E}[\xi] = \frac{1}{d-1}\sum_{i\ne s}a_i \ge\frac{1}{d-1}\cdot(d-1)=1,\qquad\mathbb{E}[\xi^2]\le\max_{i\ne s}a_i\mathbb{E}[\xi]\le\frac{d}{2}\cdot\mathbb{E}[\xi]. E [ ξ ] = d − 1 1 i = s ∑ a i ≥ d − 1 1 ⋅ ( d − 1 ) = 1 , E [ ξ 2 ] ≤ i = s max a i E [ ξ ] ≤ 2 d ⋅ E [ ξ ] .
Hence, the first and the second moments of S S S can be written as:
E [ S ] = m E [ ξ ] , E [ S 2 ] = m E [ ξ 2 ] + m ( m − 1 ) E [ ξ ] 2 ≤ m ⋅ d 2 ⋅ E [ ξ ] + m ( m − 1 ) E [ ξ ] 2 . \mathbb{E}[S]=m\mathbb{E}[\xi],\qquad\mathbb{E}[S^2]=m\mathbb{E}[\xi^2]+m(m-1)\mathbb{E}[\xi]^2\le m\cdot\frac{d}{2}\cdot\mathbb{E}[\xi]+m(m-1)\mathbb{E}[\xi]^2. E [ S ] = m E [ ξ ] , E [ S 2 ] = m E [ ξ 2 ] + m ( m − 1 ) E [ ξ ] 2 ≤ m ⋅ 2 d ⋅ E [ ξ ] + m ( m − 1 ) E [ ξ ] 2 .
Using the Paley-Zygmund inequality, we have:
P ( S ≥ 1 2 E [ S ] ) ≥ E [ S ] 2 4 E [ S 2 ] ≥ m 2 E [ ξ ] 2 4 m d 2 E [ ξ ] + 4 m ( m − 1 ) E [ ξ ] 2 = m E [ ξ ] 2 d + 4 ( m − 1 ) E [ ξ ] ≥ m 2 d + 4 ( m − 1 ) ≥ m 2 ⋅ d m + 4 ≥ 1 8 . \mathbb{P}\left(S\ge\frac{1}{2}\mathbb{E}[S]\right)\ge\frac{\mathbb{E}[S]^2}{4\mathbb{E}[S^2]}\ge\frac{m^2\mathbb{E}[\xi]^2}{4m\frac{d}{2}\mathbb{E}[\xi]+4m(m-1)\mathbb{E}[\xi]^2}=\frac{m\mathbb{E}[\xi]}{2d+4(m-1)\mathbb{E}[\xi]}\ge\frac{m}{2d+4(m-1)}\ge\frac{m}{2\cdot\frac{d}{m}+4}\ge\frac{1}{8}. P ( S ≥ 2 1 E [ S ] ) ≥ 4 E [ S 2 ] E [ S ] 2 ≥ 4 m 2 d E [ ξ ] + 4 m ( m − 1 ) E [ ξ ] 2 m 2 E [ ξ ] 2 = 2 d + 4 ( m − 1 ) E [ ξ ] m E [ ξ ] ≥ 2 d + 4 ( m − 1 ) m ≥ 2 ⋅ m d + 4 m ≥ 8 1 .
Since E [ S ] ≥ m \mathbb{E}[S]\ge m E [ S ] ≥ m , we have P ( S ≥ m 2 ) ≥ 1 8 \mathbb{P}\left(S\ge\frac{m}{2}\right)\ge\frac{1}{8} P ( S ≥ 2 m ) ≥ 8 1 . Under which case we have γ s ( z ′ ) ≤ a s a s + m 2 ≤ 4 d + 4 < 4 d \gamma_s(z')\le\frac{a_s}{a_s+\frac{m}{2}}\le\frac{4}{d+4}<\frac{4}{d} γ s ( z ′ ) ≤ a s + 2 m a s ≤ d + 4 4 < d 4 .
For each m ≥ d m\ge d m ≥ d , let G m : = { z ∈ ( Σ ∖ { s } ) m : γ s ( z ′ ) < 4 d for every z ′ ∈ Z ( z ) } G_m:=\{z\in(\Sigma\setminus\{s\})^m:\gamma_s(z')<\frac{4}{d}\text{ for every }z'\in Z(z)\} G m := { z ∈ ( Σ ∖ { s } ) m : γ s ( z ′ ) < d 4 for every z ′ ∈ Z ( z )} .
Conditional on ∣ z ∣ = m |z|=m ∣ z ∣ = m and χ s ( z ) = − 1 \chi_s(z)=-1 χ s ( z ) = − 1 , the symbols of z z z are i.i.d. uniform on Σ ∖ { s } \Sigma\setminus\{s\} Σ ∖ { s } . The two cases before show that P ( z ∈ G m ∣ ∣ z ∣ = m , y = − 1 ) ≥ 1 8 \mathbb{P}(z\in G_m\mid|z|=m,y=-1)\ge\frac{1}{8} P ( z ∈ G m ∣ ∣ z ∣ = m , y = − 1 ) ≥ 8 1 . Fix any final output vector β \beta β with β s ≤ d / 4 \beta_s\le d/4 β s ≤ d /4 , and write G ( z ) : = ∑ i ≠ s β i γ i ( z ) G(z):=\sum_{i\ne s}\beta_i\gamma_i(z) G ( z ) := ∑ i = s β i γ i ( z ) . For every z ∈ G m z\in G_m z ∈ G m , either G ( z ) ≥ 1 / 2 G(z)\ge1/2 G ( z ) ≥ 1/2 , in which case ℓ ( z ) = 1 2 G ( z ) ≥ 1 8 \ell(z)=\frac{1}{2}G(z)\ge\frac{1}{8} ℓ ( z ) = 2 1 G ( z ) ≥ 8 1 , or G ( z ) < 1 / 2 G(z)<1/2 G ( z ) < 1/2 . In the latter case, for every z ′ ∈ Z ( z ) z'\in Z(z) z ′ ∈ Z ( z ) , we have f α ′ , β ( z ′ ) − 1 = G ( z ) ( 1 − γ s ( z ′ ) ) + β s γ s ( z ′ ) − 2 < 1 2 + 1 − 2 = − 1 2 f_{\alpha',\beta}(z')-1=G(z)(1-\gamma_s(z'))+\beta_s\gamma_s(z')-2<\frac{1}{2}+1-2=-\frac{1}{2} f α ′ , β ( z ′ ) − 1 = G ( z ) ( 1 − γ s ( z ′ )) + β s γ s ( z ′ ) − 2 < 2 1 + 1 − 2 = − 2 1 , so ℓ ( z ′ ) ≥ 1 / 8 \ell(z')\ge1/8 ℓ ( z ′ ) ≥ 1/8 .
Consequently, it follows that ρ ( z ) ℓ ( z ) + ∑ z ′ ∈ Z ( z ) ρ ( z ′ ) ℓ ( z ′ ) ≥ 1 8 min { ρ ( z ) , ρ ( Z ( z ) ) } ≥ 1 16 ρ ( z ) \rho(z)\ell(z)+\sum_{z'\in Z(z)}\rho(z')\ell(z')\ge\frac{1}{8}\min\{\rho(z),\rho(Z(z))\}\ge\frac{1}{16}\rho(z) ρ ( z ) ℓ ( z ) + ∑ z ′ ∈ Z ( z ) ρ ( z ′ ) ℓ ( z ′ ) ≥ 8 1 min { ρ ( z ) , ρ ( Z ( z ))} ≥ 16 1 ρ ( z ) . The sets { z } ∪ Z ( z ) \{z\}\cup Z(z) { z } ∪ Z ( z ) are disjoint across negative strings z z z . Hence, with G : = ⋃ m ≥ d G m G:=\bigcup_{m\ge d}G_m G := ⋃ m ≥ d G m , L s ( α ′ , β ) ≥ 1 16 ρ ( G ) ≥ 1 128 P ρ ( y ( w ) = − 1 , ∣ w ∣ ≥ d ) = 1 256 ( 1 − 2 d ) d − 1 ≥ 1 6912 \mathcal{L}_s(\alpha',\beta)\ge\frac{1}{16}\rho(G)\ge\frac{1}{128}\mathbb{P}_\rho(y(w)=-1,|w|\ge d)=\frac{1}{256}\left(1-\frac{2}{d}\right)^{d-1}\ge\frac{1}{6912} L s ( α ′ , β ) ≥ 16 1 ρ ( G ) ≥ 128 1 P ρ ( y ( w ) = − 1 , ∣ w ∣ ≥ d ) = 256 1 ( 1 − d 2 ) d − 1 ≥ 6912 1 .
For the last inequality, when d ≥ 9 d\ge9 d ≥ 9 , ( d − 1 ) ln ( 1 − 2 d ) ≥ − 2 ( d − 1 ) d − 2 ≥ − 16 7 > − 3 (d-1)\ln\left(1-\frac{2}{d}\right)\ge-\frac{2(d-1)}{d-2}\ge-\frac{16}{7}>-3 ( d − 1 ) ln ( 1 − d 2 ) ≥ − d − 2 2 ( d − 1 ) ≥ − 7 16 > − 3 , and e − 3 > 1 / 27 e^{-3}>1/27 e − 3 > 1/27 . Combining this bound with the earlier case β s > d / 4 \beta_s>d/4 β s > d /4 , which gives L s ( α ′ , β ) ≥ 1 / 2080 \mathcal{L}_s(\alpha',\beta)\ge1/2080 L s ( α ′ , β ) ≥ 1/2080 , proves the theorem with c 3 = 1 / 6912 c_3=1/6912 c 3 = 1/6912 .
Proof of Theorem 2
Proof. Throughout this proof, β ′ \beta' β ′ denotes the output weights after Phase 1, α ′ \alpha' α ′ the attention weights after Phase 2, and β ( t ) \beta^{(t)} β ( t ) the output weights after t ≥ 0 t\ge0 t ≥ 0 steps of Phase 3, so that β ( 0 ) = β ′ \beta^{(0)}=\beta' β ( 0 ) = β ′ and β ′ ′ = β ( T ) \beta''=\beta^{(T)} β ′′ = β ( T ) . We first prove the following lemma.
Lemma 2 (Induction on Symmetry). For any target index s ∈ [ d ] s\in[d] s ∈ [ d ] , if at the current step we have β i = β j \beta_i=\beta_j β i = β j and α i = α j \alpha_i=\alpha_j α i = α j for every pair of background indices i , j ≠ s i,j\ne s i , j = s , then after one step of population GD, the updated parameters satisfy α i ′ = α j ′ \alpha'_i=\alpha'_j α i ′ = α j ′ , and β i ′ = β j ′ \beta'_i=\beta'_j β i ′ = β j ′ .
Proof. For any fixed target index s s s , let τ i , j : = ( i j ) ∈ Sym ( [ d ] ) \tau_{i,j}:=(i\ j)\in\operatorname{Sym}([d]) τ i , j := ( i j ) ∈ Sym ([ d ]) denote the transposition swapping i , j ≠ s i,j\ne s i , j = s while keeping other indices fixed. For any string w = ( x 1 , x 2 ⋯ x m ) ∈ Σ m w=(x_1,x_2\cdots x_m)\in\Sigma^m w = ( x 1 , x 2 ⋯ x m ) ∈ Σ m , we write τ i , j ( w ) = τ i , j ( x 1 ) τ i , j ( x 2 ) ⋯ τ i , j ( x m ) \tau_{i,j}(w)=\tau_{i,j}(x_1)\tau_{i,j}(x_2)\cdots\tau_{i,j}(x_m) τ i , j ( w ) = τ i , j ( x 1 ) τ i , j ( x 2 ) ⋯ τ i , j ( x m ) . It follows that ρ ( w ) = ρ ( τ i , j ( w ) ) \rho(w)=\rho(\tau_{i,j}(w)) ρ ( w ) = ρ ( τ i , j ( w )) for every w ∈ Σ + w\in\Sigma^+ w ∈ Σ + . Moreover, since i , j ≠ s i,j\ne s i , j = s , swapping v i v_i v i and v j v_j v j will not change the acceptance of the string, i.e., y ( w ) = y ( τ i , j ( w ) ) y(w)=y(\tau_{i,j}(w)) y ( w ) = y ( τ i , j ( w )) .
Next, define the corresponding action on parameters: for ( α , β ) ∈ R d × R d (\alpha,\beta)\in\mathbb{R}^d\times\mathbb{R}^d ( α , β ) ∈ R d × R d , let τ i , j ( α , β ) \tau_{i,j}(\alpha,\beta) τ i , j ( α , β ) denote the parameter vector obtained by swapping α i \alpha_i α i with α j \alpha_j α j and β i \beta_i β i with β j \beta_j β j , leaving all other coordinates fixed. It follows that f α , β ( w ) = f τ i , j ( α , β ) ( τ i , j ( w ) ) f_{\alpha,\beta}(w)=f_{\tau_{i,j}(\alpha,\beta)}(\tau_{i,j}(w)) f α , β ( w ) = f τ i , j ( α , β ) ( τ i , j ( w )) for every w ∈ Σ + w\in\Sigma^+ w ∈ Σ + .
Combining these three facts, the population loss is invariant under this joint relabeling:
L ( α , β ) = E w ∼ ρ [ ( f α , β ( w ) − y ( w ) ) 2 ] = E w ∼ ρ [ ( f τ i , j ( α , β ) ( τ i , j ( w ) ) − y ( τ i , j ( w ) ) ) 2 ] = E w ′ ∼ ρ [ ( f τ i , j ( α , β ) ( w ′ ) − y ( w ′ ) ) 2 ] = L ( τ i , j ( α , β ) ) . \begin{aligned}
\mathcal{L}(\alpha,\beta)=\mathbb{E}_{w\sim\rho}\left[(f_{\alpha,\beta}(w)-y(w))^2\right]=\mathbb{E}_{w\sim\rho}\left[\left(f_{\tau_{i,j}(\alpha,\beta)}(\tau_{i,j}(w))-y(\tau_{i,j}(w))\right)^2\right] \\
&=\mathbb{E}_{w'\sim\rho}\left[\left(f_{\tau_{i,j}(\alpha,\beta)}(w')-y(w')\right)^2\right]=\mathcal{L}(\tau_{i,j}(\alpha,\beta)).
\end{aligned} L ( α , β ) = E w ∼ ρ [ ( f α , β ( w ) − y ( w ) ) 2 ] = E w ∼ ρ [ ( f τ i , j ( α , β ) ( τ i , j ( w )) − y ( τ i , j ( w )) ) 2 ] = E w ′ ∼ ρ [ ( f τ i , j ( α , β ) ( w ′ ) − y ( w ′ ) ) 2 ] = L ( τ i , j ( α , β )) .
e n d s m i d = 1 {ends_mid=1} e n d s m i d = 1
Therefore, for every pair of weights ( α , β ) (\alpha,\beta) ( α , β ) , it holds that
∂ L ∂ α i ( τ i , j ( α , β ) ) = ∂ L ∂ α j ( α , β ) , ∂ L ∂ β i ( τ i , j ( α , β ) ) = ∂ L ∂ β j ( α , β ) . \frac{\partial\mathcal{L}}{\partial\alpha_i}(\tau_{i,j}(\alpha,\beta))=\frac{\partial\mathcal{L}}{\partial\alpha_j}(\alpha,\beta),\qquad\frac{\partial\mathcal{L}}{\partial\beta_i}(\tau_{i,j}(\alpha,\beta))=\frac{\partial\mathcal{L}}{\partial\beta_j}(\alpha,\beta). ∂ α i ∂ L ( τ i , j ( α , β )) = ∂ α j ∂ L ( α , β ) , ∂ β i ∂ L ( τ i , j ( α , β )) = ∂ β j ∂ L ( α , β ) .
Since the current parameters satisfy α i = α j \alpha_i=\alpha_j α i = α j and β i = β j \beta_i=\beta_j β i = β j , then τ i , j ( α , β ) = ( α , β ) \tau_{i,j}(\alpha,\beta)=(\alpha,\beta) τ i , j ( α , β ) = ( α , β ) , and the identities above rewrites as
∂ L ∂ α i ( α , β ) = ∂ L ∂ α j ( α , β ) , ∂ L ∂ β i ( α , β ) = ∂ L ∂ β j ( α , β ) . \frac{\partial\mathcal{L}}{\partial\alpha_i}(\alpha,\beta)=\frac{\partial\mathcal{L}}{\partial\alpha_j}(\alpha,\beta),\qquad\frac{\partial\mathcal{L}}{\partial\beta_i}(\alpha,\beta)=\frac{\partial\mathcal{L}}{\partial\beta_j}(\alpha,\beta). ∂ α i ∂ L ( α , β ) = ∂ α j ∂ L ( α , β ) , ∂ β i ∂ L ( α , β ) = ∂ β j ∂ L ( α , β ) .
Plugging these equalities into the GD update rule we have α i ′ = α i − η ∂ L ∂ α i = α j − η ∂ L ∂ α j = α j ′ \alpha_i'=\alpha_i-\eta\frac{\partial\mathcal{L}}{\partial\alpha_i}=\alpha_j-\eta\frac{\partial\mathcal{L}}{\partial\alpha_j}=\alpha_j' α i ′ = α i − η ∂ α i ∂ L = α j − η ∂ α j ∂ L = α j ′ . Same equality holds for β \beta β as well.
With this lemma, and the symmetrical initialisation for α \alpha α and β \beta β , the parameter can be reduced to 4 scalars, α s \alpha_s α s and β s \beta_s β s for the target, and α j \alpha_j α j , β j \beta_j β j as the common weight for the background indices. We also shorthand γ i ( w ) \gamma_i(w) γ i ( w ) as the aggregated softmax-attention score for symbol v i v_i v i , note that sample-wise there is no symmetry for γ i \gamma_i γ i when i ≠ s i\ne s i = s , but on expectation level we have E [ γ j ] \mathbb{E}[\gamma_j] E [ γ j ] which is shared by all background indices j ≠ s j\ne s j = s . We also shorthand Δ β = β s − β j \Delta\beta=\beta_s-\beta_j Δ β = β s − β j and β ˉ = 1 d − 1 ∑ i ≠ s β i \bar{\beta}=\frac{1}{d-1}\sum_{i\ne s}\beta_i β ˉ = d − 1 1 ∑ i = s β i .
First Phase In the first step, we calculate the gradient for β s \beta_s β s and β j \beta_j β j in closed forms:
∂ L ∂ β s = E [ ( y ^ ( w ) − y ( w ) ) γ s ] = ( a ) E [ ( − 1 − y ( w ) ) γ s ] = P ( y = 1 ) ⋅ − 2 ⋅ E [ γ s ∣ y = 1 ] = − 2 d . \frac{\partial\mathcal{L}}{\partial\beta_s}=\mathbb{E}[(\hat{y}(w)-y(w))\gamma_s]\overset{(a)}{=}\mathbb{E}[(-1-y(w))\gamma_s]=\mathbb{P}(y=1)\cdot-2\cdot\mathbb{E}[\gamma_s\mid y=1]=-\frac{2}{d}. ∂ β s ∂ L = E [( y ^ ( w ) − y ( w )) γ s ] = ( a ) E [( − 1 − y ( w )) γ s ] = P ( y = 1 ) ⋅ − 2 ⋅ E [ γ s ∣ y = 1 ] = − d 2 .
∂ L ∂ β j = E [ ( y ^ ( w ) − y ( w ) ) γ j ] = E [ ( − 1 − y ( w ) ) γ j ] = P ( y = 1 ) ⋅ − 2 ⋅ E [ γ j ∣ y = 1 ] = 1 d − 1 ⋅ ( 2 d − 1 ) . \frac{\partial\mathcal{L}}{\partial\beta_j}=\mathbb{E}[(\hat{y}(w)-y(w))\gamma_j]=\mathbb{E}[(-1-y(w))\gamma_j]=\mathbb{P}(y=1)\cdot-2\cdot\mathbb{E}[\gamma_j\mid y=1]=\frac{1}{d-1}\cdot\left(\frac{2}{d}-1\right). ∂ β j ∂ L = E [( y ^ ( w ) − y ( w )) γ j ] = E [( − 1 − y ( w )) γ j ] = P ( y = 1 ) ⋅ − 2 ⋅ E [ γ j ∣ y = 1 ] = d − 1 1 ⋅ ( d 2 − 1 ) .
Hence, the updated parameter is β s ′ = 2 η 1 d \beta_s'=\frac{2\eta_1}{d} β s ′ = d 2 η 1 , β j ′ = η 1 d − 1 ⋅ ( 1 − 2 d ) \beta_j'=\frac{\eta_1}{d-1}\cdot\left(1-\frac{2}{d}\right) β j ′ = d − 1 η 1 ⋅ ( 1 − d 2 ) for every j ≠ s j\ne s j = s . The separation of target and the background output weights grows from Δ β = 0 \Delta\beta=0 Δ β = 0 to Δ β ′ = η 1 d − 1 \Delta\beta'=\frac{\eta_1}{d-1} Δ β ′ = d − 1 η 1 . We choose the learning rate of the first phase to be 0 < η 1 < d − 1 2 0<\eta_1<\frac{d-1}{2} 0 < η 1 < 2 d − 1 and therefore the separation will be controlled within a constant range 0 < Δ β ′ < 1 2 0<\Delta\beta'<\frac{1}{2} 0 < Δ β ′ < 2 1 .
Second Phase In the second phase, we calculate the gradient for α s \alpha_s α s and α j \alpha_j α j in closed forms:
∂ L ∂ α s = Δ β ′ ⋅ E [ ( y ^ ( w ) − y ( w ) ) ⋅ γ s ( 1 − γ s ) ] \frac{\partial\mathcal{L}}{\partial\alpha_s}=\Delta\beta'\cdot\mathbb{E}[(\hat{y}(w)-y(w))\cdot\gamma_s(1-\gamma_s)] ∂ α s ∂ L = Δ β ′ ⋅ E [( y ^ ( w ) − y ( w )) ⋅ γ s ( 1 − γ s )]
∂ L ∂ α j = − 1 d − 1 ⋅ ∂ L ∂ α s \frac{\partial\mathcal{L}}{\partial\alpha_j}=-\frac{1}{d-1}\cdot\frac{\partial\mathcal{L}}{\partial\alpha_s} ∂ α j ∂ L = − d − 1 1 ⋅ ∂ α s ∂ L
Consider 0 < η 1 < d − 1 2 0<\eta_1<\frac{d-1}{2} 0 < η 1 < 2 d − 1 , we have β i ′ < 1 \beta_i'<1 β i ′ < 1 for every i ∈ [ d ] i\in[d] i ∈ [ d ] , therefore for positive words y ^ ( w ) = ∑ i = 1 d γ i β i ′ − 1 < 0 \hat{y}(w)=\sum_{i=1}^{d}\gamma_i\beta_i'-1<0 y ^ ( w ) = ∑ i = 1 d γ i β i ′ − 1 < 0 and y ^ − y < − 1 \hat{y}-y<-1 y ^ − y < − 1 , hence we get an upper bound for the target gradient (which holds for negative words too since γ s = 0 \gamma_s=0 γ s = 0 ):
∂ L ∂ α s ≤ − Δ β ′ E [ γ s ( 1 − γ s ) ] \frac{\partial\mathcal{L}}{\partial\alpha_s}\le-\Delta\beta'\mathbb{E}[\gamma_s(1-\gamma_s)] ∂ α s ∂ L ≤ − Δ β ′ E [ γ s ( 1 − γ s )]
At uniform attention, the moments in (3) and (4) give d E [ γ s ( 1 − γ s ) ] = d − 1 d ( 1 − ln ( d − 1 ) d − 2 ) ≥ 2 3 ( 1 − ln 2 ) > 1 20 d\mathbb{E}[\gamma_s(1-\gamma_s)]=\frac{d-1}{d}\left(1-\frac{\ln(d-1)}{d-2}\right)\ge\frac{2}{3}(1-\ln2)>\frac{1}{20} d E [ γ s ( 1 − γ s )] = d d − 1 ( 1 − d − 2 l n ( d − 1 ) ) ≥ 3 2 ( 1 − ln 2 ) > 20 1 for every d ≥ 3 d\ge3 d ≥ 3 . Hence we have ∂ L ∂ α s ≤ − η 1 20 d ( d − 1 ) \frac{\partial\mathcal{L}}{\partial\alpha_s}\le-\frac{\eta_1}{20d(d-1)} ∂ α s ∂ L ≤ − 20 d ( d − 1 ) η 1 and ∂ L ∂ α j ≥ η 1 20 d ( d − 1 ) 2 \frac{\partial\mathcal{L}}{\partial\alpha_j}\ge\frac{\eta_1}{20d(d-1)^2} ∂ α j ∂ L ≥ 20 d ( d − 1 ) 2 η 1 . Combining both bounds, the attention gap after the second step satisfies
Δ α ′ : = α s ′ − α j ′ = − d d − 1 η 2 ∂ L ∂ α s ≥ η 1 η 2 20 ( d − 1 ) 2 ≥ ln 8 d ε . \Delta\alpha':=\alpha_s'-\alpha_j'=-\frac{d}{d-1}\eta_2\frac{\partial\mathcal{L}}{\partial\alpha_s}\ge\frac{\eta_1\eta_2}{20(d-1)^2}\ge\ln\frac{8d}{\varepsilon}. Δ α ′ := α s ′ − α j ′ = − d − 1 d η 2 ∂ α s ∂ L ≥ 20 ( d − 1 ) 2 η 1 η 2 ≥ ln ε 8 d .
For a positive string w w w with ∣ w ∣ = m |w|=m ∣ w ∣ = m and C s ( w ) = n ≥ 1 C_s(w)=n\ge1 C s ( w ) = n ≥ 1 ,
1 − γ s ′ ( w ) = m − n n exp ( Δ α ′ ) + m − n ≤ ( m − 1 ) exp ( − Δ α ′ ) . 1-\gamma_s'(w)=\frac{m-n}{n\exp(\Delta\alpha')+m-n}\le(m-1)\exp(-\Delta\alpha'). 1 − γ s ′ ( w ) = n exp ( Δ α ′ ) + m − n m − n ≤ ( m − 1 ) exp ( − Δ α ′ ) .
Since E [ m − 1 ∣ y = 1 ] ≤ 2 E [ m − 1 ] = 2 ( d − 2 ) \mathbb{E}[m-1\mid y=1]\le2\mathbb{E}[m-1]=2(d-2) E [ m − 1 ∣ y = 1 ] ≤ 2 E [ m − 1 ] = 2 ( d − 2 ) , we obtain
E [ 1 − γ s ′ ∣ y = 1 ] ≤ δ : = 2 d exp ( − Δ α ′ ) ≤ ε 4 . \mathbb{E}[1-\gamma_s'\mid y=1]\le\delta:=2d\exp(-\Delta\alpha')\le\frac{\varepsilon}{4}. E [ 1 − γ s ′ ∣ y = 1 ] ≤ δ := 2 d exp ( − Δ α ′ ) ≤ 4 ε .
Third Phase During the third step, the attention is fixed at α ′ \alpha' α ′ , so L ( α ′ , β ) \mathcal{L}(\alpha',\beta) L ( α ′ , β ) is a convex quadratic function w.r.t. β \beta β with Hessian H = E [ γ ′ γ ′ ⊤ ] H=\mathbb{E}[\gamma'\gamma'^{\top}] H = E [ γ ′ γ ′ ⊤ ] . Let μ k ′ : = E [ ( γ s ′ ) k ∣ y = 1 ] \mu_k':=\mathbb{E}[(\gamma_s')^k\mid y=1] μ k ′ := E [( γ s ′ ) k ∣ y = 1 ] for k = 1 , 2 , 3 k=1,2,3 k = 1 , 2 , 3 , so that 1 − δ ≤ μ 1 ′ 1-\delta\le\mu_1' 1 − δ ≤ μ 1 ′ and ( μ 1 ′ ) 2 ≤ μ 2 ′ ≤ 1 (\mu_1')^2\le\mu_2'\le1 ( μ 1 ′ ) 2 ≤ μ 2 ′ ≤ 1 . Let S : = span { e s , 1 − s } S:=\operatorname{span}\{e_s,1_{-s}\} S := span { e s , 1 − s } and u : = 1 − s / d − 1 u:=1_{-s}/\sqrt{d-1} u := 1 − s / d − 1 . On S S S , the risk is minimized at β ⋆ \beta^\star β ⋆ with:
β s ⋆ = 2 μ 1 ′ + 2 μ 2 ′ − 2 ( μ 1 ′ ) 2 2 μ 2 ′ − ( μ 1 ′ ) 2 , β j ⋆ = 2 μ 2 ′ − 2 ( μ 1 ′ ) 2 2 μ 2 ′ − ( μ 1 ′ ) 2 . \beta_s^\star= \frac{2\mu_1' + 2\mu_2' - 2(\mu_1')^2}{2\mu_2' - (\mu_1')^2}, \qquad\beta_j^\star= \frac{2\mu_2' - 2(\mu_1')^2}{2\mu_2' - (\mu_1')^2}. β s ⋆ = 2 μ 2 ′ − ( μ 1 ′ ) 2 2 μ 1 ′ + 2 μ 2 ′ − 2 ( μ 1 ′ ) 2 , β j ⋆ = 2 μ 2 ′ − ( μ 1 ′ ) 2 2 μ 2 ′ − 2 ( μ 1 ′ ) 2 .
And the expected risk at this point will be:
L ( α ′ , β ⋆ ) = 1 2 ⋅ E [ 1 2 ( β s ⋆ γ s ′ + ∑ j ≠ s β j ⋆ γ j ′ − 1 − 1 ) 2 | y = 1 ] + 1 2 ⋅ E [ 1 2 ( ∑ j ≠ s β j ⋆ γ j ′ − 1 + 1 ) 2 | y = − 1 ] = 1 4 ⋅ ( E [ ( Δ β ⋆ γ s ′ + β j ⋆ − 2 ) 2 | y = 1 ] + ( β j ⋆ ) 2 ) = 1 4 ( ( Δ β ⋆ ) 2 μ 2 ′ + 1 2 Δ β ⋆ ( β j ⋆ − 2 ) μ 1 ′ + 1 4 ( β j ⋆ − 2 ) 2 + 1 4 ( β j ⋆ ) 2 ) = ( μ 1 ′ − ( μ 1 ′ ) 2 ) 2 2 μ 2 ′ − ( μ 1 ′ ) 2 < 2 δ \begin{aligned}
\mathcal{L}(\alpha',\beta^\star) = \frac{1}{2}\cdot\mathbb{E}\left[\frac{1}{2}\left(\beta_s^\star\gamma_s' + \sum_{j\ne s}\beta_j^\star\gamma_j' - 1 - 1\right)^2 \,\middle|\, y=1\right] + \frac{1}{2}\cdot\mathbb{E}\left[\frac{1}{2}\left(\sum_{j\ne s}\beta_j^\star\gamma_j' - 1 + 1\right)^2 \,\middle|\, y=-1\right] \\
&= \frac{1}{4}\cdot\left(\mathbb{E}\left[\left(\Delta\beta^\star\gamma_s' + \beta_j^\star- 2\right)^2 \,\middle|\, y=1\right] + (\beta_j^\star)^2\right) \\
&= \frac{1}{4}\left((\Delta\beta^\star)^2\mu_2' + \frac{1}{2}\Delta\beta^\star(\beta_j^\star-2)\mu_1' + \frac{1}{4}(\beta_j^\star-2)^2 + \frac{1}{4}(\beta_j^\star)^2\right) = \frac{(\mu_1' - (\mu_1')^2)^2}{2\mu_2' - (\mu_1')^2} < 2\delta
\end{aligned} L ( α ′ , β ⋆ ) = 2 1 ⋅ E 2 1 β s ⋆ γ s ′ + j = s ∑ β j ⋆ γ j ′ − 1 − 1 2 y = 1 + 2 1 ⋅ E 2 1 j = s ∑ β j ⋆ γ j ′ − 1 + 1 2 y = − 1 = 4 1 ⋅ ( E [ ( Δ β ⋆ γ s ′ + β j ⋆ − 2 ) 2 y = 1 ] + ( β j ⋆ ) 2 ) = 4 1 ( ( Δ β ⋆ ) 2 μ 2 ′ + 2 1 Δ β ⋆ ( β j ⋆ − 2 ) μ 1 ′ + 4 1 ( β j ⋆ − 2 ) 2 + 4 1 ( β j ⋆ ) 2 ) = 2 μ 2 ′ − ( μ 1 ′ ) 2 ( μ 1 ′ − ( μ 1 ′ ) 2 ) 2 < 2 δ
Moreover, we have β j ⋆ = 2 L ( α ′ , β ⋆ ) ∈ [ 0 , 4 δ ] \beta_j^\star= 2\mathcal{L}(\alpha',\beta^\star)\in[0,4\delta] β j ⋆ = 2 L ( α ′ , β ⋆ ) ∈ [ 0 , 4 δ ] and 0 ≤ β s ⋆ ≤ 4 δ + 2 ( μ 1 ′ ) 2 < 4 0\leq\beta_s^\star\leq4\delta+\frac{2}{(\mu_1')^2}<4 0 ≤ β s ⋆ ≤ 4 δ + ( μ 1 ′ ) 2 2 < 4 .
At any step in the third phase, the symmetry is preserved for the α ′ \alpha' α ′ , β \beta β , and the E [ γ ′ ] \mathbb{E}[\gamma'] E [ γ ′ ] among all indices j ≠ s j\ne s j = s , as a result of Lemma 2. Since β ⋆ \beta^\star β ⋆ minimizes the risk over S S S , its gradient is orthogonal to S S S and hence zero. Therefore, for every β ∈ R d \beta\in\mathbb{R}^d β ∈ R d ,
L ( α ′ , β ) − L ( α ′ , β ⋆ ) = 1 2 ( β − β ⋆ ) ⊤ H ( β − β ⋆ ) . \mathcal{L}(\alpha',\beta)-\mathcal{L}(\alpha',\beta^\star)=\frac{1}{2}(\beta-\beta^\star)^\top H(\beta-\beta^\star). L ( α ′ , β ) − L ( α ′ , β ⋆ ) = 2 1 ( β − β ⋆ ) ⊤ H ( β − β ⋆ ) .
and the GD iterates with η 3 = 1 \eta_3=1 η 3 = 1 satisfy β ( t + 1 ) − β ⋆ = ( I − H ) ( β ( t ) − β ⋆ ) \beta(t+1)-\beta^\star=(I-H)(\beta(t)-\beta^\star) β ( t + 1 ) − β ⋆ = ( I − H ) ( β ( t ) − β ⋆ ) . By Lemma 2, all iterates lie in S S S , so only the restriction H ~ \widetilde{H} H of H H H to S S S matters. Take an orthonormal basis ( e s , 1 − s d − 1 , ξ 1 , … , ξ d − 2 ) (e_s,\frac{\mathbf{1}_{-s}}{\sqrt{d-1}},\xi_1,\ldots,\xi_{d-2}) ( e s , d − 1 1 − s , ξ 1 , … , ξ d − 2 ) of R d \mathbb{R}^d R d , where ξ 1 , … , ξ d − 2 \xi_1,\ldots,\xi_{d-2} ξ 1 , … , ξ d − 2 span the subspace { e s , 1 − s } ⊥ \{e_s,\mathbf{1}_{-s}\}^{\perp} { e s , 1 − s } ⊥ . We can then block-diagonalize H H H in this basis as H = H ~ ⊕ a I d − 2 H=\widetilde{H}\oplus aI_{d-2} H = H ⊕ a I d − 2 with a = Θ ( ln d d 2 ) a=\Theta\left(\frac{\ln d}{d^2}\right) a = Θ ( d 2 l n d ) , where H ~ ∈ R 2 × 2 \widetilde{H}\in\mathbb{R}^{2\times2} H ∈ R 2 × 2 acts on span { e s , 1 − s } \operatorname{span}\{e_s,\mathbf{1}_{-s}\} span { e s , 1 − s } . Each component of H ~ \widetilde{H} H has closed forms:
H ~ 11 = E [ ( γ s ′ ) 2 ] = 1 2 μ 2 ′ ∈ [ 1 2 ( 1 − δ ) 2 , 1 2 ] , \widetilde{H}_{11}=\mathbb{E}[(\gamma_s')^2]=\frac{1}{2}\mu_2'\in\left[\frac{1}{2}(1-\delta)^2,\frac{1}{2}\right], H 11 = E [( γ s ′ ) 2 ] = 2 1 μ 2 ′ ∈ [ 2 1 ( 1 − δ ) 2 , 2 1 ] ,
H ~ 22 = E [ ( 1 − γ s ′ ) 2 ] d − 1 ∈ [ 1 2 ( d − 1 ) , 1 + δ 2 ( d − 1 ) ] , \widetilde{H}_{22}=\frac{\mathbb{E}[(1-\gamma_s')^2]}{d-1}\in\left[\frac{1}{2(d-1)},\frac{1+\delta}{2(d-1)}\right], H 22 = d − 1 E [( 1 − γ s ′ ) 2 ] ∈ [ 2 ( d − 1 ) 1 , 2 ( d − 1 ) 1 + δ ] ,
H ~ 12 = H ~ 21 = E [ γ s ′ ( 1 − γ s ′ ) ] d − 1 ∈ [ 0 , δ 2 d − 1 ] . \widetilde{H}_{12}=\widetilde{H}_{21}=\frac{\mathbb{E}[\gamma_s'(1-\gamma_s')]}{\sqrt{d-1}}\in\left[0,\frac{\delta}{2\sqrt{d-1}}\right]. H 12 = H 21 = d − 1 E [ γ s ′ ( 1 − γ s ′ )] ∈ [ 0 , 2 d − 1 δ ] .
where we used that E [ 1 − γ s ′ ∣ y = − 1 ] = 1 \mathbb{E}[1-\gamma_s'\mid y=-1]=1 E [ 1 − γ s ′ ∣ y = − 1 ] = 1 and E [ 1 − γ s ′ ∣ y = 1 ] ≤ δ \mathbb{E}[1-\gamma_s'\mid y=1]\leq\delta E [ 1 − γ s ′ ∣ y = 1 ] ≤ δ . Hence tr ( H ~ ) ≤ 1 2 + 1 + δ 4 ≤ 1 \operatorname{tr}(\widetilde{H})\leq\frac{1}{2}+\frac{1+\delta}{4}\leq1 tr ( H ) ≤ 2 1 + 4 1 + δ ≤ 1 for d ≥ 3 d\geq3 d ≥ 3 , and
det ( H ~ ) ≥ ( 1 − δ ) 2 − δ 2 4 ( d − 1 ) = 1 − 2 δ 4 ( d − 1 ) , λ min ( H ~ ) ≥ det ( H ~ ) tr ( H ~ ) ≥ 1 8 d , \det(\widetilde{H})\geq\frac{(1-\delta)^2-\delta^2}{4(d-1)}=\frac{1-2\delta}{4(d-1)},\qquad\lambda_{\min}(\widetilde{H})\geq\frac{\det(\widetilde{H})}{\operatorname{tr}(\widetilde{H})}\geq\frac{1}{8d}, det ( H ) ≥ 4 ( d − 1 ) ( 1 − δ ) 2 − δ 2 = 4 ( d − 1 ) 1 − 2 δ , λ m i n ( H ) ≥ tr ( H ) det ( H ) ≥ 8 d 1 ,
using δ ≤ 1 4 \delta\leq\frac{1}{4} δ ≤ 4 1 . Since also λ max ( H ~ ) ≤ 1 \lambda_{\max}(\widetilde{H})\leq1 λ m a x ( H ) ≤ 1 , each step contracts the error by a factor of at most 1 − 1 8 d 1-\frac{1}{8d} 1 − 8 d 1 .
At the beginning of Phase 3, output starts from β ′ \beta' β ′ , with β s ′ ∈ ( 0 , 1 ) \beta_s'\in(0,1) β s ′ ∈ ( 0 , 1 ) and β j ′ ∈ ( 0 , 1 2 ) \beta_j'\in(0,\frac{1}{2}) β j ′ ∈ ( 0 , 2 1 ) , so ∥ β ′ − β ⋆ ∥ 2 ≤ ∥ β ⋆ ∥ 2 + ∥ β ′ ∥ 2 ≤ 16 + ( d − 1 ) ≤ 16 d \|\beta'-\beta^\star\|^2\leq\|\beta^\star\|^2+\|\beta'\|^2\leq16+(d-1)\leq16d ∥ β ′ − β ⋆ ∥ 2 ≤ ∥ β ⋆ ∥ 2 + ∥ β ′ ∥ 2 ≤ 16 + ( d − 1 ) ≤ 16 d . Therefore L ( α ′ , β ( T ) ) − L ( α ′ , β ⋆ ) ≤ 1 2 ∥ β ( T ) − β ⋆ ∥ 2 ≤ 8 d ( 1 − 1 8 d ) 2 T ≤ 8 d exp ( − T 4 d ) ≤ ε 2 \mathcal{L}(\alpha',\beta(T))-\mathcal{L}(\alpha',\beta^\star)\leq\frac{1}{2}\|\beta(T)-\beta^\star\|^2\leq8d\left(1-\frac{1}{8d}\right)^{2T}\leq8d\exp\left(-\frac{T}{4d}\right)\leq\frac{\varepsilon}{2} L ( α ′ , β ( T )) − L ( α ′ , β ⋆ ) ≤ 2 1 ∥ β ( T ) − β ⋆ ∥ 2 ≤ 8 d ( 1 − 8 d 1 ) 2 T ≤ 8 d exp ( − 4 d T ) ≤ 2 ε when plugging in T ≥ 4 d ln 16 d ε T\geq4d\ln\frac{16d}{\varepsilon} T ≥ 4 d ln ε 16 d . After T T T steps we have β ′ ′ : = β ( T ) \beta'':=\beta(T) β ′′ := β ( T ) and hence L ( α ′ , β ′ ′ ) ≤ 2 δ + ε 2 ≤ ε \mathcal{L}(\alpha',\beta'')\leq2\delta+\frac{\varepsilon}{2}\leq\varepsilon L ( α ′ , β ′′ ) ≤ 2 δ + 2 ε ≤ ε .
Proof of Corollary 1
Proof. We use ( w ( k ) , y ( k ) ) k = 1 N 1 (w^{(k)},y^{(k)})_{k=1}^{N_1} ( w ( k ) , y ( k ) ) k = 1 N 1 denotes the first batch, and for any function g ( w ) g(w) g ( w ) of a sample we write g ^ : = 1 N 1 ∑ k = 1 N 1 g ( w ( k ) , y ( k ) ) \hat{g}:=\frac{1}{N_1}\sum_{k=1}^{N_1}g(w^{(k)},y^{(k)}) g ^ := N 1 1 ∑ k = 1 N 1 g ( w ( k ) , y ( k ) ) for its average over this batch. In Phases 1 and 2, α = 0 d \alpha=0_d α = 0 d , so γ i ( w ) = C i ( w ) ∣ w ∣ \gamma_i(w)=\frac{C_i(w)}{|w|} γ i ( w ) = ∣ w ∣ C i ( w ) .
With respect to the first draw of samples, we consider the following variables. For any sample ( w , y ) (w,y) ( w , y ) and i ∈ [ d ] i\in[d] i ∈ [ d ] , we define Z i : = 1 { y = 1 } γ i ( w ) Z_i:=\mathbf{1}\{y=1\}\gamma_i(w) Z i := 1 { y = 1 } γ i ( w ) , V : = γ s ( w ) ( 1 − γ s ( w ) ) V:=\gamma_s(w)(1-\gamma_s(w)) V := γ s ( w ) ( 1 − γ s ( w )) . 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 c > 0 c>0 c > 0 , there exists a constant C > 0 C>0 C > 0 such that, when N 1 ≥ C d ln d N_1 \ge Cd\ln d N 1 ≥ C d ln d , with probability at least 1 − d − c 1-d^{-c} 1 − d − c , the following event A A A holds:
∣ Z ^ i − E [ Z i ] ∣ ≤ 1 800 d \left|\widehat{Z}_i-\mathbb{E}[Z_i]\right|\le\frac{1}{800d} Z i − E [ Z i ] ≤ 800 d 1 for every i ∈ [ d ] i\in[d] i ∈ [ d ] ;
V ^ ≥ 1 2 E [ V ] \widehat{V}\ge\frac{1}{2}\mathbb{E}[V] V ≥ 2 1 E [ V ] ;
γ ^ j ≤ 2 d \widehat{\gamma}_j\le\frac{2}{d} γ j ≤ d 2 for every j ≠ s j\ne s j = s .
Proof. All of Z i Z_i Z i , V V V , γ j \gamma_j γ j take values in [ 0 , 1 ] [0,1] [ 0 , 1 ] . We can bound their second moments by:
E [ Z i 2 ] = 1 2 ⋅ E [ γ i 2 ∣ y = 1 ] = 1 ( d − 1 ) 2 + ln ( d − 1 ) ( d − 1 ) ( d − 2 ) ≤ 1 + ln ( d − 1 ) ( d − 1 ) 2 ; \mathbb{E}[Z_i^2]=\frac{1}{2}\cdot\mathbb{E}[\gamma_i^2\mid y=1]=\frac{1}{(d-1)^2}+\frac{\ln(d-1)}{(d-1)(d-2)}\le\frac{1+\ln(d-1)}{(d-1)^2}; E [ Z i 2 ] = 2 1 ⋅ E [ γ i 2 ∣ y = 1 ] = ( d − 1 ) 2 1 + ( d − 1 ) ( d − 2 ) ln ( d − 1 ) ≤ ( d − 1 ) 2 1 + ln ( d − 1 ) ;
E [ V 2 ] ≤ E [ γ s 2 ∣ y = 1 ] ≤ 2 + 2 ln d d 2 ; \mathbb{E}[V^2]\le\mathbb{E}[\gamma_s^2\mid y=1]\le\frac{2+2\ln d}{d^2}; E [ V 2 ] ≤ E [ γ s 2 ∣ y = 1 ] ≤ d 2 2 + 2 ln d ;
E [ γ j 2 ] = 1 d 2 + ( d − 1 ) ln ( d − 1 ) d 2 ( d − 2 ) ≤ 1 + 2 ln d d 2 . \mathbb{E}[\gamma_j^2]=\frac{1}{d^2}+\frac{(d-1)\ln(d-1)}{d^2(d-2)}\le\frac{1+2\ln d}{d^2}. E [ γ j 2 ] = d 2 1 + d 2 ( d − 2 ) ( d − 1 ) ln ( d − 1 ) ≤ d 2 1 + 2 ln d .
Hence, we can use σ 2 = 2 + 2 ln d ( d − 1 ) 2 ≤ 12 ln d d 2 \sigma^2=\frac{2+2\ln d}{(d-1)^2}\le\frac{12\ln d}{d^2} σ 2 = ( d − 1 ) 2 2 + 2 l n d ≤ d 2 12 l n d as a common upper bound for the three terms above. And we also have E [ V ] = E [ γ s ] − E [ γ s 2 ] = 1 d − 1 d 2 − ( d − 1 ) ln ( d − 1 ) d 2 ( d − 2 ) ≥ 1 5 d \mathbb{E}[V]=\mathbb{E}[\gamma_s]-\mathbb{E}[\gamma_s^2]=\frac{1}{d}-\frac{1}{d^2}-\frac{(d-1)\ln(d-1)}{d^2(d-2)}\ge\frac{1}{5d} E [ V ] = E [ γ s ] − E [ γ s 2 ] = d 1 − d 2 1 − d 2 ( d − 2 ) ( d − 1 ) l n ( d − 1 ) ≥ 5 d 1 for all d ≥ 3 d\ge3 d ≥ 3 . By Bernstein’s inequality, for each statement in the event A A A , the failure probability of the each term can be bounded by:
P ( ∣ Z ^ i − E [ Z i ] ∣ > 1 800 d ) < 2 exp ( − N 1 ( 1 800 d ) 2 2 ⋅ 12 ln d d 2 + 1 1200 d ) < 2 exp ( − N 1 C 0 ln d + C 1 d ) , \mathbb{P}\left(\left|\widehat{Z}_i-\mathbb{E}[Z_i]\right|>\frac{1}{800d}\right)<2\exp\left(-\frac{N_1\left(\frac{1}{800d}\right)^2}{2\cdot\frac{12\ln d}{d^2}+\frac{1}{1200d}}\right)<2\exp\left(-\frac{N_1}{C_0\ln d+C_1d}\right), P ( Z i − E [ Z i ] > 800 d 1 ) < 2 exp ( − 2 ⋅ d 2 12 l n d + 1200 d 1 N 1 ( 800 d 1 ) 2 ) < 2 exp ( − C 0 ln d + C 1 d N 1 ) ,
P ( E [ V ] − V ^ > 1 2 E [ V ] ) < exp ( − N 1 ( 1 10 d ) 2 2 ⋅ 12 ln d d 2 + 1 15 d ) < exp ( − N 1 C 0 ′ ln d + C 1 ′ d ) , \mathbb{P}\left(\mathbb{E}[V]-\widehat{V}>\frac{1}{2}\mathbb{E}[V]\right)<\exp\left(-\frac{N_1\left(\frac{1}{10d}\right)^2}{2\cdot\frac{12\ln d}{d^2}+\frac{1}{15d}}\right)<\exp\left(-\frac{N_1}{C'_0\ln d+C'_1d}\right), P ( E [ V ] − V > 2 1 E [ V ] ) < exp ( − 2 ⋅ d 2 12 l n d + 15 d 1 N 1 ( 10 d 1 ) 2 ) < exp ( − C 0 ′ ln d + C 1 ′ d N 1 ) ,
P ( γ ^ j − E [ γ j ] > 1 d ) < exp ( − N 1 ( 1 d ) 2 2 ⋅ 12 ln d d 2 + 2 3 d ) < exp ( − N 1 C 0 ′ ′ ln d + C 1 ′ ′ d ) . \mathbb{P}\left(\widehat{\gamma}_j-\mathbb{E}[\gamma_j]>\frac{1}{d}\right)<\exp\left(-\frac{N_1\left(\frac{1}{d}\right)^2}{2\cdot\frac{12\ln d}{d^2}+\frac{2}{3d}}\right)<\exp\left(-\frac{N_1}{C''_0\ln d+C''_1d}\right). P ( γ j − E [ γ j ] > d 1 ) < exp ( − 2 ⋅ d 2 12 l n d + 3 d 2 N 1 ( d 1 ) 2 ) < exp ( − C 0 ′′ ln d + C 1 ′′ d N 1 ) .
Taking the union bound of all the 2 d + 1 2d+1 2 d + 1 statements, choosing N 1 ≥ C d ln d N_1\ge Cd\ln d N 1 ≥ C d ln d with C C C large enough (depending on c c c ) makes the combined failure at most d − c 2 d + 1 \frac{d^{-c}}{2d+1} 2 d + 1 d − c .
First Phase
When α = β = 0 d \alpha=\beta=\mathbf{0}_d α = β = 0 d , the output is f ( w ) = − 1 f(w)=-1 f ( w ) = − 1 on every string, so ∂ L ^ ∂ β i = − 2 Z ^ i \frac{\partial\widehat{\mathcal{L}}}{\partial\beta_i}=-2\widehat{Z}_i ∂ β i ∂ L = − 2 Z i and the updated output weight becomes β ^ i ′ = 2 η 1 Z ^ i ≥ 0 \widehat{\beta}'_i=2\eta_1\widehat{Z}_i\ge0 β i ′ = 2 η 1 Z i ≥ 0 . By the moment of the attention scores specified in (5) , (6) , (7) , and P ( y = − 1 ) = 1 2 \mathbb{P}(y=-1)=\frac{1}{2} P ( y = − 1 ) = 2 1 , we have E [ Z s ] = 1 d \mathbb{E}[Z_s]=\frac{1}{d} E [ Z s ] = d 1 , E [ Z j ] = 1 d − 1 2 ( d − 1 ) = d − 2 2 d ( d − 1 ) \mathbb{E}[Z_j]=\frac{1}{d}-\frac{1}{2(d-1)}=\frac{d-2}{2d(d-1)} E [ Z j ] = d 1 − 2 ( d − 1 ) 1 = 2 d ( d − 1 ) d − 2 for every j ≠ s j\ne s j = s . With Lemma 3 and 0 < η 1 ≤ d 0<\eta_1\le\sqrt{d} 0 < η 1 ≤ d , we have:
β ^ s ′ ≤ η 1 ( 2 d + 1 400 d ) ≤ 2.01 d ≤ 5 4 (10) \widehat{\beta}'_s\le\eta_1\left(\frac{2}{d}+\frac{1}{400d}\right)\le\frac{2.01}{\sqrt{d}}\le\frac{5}{4} \tag*{(10)} β s ′ ≤ η 1 ( d 2 + 400 d 1 ) ≤ d 2.01 ≤ 4 5 (10)
β ^ s ′ − max i ≠ s β ^ i ′ ≥ η 1 ( 1 d − 1 − 1 200 d ) ≥ 199 200 η 1 d (11) \widehat{\beta}'_s-\max_{i\ne s}\widehat{\beta}'_i\ge\eta_1\left(\frac{1}{d-1}-\frac{1}{200d}\right)\ge\frac{199}{200}\frac{\eta_1}{d} \tag*{(11)} β s ′ − i = s max β i ′ ≥ η 1 ( d − 1 1 − 200 d 1 ) ≥ 200 199 d η 1 (11)
∣ β ^ j ′ − β ^ j ′ ′ ∣ ≤ η 1 200 d , for j , j ′ ≠ s ; 0 ≤ β ^ j ′ ≤ 1.01 η 1 d . (12) \left|\widehat{\beta}'_j-\widehat{\beta}'_{j'}\right|\le\frac{\eta_1}{200d},\quad\text{for }j,j'\ne s;\quad0\le\widehat{\beta}'_j\le\frac{1.01\eta_1}{d}. \tag*{(12)} β j ′ − β j ′ ′ ≤ 200 d η 1 , for j , j ′ = s ; 0 ≤ β j ′ ≤ d 1.01 η 1 . (12)
Second Phase
For a sample ( w , y ) (w,y) ( w , y ) and i ∈ [ d ] i\in[d] i ∈ [ d ] , we define T i : = ( y − f ( w ) ) γ i ∑ j ≠ i ( β ^ i ′ − β ^ j ′ ) γ j T_i:=(y-f(w))\gamma_i\sum_{j\ne i}(\widehat{\beta}'_i-\widehat{\beta}'_j)\gamma_j T i := ( y − f ( w )) γ i ∑ j = i ( β i ′ − β j ′ ) γ j . Then the empirical gradient w.r.t. α i \alpha_i α i can be written as ∂ L ^ ∂ α i ( 0 d , β ^ ′ ) = − T ^ i \frac{\partial\widehat{\mathcal{L}}}{\partial\alpha_i}(\mathbf{0}_d,\widehat{\beta}')=-\widehat{T}_i ∂ α i ∂ L ( 0 d , β ′ ) = − T i , hence for every background symbol j ≠ s j\ne s j = s :
α ^ s ′ − α ^ j ′ = η 2 ( T ^ s − T ^ j ) (13) \widehat{\alpha}'_s-\widehat{\alpha}'_j=\eta_2\left(\widehat{T}_s-\widehat{T}_j\right) \tag*{(13)} α s ′ − α j ′ = η 2 ( T s − T j ) (13)
Since the gap and the output weights β ^ ′ \widehat{\beta}' β ′ depend on the same batch of samples, we will not apply a concentration inequality directly to T i T_i T i . Instead, we bound T i T_i T i sample by sample, in terms of V V V and γ j \gamma_j γ j . We first consider a lower bound for T s T_s T s . For negative samples, we have y = − 1 y=-1 y = − 1 , then γ s = 0 \gamma_s=0 γ s = 0 and T s = 0 = V T_s=0=V T s = 0 = V . If y = 1 y=1 y = 1 , then y − f ( w ) = 2 − ∑ i = 1 d β ^ i ′ γ i ≥ 2 − β ^ s ′ ≥ 3 4 y-f(w)=2-\sum_{i=1}^{d}\hat{\beta}'_i\gamma_i\ge2-\hat{\beta}'_s\ge\frac{3}{4} y − f ( w ) = 2 − ∑ i = 1 d β ^ i ′ γ i ≥ 2 − β ^ s ′ ≥ 4 3 by (11), and ∑ i ≠ s ( β ^ s ′ − β ^ i ′ ) γ i ≥ 199 200 η 1 d ( 1 − γ s ) \sum_{i\ne s}(\hat{\beta}'_s-\hat{\beta}'_i)\gamma_i\ge\frac{199}{200}\frac{\eta_1}{d}(1-\gamma_s) ∑ i = s ( β ^ s ′ − β ^ i ′ ) γ i ≥ 200 199 d η 1 ( 1 − γ s ) by (12). Hence T s ≥ 3 4 ⋅ 199 200 ⋅ η 1 d V T_s\ge\frac{3}{4}\cdot\frac{199}{200}\cdot\frac{\eta_1}{d}V T s ≥ 4 3 ⋅ 200 199 ⋅ d η 1 V for every sample, regardless of positive or negative, and by Lemma 3, when A A A happens:
T ^ s ≥ 3 4 ⋅ 199 200 ⋅ η 1 d ⋅ 1 10 d ≥ 7 η 1 100 d 2 . \hat{T}_s\ge\frac{3}{4}\cdot\frac{199}{200}\cdot\frac{\eta_1}{d}\cdot\frac{1}{10d}\ge\frac{7\eta_1}{100d^2}. T ^ s ≥ 4 3 ⋅ 200 199 ⋅ d η 1 ⋅ 10 d 1 ≥ 100 d 2 7 η 1 .
Then we bound T j T_j T j from above. For positive samples, y = 1 y=1 y = 1 , then 0 < y − f ( w ) ≤ 2 0<y-f(w)\le2 0 < y − f ( w ) ≤ 2 , and
∑ i ≠ j ( β ^ j ′ − β ^ i ′ ) γ i = ( β ^ j ′ − β ^ s ′ ) γ s + ∑ i ≠ j , s ( β ^ j ′ − β ^ i ′ ) γ i ≤ η 1 200 d , \sum_{i\ne j}(\hat{\beta}'_j-\hat{\beta}'_i)\gamma_i=(\hat{\beta}'_j-\hat{\beta}'_s)\gamma_s+\sum_{i\ne j,s}(\hat{\beta}'_j-\hat{\beta}'_i)\gamma_i\le\frac{\eta_1}{200d}, i = j ∑ ( β ^ j ′ − β ^ i ′ ) γ i = ( β ^ j ′ − β ^ s ′ ) γ s + i = j , s ∑ ( β ^ j ′ − β ^ i ′ ) γ i ≤ 200 d η 1 ,
since the first term is negative and the second is bounded by (13). For negative samples y = − 1 y=-1 y = − 1 , then γ s = 0 \gamma_s=0 γ s = 0 , ∣ y − f ( w ) ∣ = ∑ i ≠ s β ^ i ′ γ i ≤ 2 |y-f(w)|=\sum_{i\ne s}\hat{\beta}'_i\gamma_i\le2 ∣ y − f ( w ) ∣ = ∑ i = s β ^ i ′ γ i ≤ 2 , and ∣ ∑ i ≠ j ( β ^ j ′ − β ^ i ′ ) γ i ∣ ≤ η 1 200 d \left|\sum_{i\ne j}(\hat{\beta}'_j-\hat{\beta}'_i)\gamma_i\right|\le\frac{\eta_1}{200d} ∑ i = j ( β ^ j ′ − β ^ i ′ ) γ i ≤ 200 d η 1 . For both positive and negative samples, we have T j ≤ 2 γ j ⋅ η 1 200 d T_j\le2\gamma_j\cdot\frac{\eta_1}{200d} T j ≤ 2 γ j ⋅ 200 d η 1 , and by Lemma 3, we have T ^ j ≤ η 1 100 d ⋅ 2 d = 2 η 1 100 d 2 \hat{T}_j\le\frac{\eta_1}{100d}\cdot\frac{2}{d}=\frac{2\eta_1}{100d^2} T ^ j ≤ 100 d η 1 ⋅ d 2 = 100 d 2 2 η 1 .
Combining both bounds with (14), on the event A A A , the empirical attention gap is bounded by:
Δ ^ : = α ^ s ′ − max j ≠ s α ^ j ′ ≥ η 1 η 2 20 d 2 . (14) \hat{\Delta}:=\hat{\alpha}'_s-\max_{j\ne s}\hat{\alpha}'_j\ge\frac{\eta_1\eta_2}{20d^2}. \tag*{(14)} Δ ^ := α ^ s ′ − j = s max α ^ j ′ ≥ 20 d 2 η 1 η 2 . (14)
Third phase. Conditioned on event A A A happens with the first batch, we fix ( α ^ ′ , β ^ ′ ) (\hat{\alpha}',\hat{\beta}') ( α ^ ′ , β ^ ′ ) . All probabilities below are over the fresh batch ( w ( k ) , y ( k ) ) k = 1 N 3 (w^{(k)},y^{(k)})_{k=1}^{N_3} ( w ( k ) , y ( k ) ) k = 1 N 3 , which is independent of ( α ^ ′ , β ^ ′ ) (\hat{\alpha}',\hat{\beta}') ( α ^ ′ , β ^ ′ ) . From here on, γ ( w ) \gamma(w) γ ( w ) denotes the attention weights under α ^ ′ \hat{\alpha}' α ^ ′ , γ ( k ) : = γ ( w ( k ) ) \gamma^{(k)}:=\gamma(w^{(k)}) γ ( k ) := γ ( w ( k ) ) , and we denote the expected as well as the empirical hessians of β \beta β as H : = E [ γ γ ⊤ ] H:=\mathbb{E}[\gamma\gamma^{\top}] H := E [ γ γ ⊤ ] and H ^ : = 1 N 3 ∑ k = 1 N 3 γ ( k ) ( γ ( k ) ) ⊤ \hat{H}:=\frac{1}{N_3}\sum_{k=1}^{N_3}\gamma^{(k)}(\gamma^{(k)})^{\top} H ^ := N 3 1 ∑ k = 1 N 3 γ ( k ) ( γ ( k ) ) ⊤ . We write L ( β ) : = L s ( α ^ ′ , β ) L(\beta):=L_s(\hat{\alpha}',\beta) L ( β ) := L s ( α ^ ′ , β ) and L ^ ( β ) \hat{L}(\beta) L ^ ( β ) for the empirical risk on the fresh batch. In contrast to the third phase of population GD, we do not analyze the convergence of β \beta β to the risk minimizer. Instead, we compare the iterates with the fixed reference point z : = 2 e s z:=2e_s z := 2 e s .
We first prove that the reference point has negligible risk. Let r ( w ) : = f α ^ ′ , z ( w ) − y ( w ) = 2 γ s ( w ) − 1 − y ( w ) r(w):=f_{\hat{\alpha}',z}(w)-y(w)=2\gamma_s(w)-1-y(w) r ( w ) := f α ^ ′ , z ( w ) − y ( w ) = 2 γ s ( w ) − 1 − y ( w ) . For negative samples, r ( w ) = 0 − 1 + 1 = 0 r(w)=0-1+1=0 r ( w ) = 0 − 1 + 1 = 0 . For positive samples, when ∣ w ∣ = m |w|=m ∣ w ∣ = m and C s ( w ) = n ≥ 1 C_s(w)=n\ge1 C s ( w ) = n ≥ 1 , we have
∣ r ( w ) ∣ = 2 − 2 γ s ( w ) = 2 ⋅ ∑ j ≠ s C j ( w ) exp ( α ^ j ′ ) n exp ( α ^ s ′ ) + ∑ j ≠ s C j ( w ) exp ( α ^ j ′ ) ≤ 2 ( m − 1 ) exp ( − Δ ^ ) , |r(w)|=2-2\gamma_s(w)=\frac{2\cdot\sum_{j\ne s}C_j(w)\exp(\hat{\alpha}'_j)}{n\exp(\hat{\alpha}'_s)+\sum_{j\ne s}C_j(w)\exp(\hat{\alpha}'_j)}\le2(m-1)\exp(-\hat{\Delta}), ∣ r ( w ) ∣ = 2 − 2 γ s ( w ) = n exp ( α ^ s ′ ) + ∑ j = s C j ( w ) exp ( α ^ j ′ ) 2 ⋅ ∑ j = s C j ( w ) exp ( α ^ j ′ ) ≤ 2 ( m − 1 ) exp ( − Δ ^ ) ,
Note that this bound does not depend on how the attention is distributed among the non-target symbols. Define the random variable κ : = r ( w ) 2 \kappa:=r(w)^2 κ := r ( w ) 2 and κ ^ : = 1 N 3 ∑ k = 1 N 3 r ( w ( k ) ) 2 \hat{\kappa}:=\frac{1}{N_3}\sum_{k=1}^{N_3}r(w^{(k)})^2 κ ^ := N 3 1 ∑ k = 1 N 3 r ( w ( k ) ) 2 . Since E [ ( m − 1 ) 2 ] = ( d − 2 ) ( 2 d − 3 ) ≤ 2 d 2 \mathbb{E}[(m-1)^2]=(d-2)(2d-3)\le2d^2 E [( m − 1 ) 2 ] = ( d − 2 ) ( 2 d − 3 ) ≤ 2 d 2 , we can bound the expectation of κ \kappa κ by:
E [ κ ] ≤ 8 d 2 exp ( − 2 Δ ^ ) , (15) \mathbb{E}[\kappa]\le8d^2\exp(-2\hat{\Delta}), \tag*{(15)} E [ κ ] ≤ 8 d 2 exp ( − 2 Δ ^ ) , (15)
and by Markov’s inequality, we have κ ^ ≤ d c E [ κ ] \hat{\kappa}\le d^c\mathbb{E}[\kappa] κ ^ ≤ d c E [ κ ] with probability at least 1 − d − c 1-d^{-c} 1 − d − c .
Now we compare population and empirical risk through z z z . For every β ∈ R d \beta\in\mathbb{R}^d β ∈ R d and every string w w w , we have f α ^ ′ , β ( w ) − y ( w ) = ( β − z ) ⊤ γ ( w ) + r ( w ) f_{\hat{\alpha}',\beta}(w)-y(w)=(\beta-z)^{\top}\gamma(w)+r(w) f α ^ ′ , β ( w ) − y ( w ) = ( β − z ) ⊤ γ ( w ) + r ( w ) , and the loss can be bounded from above and below by:
L ( β ) ≤ ( β − z ) ⊤ H ( β − z ) + E [ κ ] , (16) L(\beta)\le(\beta-z)^{\top}H(\beta-z)+\mathbb{E}[\kappa], \tag*{(16)} L ( β ) ≤ ( β − z ) ⊤ H ( β − z ) + E [ κ ] , (16)
( β − z ) ⊤ H ^ ( β − z ) ≤ 4 L ^ ( β ) + 2 κ ^ ; (17) (\beta-z)^{\top}\hat{H}(\beta-z)\le4\hat{L}(\beta)+2\hat{\kappa}; \tag*{(17)} ( β − z ) ⊤ H ^ ( β − z ) ≤ 4 L ^ ( β ) + 2 κ ^ ; (17)
from the inequalities ( a + b ) 2 ≤ 2 a 2 + 2 b 2 (a+b)^2\le2a^2+2b^2 ( a + b ) 2 ≤ 2 a 2 + 2 b 2 and ( a + b ) 2 ≥ 1 2 a 2 − b 2 (a+b)^2\ge\frac{1}{2}a^2-b^2 ( a + b ) 2 ≥ 2 1 a 2 − b 2 . In particular, L ^ ( z ) = 1 2 κ ^ \hat{L}(z)=\frac{1}{2}\hat{\kappa} L ^ ( z ) = 2 1 κ ^ .
The empirical risk L ^ \hat{L} L ^ is a convex quadratic with Hessian H ^ ⪯ I \hat{H}\preceq I H ^ ⪯ I , so it is 1-smooth. Let β ( 0 ) = β ^ \beta(0)=\hat{\beta} β ( 0 ) = β ^ and let β ( t ) \beta(t) β ( t ) denote the GD iterates with η 3 = 1 \eta_3=1 η 3 = 1 . By the descent lemma and convexity, for every t ≥ 0 t\ge0 t ≥ 0 ,
∥ β ( t + 1 ) − z ∥ 2 ≤ ∥ β ( t ) − z ∥ 2 − 2 ( L ^ ( β ( t + 1 ) ) − L ^ ( z ) ) , \|\beta(t+1)-z\|^2\le\|\beta(t)-z\|^2-2\left(\hat{L}(\beta(t+1))-\hat{L}(z)\right), ∥ β ( t + 1 ) − z ∥ 2 ≤ ∥ β ( t ) − z ∥ 2 − 2 ( L ^ ( β ( t + 1 )) − L ^ ( z ) ) ,
and L ^ ( β ( t ) ) \hat{L}(\beta(t)) L ^ ( β ( t )) is non-increasing in t t t . Summing over t = 0 , … , T − 1 t=0,\ldots,T-1 t = 0 , … , T − 1 yields
L ^ ( β ( T ) ) ≤ L ^ ( z ) + ∥ β ( 0 ) − z ∥ 2 2 T , ∥ β ( T ) − z ∥ 2 ≤ ∥ β ( 0 ) − z ∥ 2 + 2 T L ^ ( z ) . (18) \hat{L}(\beta(T))\le\hat{L}(z)+\frac{\|\beta(0)-z\|^2}{2T},\qquad\|\beta(T)-z\|^2\le\|\beta(0)-z\|^2+2T\hat{L}(z). \tag*{(18)} L ^ ( β ( T )) ≤ L ^ ( z ) + 2 T ∥ β ( 0 ) − z ∥ 2 , ∥ β ( T ) − z ∥ 2 ≤ ∥ β ( 0 ) − z ∥ 2 + 2 T L ^ ( z ) . (18)
By (10) and (12) , 0 ≤ β ^ s ′ < 2 0 \le\hat{\beta}'_{s} < 2 0 ≤ β ^ s ′ < 2 and ∑ j ≠ s ( β ^ j ′ ) 2 ≤ ( d − 1 ) 1.03 η 1 2 d 2 ≤ 2 \sum_{j \ne s}(\hat{\beta}'_{j})^{2} \le(d-1)\frac{1.03\,\eta_{1}^{2}}{d^{2}} \le2 ∑ j = s ( β ^ j ′ ) 2 ≤ ( d − 1 ) d 2 1.03 η 1 2 ≤ 2 , hence ∥ β ( 0 ) − z ∥ 2 ≤ 6 \|\boldsymbol{\beta}(0)-z\|^{2} \le6 ∥ β ( 0 ) − z ∥ 2 ≤ 6 . Together with L ^ ( z ) = 1 2 κ ^ \hat{\mathcal{L}}(z)=\frac{1}{2}\hat{\kappa} L ^ ( z ) = 2 1 κ ^ , (18) gives
L ^ ( β ( T ) ) ≤ κ ^ 2 + 3 T , ∥ β ( T ) − z ∥ 2 ≤ 6 + T κ ^ . (19) \hat{\mathcal{L}}(\boldsymbol{\beta}(T)) \le\frac{\hat{\kappa}}{2}+\frac{3}{T}, \qquad\|\boldsymbol{\beta}(T)-z\|^{2} \le6+T\hat{\kappa}. \tag*{(19)} L ^ ( β ( T )) ≤ 2 κ ^ + T 3 , ∥ β ( T ) − z ∥ 2 ≤ 6 + T κ ^ . (19)
We next consider the concentration on the hessian with the following lemma:
Lemma 4. Let λ : = 16 ( c + 1 ) ln d N 3 \lambda:= \frac{16(c+1)\ln d}{N_{3}} λ := N 3 16 ( c + 1 ) l n d and assume λ ≤ 1 \lambda\le1 λ ≤ 1 . Then, with probability at least 1 − d − c 1-d^{-c} 1 − d − c ,
H ⪯ 2 H ^ + λ I . H \preceq2\hat{H}+\lambda I. H ⪯ 2 H ^ + λ I .
Proof. Let H λ : = H + λ I H_{\lambda}:=H+\lambda I H λ := H + λ I and define the independent positive semidefinite matrices
Y k : = H λ − 1 / 2 γ ( k ) ( γ ( k ) ) T H λ − 1 / 2 + λ H λ − 1 , k ∈ [ N 3 ] . Y_{k}:=H_{\lambda}^{-1/2}\gamma^{(k)}\left(\gamma^{(k)}\right)^{\mathsf{T}}H_{\lambda}^{-1/2}+\lambda H_{\lambda}^{-1},\quad k\in[N_{3}]. Y k := H λ − 1/2 γ ( k ) ( γ ( k ) ) T H λ − 1/2 + λ H λ − 1 , k ∈ [ N 3 ] .
Then E [ Y k ] = I \mathbb{E}[Y_{k}]=I E [ Y k ] = I , so λ min ( ∑ k E [ Y k ] ) = N 3 \lambda_{\min}\left(\sum_{k}\mathbb{E}[Y_{k}]\right)=N_{3} λ m i n ( ∑ k E [ Y k ] ) = N 3 , and λ max ( Y k ) ≤ ∥ γ ( k ) ∥ 2 λ + 1 ≤ 2 λ \lambda_{\max}(Y_{k})\le\frac{\|\gamma^{(k)}\|^{2}}{\lambda}+1\le\frac{2}{\lambda} λ m a x ( Y k ) ≤ λ ∥ γ ( k ) ∥ 2 + 1 ≤ λ 2 . By the matrix Chernoff inequality (Tropp, [27 ] ), we have:
P ( λ min ( ∑ k = 1 N 3 Y k ) ≤ N 3 2 ) ≤ d exp ( − N 3 8 ⋅ λ 2 ) = d − c . \mathbb{P}\left(\lambda_{\min}\left(\sum_{k=1}^{N_{3}}Y_{k}\right)\le\frac{N_{3}}{2}\right)\le d\exp\left(-\frac{N_{3}}{8}\cdot\frac{\lambda}{2}\right)=d^{-c}. P ( λ m i n ( k = 1 ∑ N 3 Y k ) ≤ 2 N 3 ) ≤ d exp ( − 8 N 3 ⋅ 2 λ ) = d − c .
On the complementary event, H λ − 1 / 2 ( H ^ + λ I ) H λ − 1 / 2 ⪰ 1 2 I H_{\lambda}^{-1/2}(\hat{H}+\lambda I)H_{\lambda}^{-1/2}\succeq\frac{1}{2}I H λ − 1/2 ( H ^ + λ I ) H λ − 1/2 ⪰ 2 1 I , that is, H ^ + λ I ⪰ 1 2 ( H + λ I ) \hat{H}+\lambda I\succeq\frac{1}{2}(H+\lambda I) H ^ + λ I ⪰ 2 1 ( H + λ I ) , proving the claim. □
On the events of Step 1 and Lemma 4, which hold simultaneously with probability at least 1 − 2 d − c 1-2d^{-c} 1 − 2 d − c , we combine (16) , Lemma 4, (17) and (19) :
L ( β ( T ) ) ≤ ( β ( T ) − z ) T H ( β ( T ) − z ) + E [ κ ] ≤ 2 ( β ( T ) − z ) T H ^ ( β ( T ) − z ) + λ ∥ β ( T ) − z ∥ 2 + E [ κ ] \mathcal{L}(\boldsymbol{\beta}(T))\le(\boldsymbol{\beta}(T)-z)^{\mathsf{T}}H(\boldsymbol{\beta}(T)-z)+\mathbb{E}[\kappa]\le2(\boldsymbol{\beta}(T)-z)^{\mathsf{T}}\hat{H}(\boldsymbol{\beta}(T)-z)+\lambda\|\boldsymbol{\beta}(T)-z\|^{2}+\mathbb{E}[\kappa] L ( β ( T )) ≤ ( β ( T ) − z ) T H ( β ( T ) − z ) + E [ κ ] ≤ 2 ( β ( T ) − z ) T H ^ ( β ( T ) − z ) + λ ∥ β ( T ) − z ∥ 2 + E [ κ ]
≤ 8 L ^ ( β ( T ) ) + 4 κ ^ + λ ∥ β ( T ) − z ∥ 2 + E [ κ ] ≤ 24 T + 6 λ + ( 8 + λ T ) κ ^ + E [ κ ] ≤ 24 T + 6 λ + ( 9 + T ) d c E [ κ ] . \le8\hat{\mathcal{L}}(\boldsymbol{\beta}(T))+4\hat{\kappa}+\lambda\|\boldsymbol{\beta}(T)-z\|^{2}+\mathbb{E}[\kappa]\le\frac{24}{T}+6\lambda+(8+\lambda T)\hat{\kappa}+\mathbb{E}[\kappa]\le\frac{24}{T}+6\lambda+(9+T)d^{c}\mathbb{E}[\kappa]. ≤ 8 L ^ ( β ( T )) + 4 κ ^ + λ ∥ β ( T ) − z ∥ 2 + E [ κ ] ≤ T 24 + 6 λ + ( 8 + λ T ) κ ^ + E [ κ ] ≤ T 24 + 6 λ + ( 9 + T ) d c E [ κ ] .
We bound the three terms by ε / 3 \varepsilon/3 ε /3 each. The first term, we can set the training step T = ⌈ 72 / ε ⌉ T=\lceil72/\varepsilon\rceil T = ⌈ 72/ ε ⌉ ; for the second term, we set N 3 ≥ 288 ( c + 1 ) ln d ε N_{3}\ge\frac{288(c+1)\ln d}{\varepsilon} N 3 ≥ ε 288 ( c + 1 ) l n d , then 6 λ ≤ ε / 3 6\lambda\le\varepsilon/3 6 λ ≤ ε /3 . For the third term, since 9 + T ≤ 82 ε 9+T\le\frac{82}{\varepsilon} 9 + T ≤ ε 82 , by (15) we know ( 9 + T ) d c E [ κ ] ≤ 656 d c + 2 ε exp ( − 2 Δ ^ ) ≤ ε / 3 (9+T)d^{c}\mathbb{E}[\kappa]\le\frac{656d^{c+2}}{\varepsilon}\exp(-2\hat{\Delta})\le\varepsilon/3 ( 9 + T ) d c E [ κ ] ≤ ε 656 d c + 2 exp ( − 2 Δ ^ ) ≤ ε /3 if Δ ^ ≥ ln 45 d ( c + 2 ) / 2 ε \hat{\Delta}\ge\ln\frac{45d^{(c+2)/2}}{\varepsilon} Δ ^ ≥ ln ε 45 d ( c + 2 ) /2 . By (14) , this will hold if η 2 ≥ 20 d 2 η 1 ε ln 45 d ( c + 2 ) / 2 ε \eta_{2}\ge\frac{20d^{2}}{\eta_{1}\varepsilon}\ln\frac{45d^{(c+2)/2}}{\varepsilon} η 2 ≥ η 1 ε 20 d 2 ln ε 45 d ( c + 2 ) /2 , which is implied by η 2 ≥ C d 2 ε ln d ε \eta_{2}\ge\frac{Cd^{2}}{\varepsilon}\ln\frac{d}{\varepsilon} η 2 ≥ ε C d 2 ln ε d for a suitable constant C C C . Hence L s ( α ^ ′ , β ^ ′ ′ ) ≤ ε \mathcal{L}_{s}(\hat{\alpha}',\hat{\beta}'')\le\varepsilon L s ( α ^ ′ , β ^ ′′ ) ≤ ε with β ^ ′ ′ : = β ( T ) \hat{\beta}'' := \boldsymbol{\beta}(T) β ^ ′′ := β ( T ) . A union bound over the event A A A and the two events above gives a total probability at least 1 − 3 d − c 1-3d^{-c} 1 − 3 d − c . □
Additional Experiments
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. [15 ] and Marion et al. [20 ] , with parameters ( W ∈ R D × D , u ∈ R D ) (W\in\mathbb{R}^{D\times D},u\in\mathbb{R}^{D}) ( W ∈ R D × D , u ∈ R D ) and ( k ∈ R D , v ∈ R D ) (k\in\mathbb{R}^{D},v\in\mathbb{R}^{D}) ( k ∈ R D , v ∈ R D ) , respectively, where D D D 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 A , B ∈ R d × d A,B\in\mathbb{R}^{d\times d} A , B ∈ R d × d . Given the query token q q q , position t t t receives the attention logit A q , x t − 1 A_{q,x_{t-1}} A q , x t − 1 , which depends on its preceding token x t − 1 x_{t-1} x t − 1 through the fixed first layer. The model outputs the logits ∑ t softmax ( A q , x t − 1 ) B : , x t ∈ R d \sum_{t}\operatorname{softmax}(A_{q,x_{t-1}})B_{:,x_{t}\,}\in\mathbb{R}^{d} ∑ t softmax ( A q , x t − 1 ) B : , x t ∈ R d over the next token and is trained with the cross-entropy loss. Here, A A A and B B B play the roles of our attention and output weights, respectively.
Initialization. Table 2 lists the initializations. AND differs in three respects. First, we draw α ( 1 ) , α ( 2 ) , β ( 1 ) , β ( 2 ) \alpha^{(1)},\alpha^{(2)},\beta^{(1)},\beta^{(2)} α ( 1 ) , α ( 2 ) , β ( 1 ) , β ( 2 ) with i.i.d. N ( 0 , 1 ) \mathcal{N}(0,1) N ( 0 , 1 ) entries and set α ( 3 ) = − α ( 1 ) \alpha^{(3)}=-\alpha^{(1)} α ( 3 ) = − α ( 1 ) , α ( 4 ) = − α ( 2 ) \alpha^{(4)}=-\alpha^{(2)} α ( 4 ) = − α ( 2 ) , β ( 3 ) = − β ( 1 ) \beta^{(3)}=-\beta^{(1)} β ( 3 ) = − β ( 1 ) , β ( 4 ) = − β ( 2 ) \beta^{(4)}=-\beta^{(2)} β ( 4 ) = − β ( 2 ) , which prevents head collapse. Second, in the plans A→ \to → O, O→ \to → A, and O→ \to → A→ \to → O, 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.
Table 2: Initializations. The fixed initialization is used only for O → A → O O\to A\to O O → A → O ; Gaussian entries are i.i.d.
Step sizes and counts. Every plan is built from the same three ingredients: a base step size η \eta η for multi-step phases and for joint GD, and the step sizes η O \eta_{O} η O and η A \eta_{A} η A 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 1/2 1/2 used in the theoretical analysis. An experimental learning rate η \eta η therefore corresponds to 2 η 2\eta 2 η under the theoretical loss normalization.
Table 3: Schedule of each training plan. “A: η A × 1 \eta_{A}\times1 η A × 1 ” means one GD step on the attention weights with step size η A \eta_{A} η A ; “O: η × 2500 \eta\times2500 η × 2500 ” means 2500 GD steps on the output weights with step size η \eta η .
Table 3.
Table 4: Step sizes per task. For AND, the attention phase uses multiple steps with the base step size η \eta η (see text).
Table 4.
For AND, every single attention step is replaced by a multi-step phase with step size η \eta η . A→ \to → O uses 1250 attention steps followed by 1250 output steps, O(1x)→ \to → A uses one output step followed by 1250 attention steps, and O(1x)→ \to → A→ \to → O uses 1250 attention steps in the second phase and 1250 output steps in the third.
Attention and Output Gaps
OR. With target set T T T (∣ T ∣ = 2 |T|=2 ∣ T ∣ = 2 ), the attention gap is E + [ ∑ t ∈ T γ t ( w ) − max i ∉ T γ i ( w ) ] \mathbb{E}_{+}\left[\sum_{t\in T}\gamma_{t}(w)-\max_{i\notin T}\gamma_{i}(w)\right] E + [ ∑ t ∈ T γ t ( w ) − max i ∈ / T γ i ( w ) ] . The output gap is ( 1 ∣ T ∣ ∑ t ∈ T β t − max j ∉ T β j ) / 2 \left(\frac{1}{|T|}\sum_{t\in T}\beta_{t}-\max_{j\notin T}\beta_{j}\right)/2 ( ∣ T ∣ 1 ∑ t ∈ T β t − max j ∈ / T β j ) /2 .
AND. For each head h h h , let t h = arg max t ∈ T α t ( h ) t_{h}=\arg\max_{t\in T}\alpha_{t}^{(h)} t h = arg max t ∈ T α t ( h ) be the target that head favours. Its attention gap is E + [ γ t h ( h ) ( w ) − max i ≠ t h γ i ( h ) ( w ) ] \mathbb{E}_{+}\left[\gamma_{t_{h}}^{(h)}(w)-\max_{i\ne t_{h}}\gamma_{i}^{(h)}(w)\right] E + [ γ t h ( h ) ( w ) − max i = t h γ i ( h ) ( w ) ] . Heads are ranked by their final gap, separately in every run.
even pairs. Let z ( X ) = ∑ l ϕ l ( X ) x l z(X)=\sum_{l}\phi_{l}(X)x_{l} z ( X ) = ∑ l ϕ l ( X ) x l be the attention output, where ϕ \phi ϕ are the attention weights under W W W . The attention measure is the linear separability of { ( z ( X ) , y ) } \{(z(X),y)\} {( z ( X ) , y )} over all strings. It is the accuracy of the max-margin linear classifier w ∗ w^{*} w ∗ through the origin, computed with a squared-hinge SVM with C = 10 3 C=10^{3} C = 1 0 3 . The output gap is cos ( u , w ∗ ) \cos(u,w^{*}) cos ( u , w ∗ ) . Since w ∗ w^{*} w ∗ is recomputed from the current attention, this gap can change while u u u is frozen.
ICL bigram. For a sequence with query q q q , let t ∗ t^{*} t ∗ be the position after the query key, i.e., the position with x t ∗ − 1 = q x_{t^{*}-1}=q x t ∗ − 1 = q . The attention gap is the average over the training sequences of softmax t ( x t ∗ − 1 ) − max t ≠ t ∗ softmax t \operatorname{softmax}_{t}(x_{t^{*}-1})-\max_{t\ne t^{*}}\operatorname{softmax}_{t} softmax t ( x t ∗ − 1 ) − max t = t ∗ softmax t , with weights softmax t ( A q t ∗ − 1 ) \operatorname{softmax}_{t}(Aq_{t^{*}-1}) softmax t ( A q t ∗ − 1 ) . The output gap is cos ( B ~ , I ~ ) \cos(\tilde{B},\tilde{I}) cos ( B ~ , I ~ ) , using the Frobenius inner product. Here B ~ \tilde{B} B ~ and I ~ = I − 1 d 11 T \tilde{I}=I-\frac{1}{d}\mathbf{1}\mathbf{1}^{\mathsf{T}} I ~ = I − d 1 1 1 T are B B B and the identity with each column centered over the classes.
SLR. With J J J the relevant location of a sample, the attention gap is the average over the training samples of softmax ( X k ) J − max l ≠ J softmax ( X k ) l \operatorname{softmax}(Xk)_{J}-\max_{l\ne J}\operatorname{softmax}(Xk)_{l} softmax ( X k ) J − max l = J softmax ( X k ) l . The output gap is cos ( v , v ∗ ) \cos(v,v^{*}) cos ( v , v ∗ ) with the ground-truth direction v ∗ v^{*} v ∗ .
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.
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.
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.
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 ≤ 10 − 3 10^{-3} 1 0 − 3 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.
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 2. Joint GD (left), O-A-O training (middle), and A-O training (right). Attention gap, output gap, and test accuracy for d = 50 d = 50 d = 50 are shown with 5 d 2 5d^2 5 d 2 training and d 2 d^2 d 2 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.
Figure 5. Attention and output gaps on occurrence and OR. Notation and phases are as in Figure 3 .