Transformers Efficiently Perform In-Context Logistic Regression via Normalized Gradient Descent
arXiv:2605.06609v1 [cs.LG] 7 May 2026
Chenyang Zhang∗
Yuan Cao†
Abstract Transformers have demonstrated remarkable in-context learning (ICL) capabilities. The strong ICL performance of transformers is commonly believed to arise from their ability to implicitly execute certain algorithms on the context, thereby enhancing prediction and generation. In this work, we investigate how transformers with softmax attention perform in-context learning on linear classification data. We first construct a class of multi-layer transformers that can perform in-context logistic regression, with each layer exactly performing one step of normalized gradient descent on an in-context loss. Then, we show that our constructed transformer can be obtained through (i) training a single self-attention layer supervised by one-step gradient descent, and (ii) recurrently applying the trained layer to obtain a looped model. Training convergence guarantees of the self-attention layer and out-of-distribution generalization guarantees of the looped model are provided. Our results advance the theoretical understanding of ICL mechanism by showcasing how softmax transformers can effectively act as in-context learners.
1
Introduction
Transformers have achieved remarkable success in a wide range of applications, including natural language processing (Vaswani et al., 2017; Devlin, 2018; Touvron et al., 2023), computer vision (Dosovitskiy et al., 2020; Rao et al., 2021; Yuan et al., 2021; Zhang et al., 2025b), and reinforcement learning (Janner et al., 2021; Reed et al., 2022; Kim et al., 2025). One widely recognized interpretation for their empirical success is their ability to perform in-context learning (ICL): pretrained transformers are capable of performing previously unseen tasks based on demonstrations and examples in the prompt, without requiring any additional task-specific fine-tuning (Brown et al., 2020). A line of recent works interpret the in-context learning (ICL) capability of transformers from an algorithmic perspective, viewing transformers as models that can implicitly execute certain learning algorithms on the context examples. Specifically, Garg et al. (2022) proposes a theoretical framework for ICL in terms of learning a hypothesis class, and empirically shows that transformers can in-context learn the linear function class. Motivated by this empirical finding, several recent works attempt to theoretically study how transformers perform in-context learning on linear regression tasks. Akyürek et al. (2022); Von Oswald et al. (2023) construct multi-layer transformers with linear attention that can execute gradient descent on the an “in-context loss” defined on the context data, thereby enabling in-context learning of linear regression. Ahn et al. (2023); Zhang ∗ †
School of Computing & Data Science, The University of Hong Kong; [email protected] School of Computing & Data Science, The University of Hong Kong; [email protected]
1
et al. (2024b); Huang et al. (2024) further provide training guarantees for single-layer transformers with linear or softmax attention, showing that such models can be trained to solve in-context regression problems. Beyond standard linear regression, Guo et al. (2023); Bai et al. (2024) further demonstrate the in-context learning capacities of transformers by constructing multi-head ReLU transformers capable of performing a variety of learning algorithms, including ridge regression, Lasso regression, and generalized linear models. More recently, Frei and Vardi (2025); Shen et al. (2025) study how single-layer transformers with linear attention can be trained to solve in-context classification on Gaussian mixture data. Several recent works also investigate in-context learning and other learning tasks with looped transformers, in which the same parameter matrices are shared across different layers. Gatmiry et al. (2024); Chen et al. (2025a) theoretically show that looped transformers still implement gradient descent for in-context linear regression. Yang et al. (2024) empirically demonstrates that looped transformers can achieve performance comparable to that of standard transformers in in-context learning, while using significantly fewer parameters. Geiping et al. (2025) further shows that at inference time, transformers can effectively benefit from increased depth by recurrently applying a trained block. In this work, we study how a multi-layer (looped) transformer with softmax attention performs in context learning on classification tasks. Following the settings in Huang et al. (2025), we consider using transformers to solve an “in-context weight prediction” task, and investigate transformer’s expressive power, training guarantees, and out-of-distribution (O.O.D.) generalization performance on this task. The major contributions of this work are as follows. • We establish expressive power guarantees and demonstrate that there exists a class of multi-layer softmax transformers that can perform in-context logistic regression (defined on exponential loss function)1 via normalized gradient descent. Specifically, the hidden layers’ outputs of an L-layer transformer exactly match the first L iterates of normalized gradient descent on the in-context loss of logistic regression. Leveraging this exact equivalence and the implicit bias of normalized gradient descent, we further prove that the transformer’s output converges in direction to the maximum-margin solution of the context dataset as the depth L increases. • We also study whether our constructed models can be obtained through training. We consider the strategy to first train a single-layer transformer, and then obtain a looped transformer by recurrently applying the trained layer. For this training problem, our results precisely characterize the existence of a unique minimizer, establish a linear convergence rate, and demonstrate that the obtained model aligns well with the ones constructed in our expressive power guarantees. Interestingly, our results show that the transformer learns normalized gradient descent even though it is supervised by a “gradient descent teacher”. • We validate the capacities of the obtained looped transformers to solve in-context weight prediction by providing an O.O.D. generalization bound. Notably, this result is a point-wise high probability guarantee that holds for any input, and is stronger than the in-expectation guarantees commonly adopted in the in-context learning literature. Under mild assumptions of the num1
In the implicit-bias literature, linear classification with exponential-tailed losses is often treated under the umbrella of the term “logistic regression” and analyzed under a unified framework. In this work, following this convention, we slightly abuse the term “in-context logistic regression” to refer specifically to the in-context linear classification setting with the exponential loss.
2
e d , matching the PAC learning sample ber of layers L, the generalization bound is given as O n complexity lower bound (Long, 1995). • From a technical perspective, our training analysis develops several novel proof techniques, including an analysis based on an approximate training procedure, the application of the Newton–Kantorovich theorem, and the derivation of a Polyak-Lojasiewicz inequality. We believe these novel proof techniques may help the analysis of transformers with softmax attention in broad scenarios, and thus may be of independent interest. Notation. Given two sequences {xn } and {yn }, we denote xn = O(yn ) if there exist some absolute constant C1 > 0 and N > 0 such that |xn | ≤ C1 |yn | for all n ≥ N . Similarly, we denote xn = Ω(yn ) if there exist C2 > 0 and N > 0 such that |xn | ≥ C2 |yn | for all n > N . We say xn = Θ(yn ) if e e e to hide logarithmic factors in xn = O(yn ) and xn = Ω(yn ) both holds. We use O(·), Ω(·), and Θ(·) these notations respectively. Moreover, we denote xn = poly(yn ) if xn = O(ynD ) for some positive constant D, and xn = polylog(yn ) if xn = poly(log(yn )). For two scalars a and b, we denote a ∨ b = max{a, b} and a ∧ b = min{a, b}. For any n ∈ N+ , we use [n] to denote the set {1, 2, · · · , n}. We use 1n to denote a n-dimensional vector with all 1 entries. For any d1 , d2 ∈ N+ , we denote Id1 the d1 × d1 identity matrix, and 0d1 ×d2 the d1 × d2 matrix with all its entries being zero. We denote Sd−1 the d-dimensional unit sphere, and U (Sd−1 ) the uniform distribution over Sd−1 . For any a ∈ Rd and a positive definite matrix Σ ∈ Rd×d , N (a, Σ) denotes the d-dimensional Gaussian distribution with mean a and covariance matrix Σ. We use ϕ(·), and Φ(·) to denote the p.d.f. and c.d.f. of standard normal distribution, respectively. For any matrix A, we use λi (A) to denote its i-th eigenvalue. In addition, we write [A]i:j,k to denote the subvector formed by entries in rows i through j of the k-th column. Similarly, [A]i,j:k denote the subvector formed by entries in columns j through k of the i-th row.
2
Related works
In-context learning of transformers. In-context learning capacities of transformers are first formalized in Garg et al. (2022), with experiments on linear function hypothesis classes. Given this formulation, many recent works attempt to investigate the in-context learning capabilities under different settings. Akyürek et al. (2022); Von Oswald et al. (2023) theoretically demonstrate the expressive power of transformers, showing that they can implicitly perform algorithms on context data like gradient descent. Ahn et al. (2023) explicitly constructs a multi-layer linear transformer capable of conducting preconditioned gradient descent for linear regression, and provides the characterization of the loss landscape and training convergence. Zhang et al. (2024b) investigates the training of a single-layer linear transformer on the context data embedded from linear regression samples, and provides both in-distribution and out-of-distribution generalization guarantees. Huang et al. (2024) extends this result to the single-layer softmax transformer, while requiring a strong assumption regarding the training strategy. Also, for in-context linear regression, Chen et al. (2024a,c) investigates the mechanism of the multi-heads from the training and expressive power perspectives respectively. Zhang et al. (2024c) investigates the training of a single-layer transformer connected with an MLP block, and shows it can simulate the one-step of gradient descent with learnable initialization. Bai et al. (2024); Guo et al. (2023) further extend the scope of in-context algorithms implemented by transformers, showing that they can perform empirical risk minimization for linear regression, ridge regression, Lasso, and more general generalized linear models. Frei 3
and Vardi (2025); Shen et al. (2025) investigates the training of single-layer linear transformer to solve in-context classification with Gaussian mixture inputs. Chen and Zou (2024) study the role of depth in transformers through a set of sequence learning tasks, showing that while a single attention layer can achieve memorization, reasoning and generalization require multiple attention layers. Chen et al. (2025b) studies how test-time computation in transformers can be understood through in-context linear regression with randomness and sampling. Cao et al. (2025) investigates the expressive power of Transformers in Bayesian network sequence modeling, showing that they can implement in-context maximum likelihood estimation and autoregressive sampling. Li et al. (2025) study the context hijacking phenomenon through the lens of an optimization procedure with heterogeneous learning rates. Anwar et al. (2024) study in-context linear regression through an adversarial lens, showing that adversarial attacks transfer poorly across transformer seeds and between transformers and classical learning algorithms. Optimization of transformers. Besides the studies focusing on the ICL capacities of transformers, several recent works study the training behavior under other settings. Zhang et al. (2020); Kunstner et al. (2023); Pan and Li (2023); Li et al. (2024a); Zhang et al. (2024d) investigate how transformers behave when trained by different optimizers, covering distinct theoretical and empirical settings. Li et al. (2023); Jelassi et al. (2022) studies the training of shallow ViT-type transformers under certain specified initializations. Gao et al. (2024) addresses the global convergence of transformers given certain prerequisites. Ildiz et al. (2024); Chen et al. (2024b); Nichani et al. (2024); Shi and Cao (2025) study how transformers are trained on Markovian data and how attention mechanisms recover the underlying transition structure. Specifically, Ildiz et al. (2024) characterize self-attention as a context-conditioned Markov chain, Chen et al. (2024b) show that induction heads emerge as a copier–selector–classifier mechanism on n-gram data, Nichani et al. (2024) demonstrates that attention gradients recover latent causal graphs, and Shi and Cao (2025) shows that attention selects parent states while values implement Markov transitions in random walks. In addition, some works provide learning guarantees of transformers in certain statistical tasks, including the sparse-linear classifier (Zhang et al., 2025a), sparse token selection (Wang et al., 2024b), one-nearest neighbor selection (Li et al., 2024b), maximum hard-margin classifier (Tarzanagh et al., 2023a,b), the compositions of functions (Wang et al., 2025), implementation of spectral methods and EM updates on Gaussian mixture models (He et al., 2025a,b), and “teacher-student” distillation (Zhang et al., 2026). Implicit bias of logistic regression. A line of theoretical works studies the implicit bias of different optimizers on logistic regression (Soudry et al., 2018; Ji and Telgarsky, 2019; Nacson et al., 2019; Qian and Qian, 2019; Ji and Telgarsky, 2021; Wang et al., 2022; Zhang et al., 2024a; Wang et al., 2024a). Soudry et al. (2018) proves that the iterates of gradient descent directionally converge to the maximum ℓ2 -margin solution on separable data, and Ji and Telgarsky (2019) extends this result to the settings with non-separable data. While the previous results are established for fullbatch gradient descent, Nacson et al. (2019) studies the implicit bias of stochastic gradient descent, and demonstrates the same directional convergence results as full-batch gradient descent. Ji and Telgarsky (2021) propose a primal-dual framework, and demonstrate a fast polynomial convergence rate for implicit bias of normalized gradient descent. Wang et al. (2024a) further proposes an exponentially adaptive learning rate for gradient descent, which achieves a linear convergence rate. Wu et al. (2023) studies the implicit bias of gradient descent under the “edge of stability” setting, where the learning rate can be set as arbitrarily large. Besides gradient descent, several works have investigated adaptive gradient-based optimization methods that incorporate momentum. Qian and
4
Qian (2019) studies the implicit bias of AdaGrad, and shows a directional convergence toward a maximum-margin solution under certain preconditioned norm. Wang et al. (2022) studies shows that the momentum does not change the implicit bias of gradient descent. Zhang et al. (2024a) demonstrates an implicit bias towards the maximum ℓ∞ -margin of Adam.
3
Problem setups
In this section, we introduce the problem setting of in-context learning for weight prediction and the multi-layer softmax transformer models considered in this work. In-context learning for weight predictions. In-context learning (ICL) refers to a learning framework in which the input consists of a collection of context data pairs Dn = {(xi , yi ) : xi ∈ X , yi ∈ Y}ni=1 ∈ D, together with a query input xquery ∈ X , whose label yquery ∈ Y is unknown. An in-context learning model f (·, ·) : X × D → Y is then expected to infer the underlying featurelabel mapping from Dn , and produce a prediction for the unknown label yquery in the form of ybquery = f (xquery , Dn ). As demonstrated in recent theoretical works (Ahn et al., 2023; Bai et al., 2024; Zhang et al., 2024b), in-context learning models like transformers typically handle this type of task by implicitly performing certain learning algorithms to fit a predictor gb(·) : X → Y based on the context dataset Dn , and then generate the final prediction via ybquery = gb(xquery ). Beyond the classic in-context learning setting where the goal is to output a prediction for yquery , Huang et al. (2025) further proposes the problem of “in-context weight prediction” under b ·⟩ is a linear model, and the the linear regression setting. In this task, the predictor gb(·) = ⟨θ, b Specifically, they assume in-context learner is required to explicitly output this weight vector θ. n that each in-context set Dn = {(xi , yi )}i=1 admits a ground truth vector θ ∗ such that yi = ⟨θ ∗ , xi ⟩, b Motivated by Huang et al. (2025), in this paper, we and the objective is to estimate θ ∗ by θ. consider “in-context weight prediction” in classification, Definition 3.1. Let Dθ∗ be a distribution over the d-dimensional unit sphere Sd−1 , and Dx be a distribution over Rd . Then the context dataset Dn = {(xi , yi )}ni=1 ⊂ Rd × {±1} and its corresponding ground-truth vector θ ∗ are generated from a joint distribution D as: 1. The ground truth vector θ ∗ is generated from Dθ∗ . 2. Each feature vector xi is generated from Dx , i ∈ [n]. 3. Each label is determined as yi = sign(⟨xi , θ ∗ ⟩), i ∈ [n]. Note that the sign function is invariant to positive rescaling, rendering each label yi determined solely by the direction of θ ∗ . Consequently, we may assume without loss of generality that θ ∗ lies on the unit sphere Sd−1 . For the same reason, we only require the predicted weight θb to approximate b θ ∗ up to its direction, quantified by bθ − θ ∗ 2 . ∥θ∥2 Transformers with softmax attention. We consider solving the in-context weight prediction tasks by transformers. The embedding matrix Z0 for the context dataset Dn = {(xi , yi )}ni=1 , which serves as the input to the transformer, is defined as z 1 z 2 · · · z n 0d Z0 = ∈ R2d×(n+1) , (3.1) 0d 0d · · · 0d θ0
5
where zi = yi · xi for all i ∈ [n], in alignment with the common settings in linear classification. This choice does not restrict the input format: if the transformer takes the concatenated vector ⊤ [x⊤ i , yi ] as input, as commonly considered in prior works, an embedding layer can transform it into zi = yi xi , and the formal derivations are provided in Appendix A. In addition, θ0 serves as an initialization for the prediction of θ ∗ . With the input matrix in the form of (3.1), a standard self-attention layer (Vaswani et al., 2017) is defined as SA(Z; V, W) = VZsoftmax(Z⊤ WZ + M).
(3.2)
In the formulation above, V, W ∈ R2d×2d denote the value and key-query parameter matrices of the self-attention layer, respectively. Following the convention of most theoretical studies (Zhang et al., 2024b,c; Huang et al., 2024; Wang et al., 2024b; Zhang et al., 2025a), we reparameterize the original key and query matrices into a single trainable parameter matrix W. The mask matrix 0n×(n+1) M= prevents attention to the last query column. To define an L-layer transformer, −∞ · 1⊤ n+1 we denote (V0:L−1 , W0:L−1 ) = (V0 , W0 ), . . . , (VL−1 , WL−1 ) as the collection of parameter pairs across layers. Then, building upon the single self-attention layer defined in (3.2), an L-layer transformer with residual connections and parameters (V0:L−1 , W0:L−1 ) is defined recursively as TF(Z0 ; V0:L−1 , W0:L−1 ) = ZL ∈ R2d×(n+1) , Zl+1 = Zl + SA(Zl ; Vl , Wl ), l = 0, . . . , L − 1.
(3.3)
We read the entries in ZL located at the same position as θ0 in Z0 , i.e., θL = [ZL ]d+1:2d, n+1 , as the predicted weight vector corresponding to the input Z0 . This setup is consistent with the setting in Huang et al. (2025).
4
Main results
4.1
Overview of Theoretical Results
In this section, we present the theoretical results on how transformers can perform in-context logistic regression and solve in-context weight prediction tasks in classification. Before presenting the technical details, we first provide a high-level roadmap and summary of our these conclusions. We begin by introducing the in-context loss for linear classification, the empirical risk defined on the context dataset. Theorem 4.1 then establishes the expressive-power result that under appropriate parameterizations, an L-layer softmax transformer can exactly implement L steps of normalized gradient descent on this in-context loss. Building on this characterization, Corollary 4.3 applies the implicit bias theory of normalized gradient descent and shows that, for linearly separable context data, the transformers’ output directionally converges to the in-context maximum-margin solution. We then move from expressivity to learning guarantees. In Theorem 4.5, we consider training a single-layer softmax transformer using supervision from a one-step gradient-descent teacher, and show that the trained parameters exactly converge to an NGD-implementing structures. This demonstrates that the NGD mechanism characterized in Theorem 4.1 can be achieved through training, rather than merely existing as an explicit expressivity construction. Finally, Theorem 4.7 validates the O.O.D. generalization behavior of the looped transformer obtained by recurrently applying the trained single-layer block from Theorem 4.5. Under log-concave feature distributions,
6
Eq (1), (2), (3): Definition of transformers and input formats.
Thm. 3.1: Expressive power The feedforward of � layers of transformers equal to the output of � steps of NGD.
By implicit bias of NGD
Cor. 3.3: Implicit bias The output of transformers directionally converges to the in-context SVM solution.
Assumption:Linear seperable context data.
Def. 2.1: Context data distribution Binary classition context examples generated with a grounth-truth linear classfier �∗ . Lemma 3.4 and Thm. 3.5: Convergence guarantee Under supervision from one-step GD, the parameter matrices of a single-layer transformer converge linearly to the structure characterized in Thm. 3.1, showing that the transformer can indeed be trained to implement NGD.
Additional assumptions: Feature vectors follow Gaussian distribution.
Assump. 3.6: Feature vectors follow log-concave distribution.
Thm. 3.7: O.O.D. generalization For O.O.D. log-concave feature distributions, the trained looped transformer predicts �∗ with the error bounded by depth-dependent implicit bias error + finite-sample statistical error.
Figure 1: High-level roadmap of the theoretical framework, illustrating the assumptions, main results, and logical flow underlying our expressivity, implicit-bias, trainability, and O.O.D. generalization guarantees. Theorem 4.7 shows that its prediction error is controlled by the implicit-bias error from Corollary 4.3 and the finite-sample statistical error of the in-context maximum-margin solution. Figure 1 provides a schematic illustration of this roadmap, highlighting the assumptions, main results, and logical flow underlying our theoretical guarantees.
4.2
Deep transformers can perform in-context logistic regression via normalized gradient descent
To study how transformers solve in-context logistic regression, we define the empirical risk on the context dataset and refer to it as “in-context loss”. Specifically, for any θ ∈ Rd , its in-context loss on Dn = {(xi , yi )}ni=1 is given as n
LICL (θ) =
1X ℓ(⟨θ, yi · xi ⟩), n
(4.1)
i=1
where ℓ(·) : R × R → R is a commonly chosen exponential-tailed loss function, such as the exponential or logistic loss. In this work, we adopt the exponential loss, i.e. ℓ(x) = e−x , to enable cleaner mathematical results. In the following, we show that there exist a class of L-layer transformers that can exactly implement L steps of normalized gradient descent (NGD) on LICL , as formalized in Theorem 4.1. Theorem 4.1. Consider an L-layer transformer TF(·) in (3.3) with parameter matrices (V0:L−1 , W0:L−1 ) of the form 0d×d 0d×d 0d×d −Id Vl = , Wl = α el · Id 0d×d A1,l A2,l
7
2. Pre-softmax attention scores
1. Input matrix �� ��
��
��
��
... ��
��
��
��� ���
�� − ��
��2 ���
��
. . . ���
��
�1
��� ���
��� ���
�� -���
�� ��
��� �� + �� =
��
+
�2
��
�� ��
=
��(�� ) −� + �� = �� �(�� )
�� ��
-��� ��
0 +
��� ��� + Mask
5. One-step NGD update ��(�� ) �(�0 )
��
0
... 0
3. Softmax weight �� �
-��� ��
1
...
=
� � �−�� �� �=1
-��� ��
−∞
−∞
�
�−�� ��
...
�
�−���� 0
4. Product �� �� �
��
�−�� ��
��
...
�� ��
�� �� �� �� ��
�−�� �� �
�−�� ��
...
�
�−���� 0
��(�� ) = �(�0 ) �(�0 ) �� 1
Figure 2: Illustration of the one-step mechanism in Theorem 4.1. Starting from the input matrix Z0 , a single softmax self-attention layer first constructs the pre-softmax attention scores, then obtains the softmax weight vector sq , and finally computes the attention output that matches one step of normalized gradient descent on the in-context loss LICL . for l = 0, 1, . . . , L − 1, where A1,l , A2,l are arbitrary d × d matrices, and α el > 0. Then for any input matrix Z0 of the form (3.1), the transformer gives hidden layer outputs Zl , l = 1, . . . , L, such that {θl = [Zl ]d+1:2d,n+1 }L l=1 are the iterates of normalized gradient descent on LICL (θ) with learning L−1 rates {e αl }l=0 : θl+1 = θl − α el
∇LICL (θl ) , LICL (θl )
l = 0, 1, . . . , L − 1.
(4.2)
Theorem 4.1 demonstrates that, under appropriate parameterizations, the outputs of softmax attention layers exactly match the iterates of normalized gradient descent applied to the in-context loss LICL . Consequently, the forward pass of an L-layer transformer can be interpreted as performing in-context logistic regression through L steps of normalized gradient descent. Specifically, Figure 2 illustrates how a single softmax self-attention layer constructs the attention weights, recovers the normalized-gradient direction, and implements one step of normalized gradient descent. As an expressive-power result, Theorem 4.1 does not impose any assumptions on the context examples. In addition, the attention-only construction should be understood as a minimal construction that isolates the role of softmax attention: adding common architectural components, such as MLP layers, gated attention, or positional encodings, does not affect the validity of the expressive-power conclusion, since these components can be parameterized so that the resulting model preserves the same input-output mapping as the attention-only transformers defined in (3.3). Moreover, we note that the update rule in (4.2) slightly differs from the standard definition of normalized gradient descent, as it normalizes the gradient by LICL (θ) instead of ∥∇LICL (θ)∥2 . 8
However, this form of normalization term is commonly adopted in theoretical studies of logistic regression (Nacson et al., 2019; Ji and Telgarsky, 2021; Wang et al., 2024a), and is also referred to as normalized gradient descent. Our use of this terminology follows this convention. We further note that if an RMSNorm-style layer normalization is incorporated into the construction, the induced update can be transformed into the standard normalized-gradient-descent form, with normalization by ∥∇LICL (θ)∥2 . Several recent works (Ahn et al., 2023; Bai et al., 2024) show that transformers with linear/ReLU attention can perform in-context linear regression with gradient descent. In comparison, our result in Theorem 4.1 shows that transformers with softmax attention can perform in-context logistic regression with normalized gradient descent. Notably, Bai et al. (2024) also covers results on in-context logistic regression, and shows that multi-head ReLU attention layers can approximate gradient descent updates. However, their results rely on universal approximation by multi-head e −2 ) heads per layer to achieve an approximation error ϵ. In ReLU attention, and require O(ϵ comparison, our result considers softmax attention, only requires a single head per layer, and the correspondence to normalized gradient descent is exact and does not suffer from any approximation error. Remark 4.2. Theorem 4.1 also enjoys an important advantage that it accommodates arbitrary parameterizations of the blocks "A1,l and A2,l within Wl . In fact, this parameterization of Wl can # e 0 −β · Id be further generalized to Wl = d×d , with βe being any positive scalar. Under this more A1,l A2,l general form, it can be shown that L-layer transformers still perform in-context logistic regression e n = {βe · xi , yi }n , and with via normalized gradient descent, but on a rescaled context dataset D i=1 L−1 e rescaled learning rates {e αl /β} l=0 . This flexibility in allowing a broad class of parameterizations for Wl plays a key role in our subsequent analysis in Subsection 4.3. The proof of Theorem 4.1 is also demonstrated for this generalized version in Appendix B Notably, regardless of the distributions Dθ∗ , Dx , any context dataset Dn following Definition 3.1 can always be linearly separated by its corresponding θ ∗ . For such linear separable datasets, a remarkable line of works (Soudry et al., 2018; Ji and Telgarsky, 2019; Nacson et al., 2019; Wang et al., 2024a) have shown that (normalized) gradient descent on logistic/exponential loss has an implicit bias towards the maximum-margin solution θSVM (Dn ) = argmax∥θ∥2 ≤1 mini∈[n] ⟨θ, yi · xi ⟩. Specifically, Theorem 4.3 in Ji and Telgarsky (2021) shows that the L-th iterate of normalized gradient descent with constant learning rate α e converges to the maximum margin solution in direction with a convergence rate O(log(n)/(e αL)). Combining this result and Theorem 4.1, we have the following corollary. Corollary 4.3. Suppose that an L-layer transformer is parameterized as in Theorem 4.1 with α el = α e ≤ O(1) for all l = 0, . . . , L − 1. Then for any context dataset Dn = {(xi , yi )}ni=1 following Definition 3.1 and any θ0 with ∥θ0 ∥2 = O(1), the predicted weight θL by this transformer directionally converges to θSVM (Dn ) as θL log n − θSVM (Dn ) ≤ O . ∥θL ∥2 α eL Corollary 4.3 indicates that the predicted weight θL produced by L-layer transformers converges in direction to its maximum margin solution θSVM (Dn ) at a rate inversely proportional to L. With 9
this result, evaluating the quality of θL as a weight predictor for θ ∗ reduces to characterizing the discrepancy between θSVM (Dn ) and θ ∗ . We elaborate this in Subsection 4.4.
4.3
Training of single softmax-attention layer
In the previous section, we have shown that under appropriate parameterizations, transformers can perform in-context logistic regression via normalized gradient descent. However, this result only demonstrates the expressive power of transformers. To give a more comprehensive analysis, in this section, we investigate whether such transformers can indeed be obtained via training. An interesting observation is that, the parameterizations in Theorem 4.1 naturally admit a looped implementation, where all layers share the same weights, i.e., V = Vl and W = Wl for all l ∈ [L]. In addition, Geiping et al. (2025) empirically demonstrates that recurrently applying the trained block enables transformers to achieve better performance at the inference stage. Motivated by these observations, we consider an effective training setup: we first train a single-layer transformer TF(·; V, W), and then obtain a multi-layer looped transformer by recurrently applying this trained layer. Notably, we adopt the one-step gradient descent, rather than normalized gradient descent, as a “teacher model” to supervise the single-layer transformer. This setup is inspired by similar settings considered in Huang et al. (2025), and allows us to test whether the model can still learn normalized gradient descent even if the teacher is a different algorithm. The one-step GD update on the context data can be expressed as θGD = θ0 − α∇LICL (θ0 ), where θ0 represents the initialization, and α denotes the learning rate for one-step GD update. We consider minimizing the discrepancy between θGD and the output of the single-layer transformer, i.e. θ1 = [TF(Z0 , V, W)]d+1;2d,n+1 . The training objective is defined as the population mean-squared error: Ltrain (V, W) = EDn ,θ0 ∥θ1 − θGD ∥22 . The expectation is taken over the context dataset Dn and the initialization θ0 , where θ0 is assumed to follow U(Sd−1 ). Moreover, we assume that Dn is generated following Definition 3.1, with the feature distribution Dx being N (0, σ 2 Id ), and the true classifier distribution Dθ∗ being U(Sd−1 ). We consider using gradient descent with zero initialization V(0) , W(0) = 02d×2d to minimize the training loss Ltrain : V(t+1) = V(t) − η∇V Ltrain (V(t) , W(t) );
(4.3)
W(t+1) = W(t) − η∇W Ltrain (V(t) , W(t) ),
(4.4)
where η denotes the learning rate. Our goal is then to theoretically study this training procedure defined above and verify whether the trained transformer learns to perform one-step normalized gradient descent. Our first observation is that the iterates V(t) , W(t) of gradient descent always preserve certain structured forms, which is summarized in the following lemma. Lemma 4.4. The iterates V(t) and W(t) of the training procedure (4.3), (4.4) always follow a
10
structured form as "
# " # (t) 0 0 0 −C2 ·Id d×d d×d V(t) = (t) , W(t) = d×d , C1 ·Id 0d×d 0d×d 0d×d (t)
(t)
where C1 and C2 are two scalar coefficients. Lemma 4.4 plays a key role in our training analysis: it reduces the original optimization problem concerning the evolutions of full d × d parameter matrices V, W to a much simpler one involving (t) (t) only two scalars C1 , C2 . The coefficient vector C(t) = [C1 , C2 ]⊤ equivalently follows gradient descent starting from zero initialization C(0) = 0 to minimize a proxy training loss: C(t+1) = C(t) − η∇C Letrain (C(t) ), 0d×d 0d×d 0d×d −C2 ·Id e Ltrain (C) = Ltrain , . C1 ·Id 0d×d 0d×d 0d×d The following theorem characterizes the convergence of this equivalent training procedure. Theorem 4.5. Suppose that n = Ω(d2 ), η ≤ O n1 , and α, σ ≤ O(1). Then the following results hold. 1. Invariant compact set R. For all t ≥ 0, the iterate C(t) always remains in a compact set R defined as 2
R = [0, 2αeσ /2 ] × [0, 2]. 2. Unique local minimizer in R. The loss Letrain (C) has a unique local minimizer C∗ = [C1∗ , C2∗ ]⊤ in R. In addition, this local minimizer satisfies that 2 C∗ − [αeσ /2 , 1]⊤ 2 ≤ O d1 . 3. Linear convergence of the loss and iterates. For t ≥ 0, the training loss enjoys a linear convergence rate: Letrain (C(t) ) − Ltrain (C∗ ) ηµ1,α,σ t e ≤ 1− Ltrain (C(0) ) − Letrain (C∗ ) . d Moreover, the iterates C(t) converges linearly to C∗ : (t)
C
ηµ1,α,σ t/2 ∗ − C 2 ≤ µ2,α,σ 1 − ∥C ∥2 . d ∗
Here, µ1,α,σ and µ2,α,σ are positive constants solely depending on α and σ. Theorem 4.5 establishes rigorous training convergence guarantees. The first and second conclusions describe the loss landscape of Letrain and proves the existence of a unique local minimizer C∗ . The third conclusion gives accurate convergence guarantees with linear rates. Importantly, by 11
(t)
2
(t)
the second and third conclusions, as t → ∞, one has C1 ≈ αeσ /2 and C2 ≈ 1, which implies that the trained transformer layer approximately matches the form of our constructed layers in Theorem 4.1. This demonstrates that: The trained transformer can indeed perform normalized gradient descent update, even though the model is supervised by a gradient descent teacher. This reveals a nontrivial separation between the supervising algorithm and the learned in-context algorithm, suggesting that transformers are not merely algorithm imitators, but may also discover (t) algorithmic mechanisms distinct from the supervising algorithm. Moreover, the fact that C2 is not exactly one does not affect the conclusion that the trained transformer layer can exactly perform one-step normalized gradient descent. As discussed in Remark 4.2, the coefficients C1 and C2 admit a clear algorithmic interpretation: C2 acts as the rescaling factor for feature vectors, and the ratio C1 /C2 determines the learning rate. Therefore, the trained single-layer transformer in Theorem 4.5 essentially performs one step of normalized gradient descent on the slightly rescaled 2 (t) (t) (t) dataset {(C2 · xi , yi )}ni=1 , with the learning rate C1 /C2 ≈ αeσ /2 . From a technical perspective, Theorem 4.5 introduces new theoretical tools. While a line of recent works have studied the training of softmax transformers (Jelassi et al., 2022; Wang et al., 2024b; Li et al., 2024b; Zhang et al., 2025a; Shi and Cao, 2025), we note that existing analyses are mostly under the setting where the learning tasks can be perfectly solved by having softmax attention perform certain “sparse selection”. As a result, existing convergence guarantees mostly focus on showing that certain pre-softmax attention scores diverge to infinity, and that they diverge at a faster rate compared to the rest of the scores. In comparison, the learning task we consider is fundamentally different in multiple aspects. First, since the “teacher model” is gradient descent, the learning task is “misspecified” and zero training loss cannot be perfectly achieved. In addition, as is shown in Theorem 4.5, training converges to a finite minimizer C∗ instead of giving diverging parameters in W. More importantly, the model with parameters defined by C∗ does not perform −C ∗ ⟨zi ,θ0 ⟩ “sparse selection”, as the softmax score from the last token to the i-th token is Pn e 2−C ∗ ⟨z ′ ,θ0 ⟩ , i′ =1 e
2
i
which defines a dense, weighted average over all the tokens. Finally, for our learning task, the training loss and its gradient do not admit closed-form expressions, further complicating the optimization analysis. To overcome these challenges, we develop several novel proof techniques, which are summarized in the brief proof sketch as follows. Step 1. We derive explicit non-asymptotic approximations of the gradients (Lemma C.2), and 2 show that [αeσ /2 , 1]⊤ is a fixed point of the approximated training process. Step 2. We then apply the Newton–Kantorovich theorem to show the existence of a fixed point 2 C∗ of the original training process that is close to [αeσ /2 , 1]⊤ (Lemma C.7). Step 3. We further prove a Polyak-Lojasiewicz (PL) inequality (Lemma C.8) despite the nonconvexity of the training loss, which leads to the linear convergence rate.
4.4
Multi-layer looped transformers efficiently solve in-context weight prediction
Theorems 4.1 and 4.5 together show that we can recurrently apply the trained transformer layer characterized in Theorem 4.5 to obtain a multi-layer looped transformer that solves in-context logistic regression via normalized gradient descent. In this section, we establish the final theoretical guarantee on the performance of such looped transformers in solving in-context weight prediction. In contrast to the assumption that Dx during training follows N (0, σ 2 Id ), here we study out-of12
distribution (O.O.D.) generalization performance on new “test” in-context datasets Dn for which Dx is a general log-concave distribution. Assumption 4.6 (Log-concave distribution). For the feature distribution Dx in Definition 3.1, let f (·) be its probability density function. Then it holds that 1. Log-concavity: log[f (x)] is a concave function. 2. Moment conditions: For any x ∼ Dx , it holds that E[x] = 0, and E[xx⊤ ] = Σ ≻ 0. Assumption 4.6 covers a broad class of distributions, such as centered Gaussian, uniform, and Laplace distributions. Based on it, we have the following theorem. (t) (t) Theorem parameter matrices trained in Theorem 4.5 after t = 4.7. Let V and W be(t)the d e Ω iterations. Denote TF(·, [V ]⊗L , [W(t) ]⊗L ) the L-layer looped transformer, with V(t)
ηµ1,α,σ and W(t)
being its shared weights across layers. Suppose that the feature distribution Dx in Definition 3.1 follows Assumption 4.6. Then for any input matrix Z0 of the form (3.1), with probability at least 1 − δ, the looped transformers’ prediction θL = [TF(Z0 , [V(t) ]⊗L , [W(t) ]⊗L )]d+1:2d, n+1 satisfies log n d log ρ θL + . (4.5) − θ∗ ≤ O ∥θL ∥2 αL n 2 −1 where ρ = max{n, d, λ−1 min (Σ), δ },
Theorem 4.7 provides an O.O.D. generalization guarantee for the looped transformer to solve in-context weight prediction. We note that in recent theoretical studies of ICL (Zhang et al., 2024b; Frei and Vardi, 2025; Huang et al., 2025), the generalization bounds are typically presented in expectation over the distribution of the test context dataset Dn . In comparison, Theorem 4.7 establishes a point-wise high-probability guarantee, which holds for any fixed input Z0 . In particular, by choosing δ = O nd , the conclusion of Theorem 4.7 can immediately induce an in-expectation n d log ρ bound EDn ∥θθLL∥2 − θ ∗ 2 ≤ O log , validating that our result is stronger than the clasαL + n sic in-expectation generalization bound. Moreover, this O.O.D. generalization ability stems from the good property that the output θL in direction converges to the maximum margin solution θSVM (Dn ). It is natural to decompose ∥θθLL∥2 − θ ∗ 2 ≤ ∥θθLL∥2 − θSVM (Dn ) 2 + ∥θSVM (Dn ) − θ ∗ ∥2 by triangle inequality. The first term ∥θθLL∥2 − θSVM (Dn ) 2 is controlled in Corollary 4.3, directly n ∗ yielding the term O log αL . In addition, the second term ∥θSVM (Dn ) − θ ∥2 quantifies how well the maximum-margin solution learned from the context dataset Dn approximates the true classifier θ ∗ . d log ρ The upper bound for this statistical error is demonstrated to be O n , corresponding to the second term of generalization bound. The detailed proof for Theorem 4.7 is deferred to Appendix D. Several recent works Frei and Vardi (2025); Shen et al. (2025) investigate how single-layer transformers with linear attention can be trained to solve in-context classification on Gaussianmixture data, and establish in-distribution generalization. In contrast, our Theorem 4.7 establishes O.O.D. generalization for multi-layer transformers with softmax attention. Compared with another recent work Bai et al. (2024), our work gives better bounds thanks to the fast convergence rate of normalized gradient descent. Specifically, as is discussed above, the first term in the bound of Theorem 4.7 quantifies the in-direction convergence of θL towards the maximum-margin solution, n e and the rate is given by Corollary 4.3. Consequently, as long as L = Ω αd , the generalization 13
e d , which matches the sample complexity lower bound bound can be given as ∥θθLL∥2 − θ ∗ 2 ≤ O n in classic PAC learning (Long, 1995). In contrast, Bai et al. (2024) constructs multi-head ReLU transformers that approximate standard gradient descent for in-context logistic regression. If similar analyses are applied to their setting, then by the implicit bias results of gradient descent (Soudry et al., 2018), their constructed model’s output approaches the maximum-margin solution only at the rate O logloglogL L . As a result, unless the depth of the model L is exponentially large in the e d , and therefore problem parameters, this term always dominates the statistical error term O n
fundamentally limits the performance in solving the weight prediction task.
5
Experiments
In this section, we present the experimental results. We consider three experimental settings: (i) training a single-layer transformer; (ii) constructing a multi-layer looped transformer from the trained layer, and evaluating its O.O.D. generalization in solving weight prediction; (iii) training a multiple-layer looped transformer from scratch, and evaluating its capacity in solving weight prediction.
5.1
Training a single-layer transformer
We first consider training a single-layer transformer to validate our Theorem 4.5. The architecture of single-layer transformer follows the definition in (3.3) with L = 1, and the training strategy aligns with the theoretical settings in Subsection 4.3. We adopt an online gradient descent algorithm to simulate training over the population loss Ltrain . Specifically, at each iteration, we generate a new batch of K = 400 context datasets {Dn,k }K k=1 , where each dataset Dn,k is generated following Definition 3.1 with Dx being N (0d , Id ) and Dθ∗ being U (Sd−1 ). For each Dn,k , we generate a corresponding θ0,k from U(Sd−1 ). Then we can obtain a batch of K input matrices {Z0,k }K k=1 embedded of the form in (3.1), and the gradient descent update in (4.3), (4.4) is conducted on this batch of inputs, with the learning rate η = 0.1. In addition, we consider two gradient descent teachers θGD with α = 0.5 and α = 1, respectively. For each case, we conduct experiments under three different configurations: (n, d) ∈ {(60, 20), (100, 25), (150, 30)}. Figure 3 reports the curves of training losses. In all settings, the training losses consistently converge near zero. Notably, configurations with a larger dimension d exhibit slower convergence. This observation aligns with our Theorem 4.5, as the linear convergence factor 1 − ηµ1,α,σ /d grows with d, thereby slowing down the optimization process. Figures 4 displays the heatmaps of the parameter matrices V(t) and W(t) obtained after training. These results demonstrate that the trained V(t) and W(t) follow the structured pattern described in Lemma 4.4: the bottom-left block of V and the top-right block of W are almost proportional to the identity matrix, with coefficients C1 > 0 and −C2 < 0, respectively, and all other blocks remain almost zero. (t) (t) Figure 5 further presents the trajectories of C(t) = [C1 , C2 ]⊤ . The trajectories exhibit clear convergence behavior, as evidenced by the dense accumulations of iterates near the end of the 2 curves. In addition, in all settings, the iterates consistently converge to points close to [αeσ /2 , 1]⊤ , aligning with the third conclusion in Theorem 4.5. The experiments in Figures 3, 4, and 5 all match our theoretical conclusions regarding the training of a single-layer transformer, validating that a single-layer transformer can be trained to
14
(a) Training loss, α = 0.5
(b) Training loss, α = 1
Figure 3: Training loss under two settings: α = 0.5, and α = 1. conduct a normalized gradient descent update.
5.2
O.O.D. generalization of looped transformers
Following our theoretical settings, we can obtain a multi-layer looped transformer by recurrently applying the trained single-layer transformer. In this section, we conduct experiments to validate the O.O.D. generalization of the resulting looped transformers in solving in-context weight prediction. To make sure that each O.O.D. setting covers significantly different distributions compared with the training data, we consider three different O.O.D. choices for Dx : we first marginally same from (i) standard Gaussian distribution N (0, 1); (ii) Laplace ple each entry of the random vector x distribution Laplace(0, 1); (iii) uniform distribution U([0, 1]), and then randomly generate a positive definite matrix Σ and obtain a sample x from Dx by calculating x = Σe x. For each choice of following exactly the same data generaDx , we generate a batch of K input matrices {Z0,k }K k=1 tion procedure as in training, except that the feature distribution is replaced by the corresponding O.O.D. distribution. For each setting, we consider feature dimensions d ∈ {20, 30}, and fix the in-context sample size as n = 500. We evaluate the performance of the looped transformers in in-context weight prediction. For better comparison, we also report the results from the iterates of NGD and standard GD under the same experimental settings. The results are given in Figure 6. Across all different settings, the discrepancy between the prediction produced by looped transformers and the ground-truth classifier θ ∗ consistently decays to a small value as the number of layers L increases, validating the capacities of deep transformers in solving in-context weight prediction. In addition, we observe that the hidden-layer outputs of the looped transformers remain very close to the iterates of NGD throughout the entire process, achieving nearly identical performance in in-context weight prediction and consistently outperforming standard GD. These observations further support our theoretical findings that multi-layer transformers can efficiently solve in-context weight prediction in in-context logistic regression via NGD.
15
(n, d) = (60, 20)
0.8
(n, d) = (60, 20)
1.00
1.00
0.6 0.4
0.50
0.2
0.25
0.5
0.25
0.0
0.00
0.0
0.00
0.2
0.25
0.4
0.50
0.6
0.75
0.8
1.00
0.8
(n, d) = (100, 25)
0.75
1.0
0.50
0.25
0.5
0.50
1.0
0.75
1.5
(b) W(t) , α = 0.5
(c) V(t) , α = 1
(d) W(t) , α = 1
(n, d) = (100, 25)
1.00
1.00
(n, d) = (100, 25) 1.5
1.00
0.6
0.75
0.4
0.50
0.2
0.25
0.5
0.25
0.0
0.00
0.0
0.00
0.2
0.25
0.4
0.50
0.6
0.75
0.8
1.00
(e) V(t) , α = 0.5
0.75
1.0
0.50
0.25
0.5
0.50
1.0
0.75
1.5
(f) W(t) , α = 0.5
(n, d) = (150, 30)
(g) V(t) , α = 1
(n, d) = (150, 30)
1.00
(h) W(t) , α = 1
(n, d) = (150, 30)
0.8
(n, d) = (150, 30) 1.5
1.00
0.6
0.75
0.4
0.50
0.2
0.25
0.5
0.25
0.0
0.00
0.0
0.00
0.2
0.25
0.5
0.4
0.50
0.6
0.75
0.75 1.0
0.50
0.25 0.50
1.0
0.75
1.5
0.8
(i) V(t) , α = 0.5
(n, d) = (60, 20) 1.5
0.75
(a) V(t) , α = 0.5 (n, d) = (100, 25)
(n, d) = (60, 20)
(j) W(t) , α = 0.5
(k) V(t) , α = 1
1.00
(l) W(t) , α = 1
Figure 4: Heatmaps of the parameter matrices V(t) and W(t) when the training loss converges. The three rows correspond to (n, d) = (60, 20), (100, 25), and (150, 30), respectively. In each row, the four panels show V(t) and W(t) under α = 0.5 and α = 1.
5.3
Training of multi-layer looped transformers
In this section, we consider training a multi-layer looped transformer from scratch. We consider ∗ d−1 to supervise the training, i.e. the training loss directly using the θground ∗truth vector θ ∈ S 2 is defined as E ∥θLL∥2 − θ 2 . Similar to the previous section, we consider using online gradient descent to minimize this training loss. In addition, each batch of inputs matrices {Z0,k }K k=1 follows the same generation process with Dx being a Gaussian distribution with a randomly generated positive definite covariance matrix Σ. We set the in-context sample size and feature dimension as (n, d) = (60, 20). The experiments are conducted under three sets of the model depth L ∈ {5, 10, 20}. The results are given in Figure 7. Since the models are trained in an online fashion, the training loss itself serves as a direct measure of the generalization performance for in-context weight prediction. Figure 7a shows that deeper models achieve lower training loss and converge faster, indicating that increasing the depth significantly improves the quality of in-context weight prediction. This behavior is consistent with our theoretical analysis, as the depth L corresponds to the number of iterations of NGD. Moreover, Figures 7b, 7c display the heatmaps of the learned parameter matrices V and W of 20-layer looped transformer. The clear block-diagonal and structured patterns closely match the pattern predicted in Theorem 4.1. These results empirically demonstrate that
16
(a) Trajectories, α = 0.5
(b) Trajectories, α = 1 (t)
(2)
Figure 5: Trajectories of the coefficient C1 and C1 α = 1.
under two different settings that α = 0.5, and
even when trained from scratch, deep looped transformers naturally learn the parameter structures required to implement in-context logistic regression.
6
Conclusions and limitations
This work provides a comprehensive analysis of how transformers with softmax attention perform ICL on linear classification data. Specifically, we construct a class of softmax transformers capable of performing in-context logistic regression. We demonstrate that these transformers can be obtained by training a single-layer model and recurrently applying the trained layer. Furthermore, we establish an O.O.D. generalization bound for the trained model in in-context weight prediction. Experimental results back up our theoretical findings, highlighting the pivotal role of transformers’ depth in ICL. There are several limitations of our analysis. First, our theory focuses on in-context linear classification with exponential loss, which is a simplified setting compared with the broad range of tasks and data distributions encountered by modern transformers. Nevertheless, this setting allows us to isolate the role of softmax attention and rigorously characterize a nontrivial algorithmic mechanism, namely the implementation and learning of normalized gradient descent. Second, our expressive-power result is established for an attention-only construction. Although this does not invalidate the conclusion for richer architectures, since additional components such as MLP layers, gated attention, and positional encodings can be parameterized so as to preserve the same input-output mapping, our analysis does not fully characterize how these components interact with the NGD mechanism during training. Lastly, while we observe in experiments that direct, end-to-end training of a multi-layer looped transformer can also give a model that matches our theoretical construction well, our theoretical training analysis currently can not directly extend to this setting. Addressing these limitations, including extending the analysis to richer architectures, broader task and data settings, and end-to-end training of multi-layer transformers, is an interesting and promising direction for future work.
17
d=20
ngd_weight_prediction gd_weight_prediction tf_weight_prediction tf_ngd_diff
* 2
1.5
1.0
L L 2
1.0
L L 2
* 2
1.5
d=30
2.0
ngd_weight_prediction gd_weight_prediction tf_weight_prediction tf_ngd_diff
0.5
0.5
0.0
0.0
0
5 10 15 20 25 Number of layers / Iterations L
30
0
(a) Gaussian data, d = 20
* 2
1.0
L L 2
* 2 L L 2
d=30 ngd_weight_prediction gd_weight_prediction tf_weight_prediction tf_ngd_diff
1.5
0.5 0.0
0
5 10 15 20 25 Number of layers / Iterations L
30
1.75 1.50 1.25 1.00 0.75 0.50 0.25 0.00
ngd_weight_prediction gd_weight_prediction tf_weight_prediction tf_ngd_diff
0
(c) Laplace data, d = 20
30
d=30
2.0
ngd_weight_prediction gd_weight_prediction tf_weight_prediction tf_ngd_diff
ngd_weight_prediction gd_weight_prediction tf_weight_prediction tf_ngd_diff
* 2
1.5 1.0 L L 2
* 2 L L 2
5 10 15 20 25 Number of layers / Iterations L (d) Laplace data, d = 30
d=20 1.75 1.50 1.25 1.00 0.75 0.50 0.25 0.00
30
(b) Gaussian data, d = 30
d=20 2.0
5 10 15 20 25 Number of layers / Iterations L
0.5
0
5 10 15 20 25 Number of layers / Iterations L
0.0
30
(e) Uniform data, d = 20
0
5 10 15 20 25 Number of layers / Iterations L
30
(f) Uniform data, d = 30
Figure 6: Evaluation of the in-context weight-prediction produced by looped transformers, NGD iterates, and standard GD iterates on different O.O.D distributed context datasets, with d ∈ {20, 30}.
18