<?xml-model href='http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng' schematypens='http://relaxng.org/ns/structure/1.0'?><TEI xmlns="http://www.tei-c.org/ns/1.0">
	<teiHeader>
		<fileDesc>
			<titleStmt><title level='a'>On the Training Convergence of Transformers for In-Context Classification of Gaussian Mixtures</title></titleStmt>
			<publicationStmt>
				<publisher>Forty-Second International Conference on Machine Learning</publisher>
				<date>07/21/2025</date>
			</publicationStmt>
			<sourceDesc>
				<bibl> 
					<idno type="par_id">10631700</idno>
					<idno type="doi"></idno>
					
					<author>W Shen</author><author>R Zhou</author><author>C Shen</author><author>J Yang</author>
				</bibl>
			</sourceDesc>
		</fileDesc>
		<profileDesc>
			<abstract><ab><![CDATA[Although transformers have demonstrated impressive capabilities for in-context learning (ICL) in practice, theoretical understanding of the underlying mechanism that allows transformers to perform ICL is still in its infancy. This work aims to theoretically study the training dynamics of transformers for in-context classification tasks. We demonstrate that, for in-context classification of Gaussian mixtures under certain assumptions, a single-layer transformer trained via gradient descent converges to a globally optimal model at a linear rate. We further quantify the impact of the training and testing prompt lengths on the ICL inference error of the trained transformer. We show that when the lengths of training and testing prompts are sufficiently large, the prediction of the trained transformer approaches the ground truth distribution of the labels. Experimental results corroborate the theoretical findings.]]></ab></abstract>
		</profileDesc>
	</teiHeader>
	<text><body xmlns="http://www.tei-c.org/ns/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink">
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="1.">Introduction</head><p>Large language models (LLMs) based on the transformer architecture <ref type="bibr">(Vaswani et al., 2017)</ref> have demonstrated remarkable in-context learning (ICL) abilities <ref type="bibr">(Brown et al., 2020)</ref>. When given a prompt consisting of examples of a learning task, these models can learn to solve this task for new test examples without any parameter updating. This behavior has been empirically demonstrated in state-of-the-art models on real-world tasks <ref type="bibr">(OpenAI, 2023;</ref><ref type="bibr">Touvron et al., 2023)</ref>. This impressive capacity of transformer-based models has inspired many recent works aiming to understand the ICL abilities of transformers. A more comprehensive literature review can be found in Appendix A. <ref type="bibr">Garg et al. (2022)</ref> was the first to study the ICL abilities of transformers for various function classes. They empirically showed that transformers can learn linear regression models in context. Later on, a line of research was developed to theoretically explain how transformers perform in-context linear regression. For example, <ref type="bibr">Aky&#252;rek et al. (2022)</ref>; Von <ref type="bibr">Oswald et al. (2023)</ref>; <ref type="bibr">Bai et al. (2024)</ref>; <ref type="bibr">Fu et al. (2023)</ref>; <ref type="bibr">Giannou et al. (2024)</ref> showed by construction that, some specially-designed transformers can perform linear regression in context. Moreover, some recent works such as <ref type="bibr">Zhang et al. (2023a)</ref>; <ref type="bibr">Huang et al. (2023)</ref>; <ref type="bibr">Chen et al. (2024)</ref> studied the training dynamics of a singlelayer transformer for in-context linear regression. They proved the convergence of certain single-layer transformers during training and showed that the trained transformers are able to perform linear regression in context.</p><p>Building on the earlier works that largely focus on linear regression problems, several recent papers have started to investigate the ICL capabilities of transformers for classification problems. For instance, <ref type="bibr">Bai et al. (2024)</ref> showed that, by construction, multi-layer transformers can be approximately viewed as multiple steps of gradient descents for logistic regression. <ref type="bibr">Giannou et al. (2024)</ref> further showcased that the constructed transformers can approximately perform Newton's method for logistic regression. <ref type="bibr">Lin &amp; Lee (2024)</ref> studied the dual operating modes for in-context classification of Gaussian mixtures. However, their analyses were based on the idealized Bayes-optimal next-token predictor for ICL tasks and did not consider the training dynamics of transformer models. Some recent works have started to study the training dynamics of transformers for certain classification problems. For example, <ref type="bibr">Li et al. (2024b)</ref> proved that a single-layer transformer can be trained to learn one-nearest neighbor in context. <ref type="bibr">Li et al. (2024a)</ref> studied the training dynamics of a single-layer transformer for some binary classification tasks with finite, pairwise orthogonal patterns. <ref type="bibr">Frei &amp; Vardi (2024)</ref> analyzed a linear transformer model for in-context classification of Gaussian mixtures, assuming additional conditions such as a sufficiently large signal-to-noise ratio. However, all these works <ref type="bibr">(Li et al., 2024a;</ref><ref type="bibr">b;</ref><ref type="bibr">Frei &amp; Vardi, 2024)</ref> only considered the binary classification problems. The training dynamics of transformers for more general in-context classification problems beyond the specific settings and assumptions in <ref type="bibr">Li et al. (2024a;</ref><ref type="bibr">b)</ref>; <ref type="bibr">Frei &amp; Vardi (2024)</ref> remain largely underexplored.</p><p>In this work, we study the training dynamics of a singlelayer transformer for both binary and multi-class classification of Gaussian mixtures during ICL, a fundamental problem in machine learning. Our main contributions can be summarized as follows:</p><p>&#8226; We prove that with appropriately distributed training data (Assumptions 3.2, 4.2), a single-layer transformer trained via gradient descent will converge to its global minimizer at a linear rate <ref type="bibr">(Theorems 3.3,</ref><ref type="bibr">4.</ref>3) for both in-context binary or multi-class classification problems. To the best of our knowledge, we are the first to prove the training convergence of transformers for in-context multi-class classification. Moreover, our analysis reveals that the trained single-layer transformer can be viewed as approximately implementing linear discriminant analysis (LDA). &#8226; Due to the non-linearity of our loss function, we cannot directly find the closed-form expression of the global minimizer. Instead, we prove an important property that the global minimizer consists of a constant plus an error term that is induced by the finite training prompt length (N ). We further show that the max norm of this error term is bounded, and converges to zero at a rate of O(1/N ). &#8226; With properly distributed testing prompts (Assumptions 3.5, 4.4), we establish an upper bound of the inference error (defined in Equation ( <ref type="formula">3</ref>)) of the trained transformer and quantify the impact of the training and testing prompt lengths on this error. We further prove that when the lengths of training prompts (N ) and testing prompts (M ) approach infinity, this error converges to zero at a rate of O(1/N + 1/ &#8730; M ) , and the prediction of the trained transformer has an identical distribution to that of the ground-truth label (Theorems 3.6, 4.5).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.">Preliminaries</head><p>Notations. We denote [n] = {1, 2, . . . , n}. For a matrix A &#8712; R m&#215;n , we denote its Frobenius norm as &#8741;A&#8741; F , and its max norm as &#8741;A&#8741; max = max i&#8712;[m],j&#8712; <ref type="bibr">[n]</ref> |A ij |. We use A a,b (or A ab ) to represent the element of matrix A at the a-th row and b-th column, and use A a:c,b to represent a vector of dimension c -a + 1 whose i-th element is A (a+i-1),b . We denote the l 2 norm of a vector as &#8741; &#8226; &#8741; 2 . We denote the all-zero vector of size n as 0 n and the all-zero matrix of size m &#215; n as 0 m&#215;n . We use &#963;(x) := 1/(1 + exp(-x)) to denote the sigmoid function. We define softmax(&#8226;) : R k &#8594; (0, 1) k , and its i-th element as softmax(&#8226;) i , where softmax(x) i = exp(x i )/( k j=1 exp(x j )).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.1.">Single-layer transformer</head><p>Given an input embedding matrix E &#8712; R de&#215;dn , a single head self-attention module F SA with width d e will output</p><p>where W V , W K , W Q &#8712; R de&#215;de are the value, key, and query weight matrices, respectively, &#961; &gt; 0 is a normalization factor, and f attn is an activation function for attention.</p><p>There are different choices of f attn ; for example <ref type="bibr">Vaswani et al. (2017)</ref> adopts softmax.</p><p>In this work, similar to <ref type="bibr">Zhang et al. (2023a)</ref>; <ref type="bibr">Wu et al. (2023)</ref>, we set f attn (x) = x and define W KQ = (W K ) &#166; W Q &#8712; R de&#215;de . We use F to denote this simplified model. Then, the output of F with an input embedding matrix E &#8712; R de&#215;dn can be expressed as</p><p>In the following theoretical study and the subsequent experiments (Section 5.2), we show that this simplified transformer model has sufficient capability to approach the optimal classifier for the in-context classification of Gaussian mixtures.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.2.">In-context learning framework</head><p>We adopt a framework for in-context learning similar to that used in <ref type="bibr">Bai et al. (2024)</ref>. Under this framework, the model receives a prompt P = (D, x query ) comprising a set</p><p>&#8764; P and a query x query &#8764; P x , where P is the joint distribution of (x, y) and P x is the marginal distribution of x. Here, x i &#8712; R d is an in-context example, and y i is the corresponding label for x i . For instance, in regression tasks, y i &#8712; R is a scalar. In this paper, we focus on classification tasks. Thus, the range of y i can be any set containing c different elements, such as {1, . . . , c}, for classification problems involving c classes. The objective is to generate an output y query that approximates the target y query &#8764; P y|xquery .</p><p>Since y query is a discrete random variable, we use the total variation distance to measure the difference between y query and y query :</p><p>where R(y query ) is the range of y query .</p><p>When &#8710;(y query , y query ) = 0, y query has the same distribution as y query , which means the output of the model perfectly approximates y query .</p><p>Unlike standard supervised learning, each prompt P &#964; can be sampled from a different distribution P &#964; in ICL. We say that a model has the ICL capability if it can approximate y &#964;,query for a broad range of P &#964; 's with fixed parameters.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.">In-context binary classification</head><p>In this section, we study the learning dynamics of a singlelayer transformer for in-context binary classification. It is a special case of the general multi-class classification. As a result, the analysis is more concise. The general in-context multi-class classification problem is studied in Section 4.</p><p>We first introduce the prompt and the transformer structure we will use for in-context binary classification. The prompt for in-context binary classification is denoted as P = (x 1 , y 1 , . . . , x N , y N , x query ), where x i &#8712; R d and y i &#8712; {-1, 1}. We can convert this prompt P into its corresponding embedding matrix E(P ) in the following form:</p><p>Similar to <ref type="bibr">Huang et al. (2023)</ref>; <ref type="bibr">Wu et al. (2023)</ref>; <ref type="bibr">Ahn et al. (2024)</ref>, we set some of the parameters in our model to 0 or 1 to simplify the optimization problem, and consider the parameters of our model (W V , W KQ ) in the following sparse form:</p><p>where W &#8712; R d&#215;d . We set the normalization factor &#961; equal to the length of the prompt N . Let F (E(P ); W ) be the output matrix of the transformer. We then read out the bottom-right entry of the output matrix through a sigmoid function, and denote this output as y out . The output y out of the transformer with prompt P and parameters W can be expressed as</p><p>We denote the prediction of our model for x query as y query , which is a random variable depending on y out . Consider generating a random variable u uniformly on [0, 1]. If u f y out , we output y query = 1; if u &gt; y out , we output y query = -1. Then, we have P ( y query = 1) = y out , P ( y query = -1) = 1 -y out .</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.1.">Training procedure</head><p>We study the binary classification of two Gaussian mixtures and use the following definition.</p><p>Definition 3.1. We say a data pair (x, y) &#8764; P b (&#181; 0 , &#181; 1 , &#923;) if y follows a Bernoulli distribution with P (y = -1) = P (y = 1) = 1/2 and f (x|y = -1) = N(&#181; 0 , &#923;), f (x|y = 1) = N(&#181; 1 , &#923;), where &#181; 0 , &#181; 1 &#8712; R d and &#923; &#8712; R d&#215;d is a positive definite matrix.</p><p>We consider the case of B training tasks indexed by &#964; &#8712; [B].</p><p>Each training task &#964; is associated with a prompt P &#964; = (x &#964;,1 , y &#964;,1 , . . . , x &#964;,N , y &#964;,N , x &#964;,query ) and a corresponding label y &#964;,query . We make the following assumption in this section.</p><p>Assumption 3.2. For each learning task &#964; &#8712; [B], we assume</p><p>(1) {x &#964;,i , y &#964;,i } N i=1 and {x &#964;,query , y &#964;,query } i.i.d.</p><p>, and U &#964; is uniformly distributed over the closed set of real unitary matrices such that</p><p>We denote the distribution of (&#181; &#964;,0 , &#181; &#964;,1 ) as P b &#8486; (&#923;). Note that U &#964;,&#923; = &#923; 1/2 U &#964; &#923; -1/2 can be viewed as a linear transformation that preserves the inner product of vectors in &#923; -1weighted norm, and we have &#181;</p><p>) ) be the output of our transformer for task &#964; . We define the empirical risk over B independent tasks as</p><p>Taking the limit of infinite training tasks B &#8594; &#8734;, the expected training loss can be defined as</p><p>where the expectation is taken over</p><p>Applying gradient descent over the expected training loss (7), we have the following theorem.</p><p>Theorem 3.3. Under Assumption 3.2, the following statements hold.</p><p>(1) Optimizing the training loss L(W ) in Equation <ref type="bibr">(7)</ref> with training prompt length N via gradient descent W t+1 = W t -&#951;&#8711;L(W t ), we have that for any t g 1,</p><p>where W 0 is the initial parameter and W * is the global minimizer of L(W ), and &#954; = l/&#945;. Here &#945;, l are constants satisfying</p><p>), and a = &#181; &#166; &#923; -1 q for simplicity. Then we have</p><p>where S = 4&#8711; 2 L(2&#923; -1 ), L(2&#923; -1 ) = lim N &#8594;&#8734; L(2&#923; -1 ), &#963; &#8242; (&#8226;) and &#963; &#8242;&#8242; (&#8226;) are the firstand second-order derivatives of &#963;(&#8226;), respectively, and the expectation is taken over</p><p>The detailed proof of Theorem 3.3 can be found in Appendix D. In the following, we provide a brief proof sketch to highlight the key ideas.</p><p>Proof sketch for Theorem 3.3. As a first step, we prove in Lemma D.2 that the expected loss function L(W ) in Equation ( <ref type="formula">7</ref>) is strictly convex with respect to (w.r.t.) W and is strongly convex in any compact set of R d&#215;d . Moreover, we prove L(W ) has one unique global minimizer W * . Since the loss function L(W ) we consider is highly non-linear, we cannot directly find the closed-form expression of W * , as is often done in the prior literature. This poses a significant challenge to our analysis.</p><p>We address this technical challenge via the following method. First, in Lemma D.3, by analyzing the Taylor expansion of L(W ), we prove that as N &#8594; &#8734;, our loss function L(W ) converges to L(W ) pointwisely (defined in Equation ( <ref type="formula">25</ref>)), and the global minimizer W * converges to 2&#923; -1 . Thus, we denote W * = 2(&#923; -1 + G), and prove &#8741;G&#8741; max is bounded and scales as</p><p>Next, in Lemma D.4, by further analyzing the Taylor expansion of the equation &#8711;L(W * ) = 0 at the point 2&#923; -1 , we establish a tighter bound &#8741;G&#8741; max = O(N -1 ). In Lemma D.5, we prove that our loss function is l-smooth and provide an upper bound for l. Thus, in a compact set R W , our loss function is &#945;-strongly convex and l-smooth. Finally, leveraging the standard results from the convex optimization, we prove Theorem 3.3.</p><p>According to Theorem 3.3, we have</p><p>). Thus, we have the following corollary.</p><p>Corollary 3.4. If we optimize the expected loss L(W ) in Equation (7) via gradient descent with training prompt length N , initial parameters W 0 , and learning rate &#951; = 1/l, then, under Assumption 3.2, after T g 2&#954; log(N &#8741;W 0 -W * &#8741; F ) steps, the updated model W satisfies</p><p>where &#8741; G&#8741; max = O(1/N ), &#954; = l/&#945;, and &#945;, l are constants defined in (9).</p><p>Theorem 3.3 and Corollary 3.4 show that training a singlelayer transformer with properly distributed data (Assumption 3.2) for binary classification via gradient descent can linearly converge to its global minimum W * = 2(&#923; -1 +G). Furthermore, when the prompt length N grows, this global minimum W * will converge to 2&#923; -1 at a rate of O(1/N ).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.2.">In-context inference</head><p>Next, we analyze the performance of the trained transformer in Equation ( <ref type="formula">11</ref>) for in-context binary classification tasks. We make the following assumption.</p><p>Assumption 3.5. For an in-context test prompt P test = (x 1 , y 1 , . . . , x M , y M , x query ), we assume</p><p>With this assumption, for y query &#8764; P b y|xquery (&#181; 0 , &#181; 1 , &#923;), according to the Bayes' theorem, we have P (y query = 1|x query ) = f (x query |y query = 1)P (y query = 1)</p><p>If we test the trained transformer with parameters W in Equation ( <ref type="formula">11</ref>) and P test , by a simple calculation, we have</p><p>Intuitively, when the training prompt length N &#8594; &#8734;, we have G &#8594; 0, and when the test prompt length M &#8594; &#8734;, we have 2 M M i=1 y i x &#166; i &#8594; (&#181; 1 -&#181; 0 ) &#166; . Thus, when N, M &#8594; &#8734;, P ( y query = 1) = y out &#8594; &#963;((&#181; 1 -&#181; 0 ) &#166; &#923; -1 x query ) = P (y query = 1|x query ), and the prediction of the trained transformer y query perfectly matches with the distribution of the ground truth label y query .</p><p>By analyzing the Taylor expansion of y out at point &#963;((&#181; 1&#181; 0 ) &#166; &#923; -1 x query ), we formally present the aforementioned intuition in the following theorem, which establishes an upper bound of the total variation distance between y query and y query . Theorem 3.6. Consider a test prompt P test satisfying Assumption 3.5, and let y query &#8764; P b y|xquery (&#181; 0 , &#181; 1 , &#923;). Let y query be the prediction of the trained transformer with parameters W in Equation (11). Then, for the inference error defined in Equation (3), we have</p><p>where &#181; = &#181; 1 -&#181; 0 , u = 2(&#181; 1 + &#181; 0 ), q = x query , and the expectation is taken over</p><p>The proof of Theorem 3.6 can be found in Appendix E. Since &#8741; G&#8741; max = O(1/N ), Theorem 3.6 suggests that if we ignore the constants regarding &#181; 0 , &#181; 1 , &#923;, x query , the expected total variation distance between y query and y query is at most O(1/N + 1/ &#8730; M ). On the other hand, for data pair (x, y) &#8764; P b (&#181; 0 , &#181; 1 , &#923;), the distribution of y, P (y = 1|x) = &#963;((&#181; 1 -&#181; 0 ) &#166; &#923; -1 x), can be characterized by a logistic regression model &#963;(w &#166; x + b) with parameters w = &#923; -1 (&#181; 1 -&#181; 0 ) and b = 0. Therefore, when N, M &#8594; &#8734;, the prediction of the trained transformer is equivalent to the optimal logistic regressor for binary classification problems with distribution P b (&#181; 0 , &#181; 1 , &#923;).</p><p>Note that different from Assumption 3.2 which states that &#181; &#964;,0 , &#181; &#964;,1 , x &#964;,query are sampled according to some specific distributions during training, Assumption 3.5 does not impose strong distributional constraints on &#181; 0 , &#181; 1 and x query , which shows the strong generalization ability of the trained transformer. Moreover, even if M &#8594; &#8734;, the distribution variation between y query and y query does not disappear unless N &#8594; &#8734;. Thus, the ICL ability of trained transformers for binary classification is limited by the finite length of training prompts. Similar behaviors have also been observed in <ref type="bibr">Zhang et al. (2023a)</ref> for in-context linear regression. Remark 3.7. Theorem 3.6 requires Assumption 3.5 to hold. For example, we need the covariance matrix &#923; in training and testing to be the same. A similar consistency requirement of &#923; in training and testing had also been observed for in-context linear regression in <ref type="bibr">Zhang et al. (2023a)</ref>. Here, we discuss the consequences when Assumption 3.5 does not hold. For example, suppose the labels of our data in test prompts are not balanced where P (y = 1) = p 1 , P (y = -1) = p 0 . Besides, &#181; 0 , &#181; 1 do not have the same &#923; -1 weighted norm, and the covariance matrix of test data satisfies &#915; &#824; = &#923;. Then, as N, M &#8594; &#8734;, we have</p><p>On the other hand, the distribution of the ground truth label is</p><p>x query . Then, we can see that unless &#7825; = z or |&#963;(&#7825;) -&#963;(z)| is sufficiently small, the transformer cannot correctly perform the in-context binary classification. Remark 3.8. Another important insight of our analysis is that the pre-trained single-layer transformer can be viewed as approximately implementing linear discriminant analysis (LDA). For example, suppose we are given {x i , y i } M i=1 and x query , and we need to predict the label y query for x query . LDA assumes that {x i , y i } M i=1 and {x query , y query } are i.i.d. samples, with P (y i = 1) = P (y i = -1), and the conditional probability density functions f (x i |y i = 1) and f (x i |y i = -1) are Gaussian with means &#181; 1 , &#181; -1 and same covariance &#931;. Under these assumptions, it can be derived that the optimal decision criterion for x query is to predict</p><p>1 &#931; -1 &#181; 1 ) &gt; 0 and y query = -1, otherwise. LDA can estimate &#956;1 as the average of x i with y i = 1, estimate &#956;-1 as the average of x i with y i = -1, and estimate the covariance &#931; from the within-class variances. For the singlelayer transformer, it can compute the in-context estimate &#956;1 -&#956;-1 = 1 M M i=1 y i x i , however, it is hard for the singlelayer transformer to estimate &#931; in context. Thus, in our paper, we make the following assumptions (Assumptions 3.2 and 3.5). We assume the pre-train data and test data have the same covariance matrix &#923; so that the transformer can learn an approximation of &#923; during pre-training. Moreover, we assume the two class means &#181; 0 , &#181; 1 have the same &#923;-weighted norm so that &#181;</p><p>Under these assumptions, the quadratic term cancels out, and the estimated decision criterion simplifies to</p><p>x query , which is very close to Equation (12) in our paper. When we use W to approximate 2&#923; -1 , the estimated decision criterion becomes exactly Equation ( <ref type="formula">12</ref>). Therefore, when W = 2&#923; -1 and the in-context examples are balanced across classes, the transformer's decision criterion is the same as that of the LDA with exact knowledge of &#923;. Our experiments also corroborate this theoretical findings. For example, in Figure <ref type="figure">3</ref>, since the pre-trained transformer has already learned a relatively good approximation of &#923; -1 , while LDA must estimate &#923; -1 in context, the trained transformer significantly outperforms LDA when the number of in-context examples is small. As the context length increases, LDA's performance approaches that of the trained transformer.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4.">In-context multi-class classification</head><p>We now extend the study of the learning dynamics of a single-layer transformer to in-context multi-class classification, generalizing the results of the previous section. We will present the detailed formulation and then focus on the main differences to binary classification.</p><p>We first introduce the prompt and the transformer structure that will be used for in-context multi-class classification. The prompt for in-context multi-class classification involving c g 2 classes can be expressed as</p><p>. . , e c }, and e i is the i-th standard unit vector of R c . Its embedding matrix can be formulated as</p><p>Similar to the binary case, we set some of the parameters in our model as 0 and 1 to simplify the optimization problem and consider the parameters of our model (W V , W KQ ) in the following sparse form:</p><p>where W &#8712; R d&#215;d . We set the normalization factor &#961; equal to the length of the prompt N . We read out the bottom-right c-dimensional column vector from the output matrix with a softmax function as the output, denoted as y out . With parameters W and a prompt P = (x 1 , y 1 , . . . , x N , y N , x query ), the output can be expressed as</p><p>We denote the prediction of the model for x query as y query , which is a random variable depending on y out . Randomly sample a random variable u that is uniformly distributed on</p><p>, where ( y out ) j is the j-th element of y out , we let y query = e i . Thus, P ( y query = e i ) = ( y out ) i .</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4.1.">Training procedure</head><p>We focus on the multi-class classification of Gaussian mixtures and use the following definition.</p><p>Definition 4.1. We say a data pair (x, y) &#8764; P m (&#181;, &#923;) if</p><p>We consider the case of B training tasks indexed by &#964; &#8712;</p><p>Each training task &#964; is associated with a prompt P &#964; = (x &#964;,1 , y &#964;,1 , . . . , x &#964;,N , y &#964;,N , x &#964;,query ) and a corresponding label y &#964;,query . We make the following assumption in this section.</p><p>Assumption 4.2. For each learning task &#964; &#8712; [B], we assume:</p><p>(1) {x &#964;,i , y &#964;,i } N i=1 and {x &#964;,query , y &#964;,query } i.i.d.</p><p>, and U &#964;,k are uniformly distributed over the closed set of real unitary matrices such that</p><p>We denote the distribution of &#181; &#964; as P m &#8486; (&#923;). Note that U &#964;,k,&#923; = &#923; 1/2 U &#964;,k &#923; -1/2 can be viewed as linear transformation that preserves the inner product of vectors in the &#923; -1 weighted norm, and we have</p><p>Let y &#964;,out = softmax [F (E(P &#964; ); W )] (d+1):(d+c),(N +1) be the output of the transformer for task &#964; . We define the empirical risk over B independent tasks as</p><p>Taking the limit of infinite training tasks B &#8594; &#8734;, the expected training loss can be defined as</p><p>where the expectation is taken over</p><p>Applying gradient descent over the expected training loss in Equation ( <ref type="formula">16</ref>), we have the following theorem.</p><p>Theorem 4.3. (Informal) Under Assumption 4.2, the following statements hold.</p><p>(1) Optimizing training loss L(W ) in Equation ( <ref type="formula">16</ref>) with training prompt length N via gradient descent W t+1 = W t -&#951;&#8711;L(W t ), for any t g 1, we have <ref type="formula">17</ref>) where W 0 is the initial parameter and W * is the global minimizer of L(W ), &#954; = l/&#945;. Here, &#945;, l are constants such that</p><p>where</p><p>The formal statement and complete proof of Theorem 4.3 can be found in Appendix F. Technically, the proof of Theorem 4.3 builds on that of Theorem 3.3, but the more complicated cross terms in the Taylor expansions of the softmax functions, which are due to the nature of multi-class classification, bring new challenges to the analysis. To address these issues, we derive new bounds on the expected errors of the cross terms in Lemma F.1, F.2, which may be of independent interest to other similar problems.</p><p>Theorem 4.3 shows that training a single-layer transformer with properly distributed data (Assumption 4.2) for incontext multi-class classification via gradient descent can linearly converge to its global minimum</p><p>When the prompt length N grows, this global minimum W * will converge to c&#923; -1 at a rate of O(c/N ). Compared to the binary case, the new results establish the scaling behavior w.r.t. the number of classes c.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4.2.">In-context inference</head><p>Assumption 4.4. For an in-context test prompt</p><p>With this assumption, for y query &#8764; P m y|xquery (&#181;, &#923;), according to the Bayes' theorem, we have If we test the trained transformer with parameters W in Equation ( <ref type="formula">19</ref>) and prompt P test , by a simple calculation, we have</p><p>Note that, when the training prompt length N &#8594; &#8734;, we have G &#8594; 0, and when the test prompt length M &#8594; &#8734;,</p><p>, the prediction of the trained transformer y query matches the ground truth label y query .</p><p>By analyzing the Taylor expansion of y out at point softmax(&#181; &#166; &#923; -1 x query ), we crystallize the aforementioned intuition in the following theorem, which establishes an upper bound of the total variation distance between y query and y query .</p><p>Theorem 4.5. (Informal) Let P test satisfy Assumption 4.4 and y query &#8764; P m y|xquery (&#181;, &#923;). Denote y query as the prediction of the trained transformer with parameter W in <ref type="bibr">Equation (19)</ref>. Then, for the inference error defined in Equation (3), we have</p><p>where the expectation is taken over {x i , y i } M i=1 i.i.d.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>&#8764; P m (&#181;, &#923;).</head><p>The formal statement and proof of Theorem 4.5 can be found in Appendix G. We can see that the convergence rate of the inference error in multi-class classification w.r.t. N and M is similar to that in the binary classification, except for the constant coefficient c. This suggests that classification tasks with more classes may have higher errors than those with fewer classes. On the other hand, for data pair (x, y) &#8764; P m (&#181;, &#923;), the distribution of y,</p><p>the prediction of the trained transformer is equivalent to the optimal softmax regressor for multi-class classification problems with distribution P m (&#181;, &#923;). Note that different from Assumption 4.2 which states that &#181; &#964; , x &#964;,query are sampled according to some specific distributions during training, Assumption 4.4 does not impose strong distributional constraints on &#181; or x query , which shows the strong generalization ability of the trained transformer. We also discuss the consequences when Assumption 4.4 does not hold in Remark G.2, which highlights the necessity of Assumption 4.4. Moreover, even if M &#8594; &#8734;, the distribution variation between y query and y query does not disappear unless N &#8594; &#8734;. Thus, the ICL ability of the trained transformers for multi-class classification is limited by the finite length of training prompts. Similar behavior has also been observed in Zhang et al. (2023a) for in-context linear regression and in Section 3.2 for in-context binary classification.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="5.">Experiments</head><p>In this section, we report the experiment results on multilayer, nonlinear transformers to investigate their similarities and differences to the single-layer, linear transformer we theoretically analyzed in the pervious sections. Detailed experimental settings and additional results can be found in Appendix H.</p><p>We train single-layer and multi-layer transformers for incontext classification of Gaussian mixtures with different numbers of Gaussian mixtures c, different lengths of training prompts N , and test them with different test prompt lengths M . The results are reported in Figure <ref type="figure">1</ref>. We can see that for both single-layer and multi-layer transformers, the inference errors decrease as N and M increase, and they increase as c increases, which not only verifies our theoretical claims but also shows that, the simplified model we have studied indeed exhibits behavioral similarities to the more complex multi-layer, nonlinear transformers, and some of our observations for this simplified model also hold for more complex transformers.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="5.1.">Varying covariances and norms</head><p>Note that in Assumption 3.2, 4.2, 3.5, 4.4, we assume that the covariance &#923; during pre-training and during inference are the same, and the means of all Gaussian components From Figure <ref type="figure">2</ref> (a), we can see that both models perform better when their &#181; &#964;,i have the same &#923; -1 weighted norm ('same norm'), however, in the 'different norms' setting, the performance of '1-layer' deteriorates more significantly, while transformers with a more complex structure ('3-layer') show better robustness under this distribution shift. Similar situations also happen in Figure <ref type="figure">2</ref> (b), where '3-layer' also shows better tolerance to the covariance shifts than '1-layer'.</p><p>Experimental results in Figure <ref type="figure">2</ref> show the necessities of Assumptions 3.2, 4.2, 3.5, 4.4 for the single-layer transformers considered in this paper, and also demonstrate the better robustness of multi-layer, nonlinear transformers. Developing a better understanding of the robustness of more complex transformers is an intriguing direction for future research.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="5.2.">Comparison of transformers with other ML algorithms</head><p>Additionally, we conduct experiments comparing the ICL performances of the transformers with other machine learning algorithms for the classification of three Gaussian mixtures. From Figure <ref type="figure">3</ref>, we can see that all three transformer models significantly outperform the classical methods (softmax regression, linear discriminant analysis), demonstrating the strong ICL capacities of transformers.  </p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="6.">Conclusion</head><p>We studied the learning dynamics of transformers for incontext classification of Gaussian mixtures, and showed that with properly distributed data, a single-layer transformer trained via gradient descent converges to its global minimum. Moreover, we established the upper bounds of the inference errors of the trained transformers and discussed how the training and test prompt lengths influence the performance of the model. Experimental results also corroborated the theoretical claims. There are some directions worth further exploring. One potential avenue is to investigate whether the assumptions regarding the training and test prompts can be relaxed. Additionally, we have only ex-amined single-layer transformers with linear attention and sparse parameters. The learning dynamics of multi-layer transformers with nonlinear attention (e.g., softmax) for incontext classification problems remain an interesting area for future investigation.</p><p>It has been observed that transformer-based models have impressive ICL abilities in natural language processing <ref type="bibr">(Brown et al., 2020;</ref><ref type="bibr">Nye et al., 2021;</ref><ref type="bibr">Wei et al., 2022;</ref><ref type="bibr">Dasgupta et al., 2022;</ref><ref type="bibr">Zhang et al., 2022)</ref>. <ref type="bibr">Garg et al. (2022)</ref> first initiated the study of the ICL abilities of transformers in a mathematical framework and they empirically showed that transformers can in-context learn linear regression, two-layer ReLU networks, and decision trees. Subsequently, numerous works have been developed to explain the ICL capacities of transformers in solving in-context mathematical problems. These works mainly use two approaches: constructing specific transformers capable of performing certain in-context learning tasks, and studying the training dynamics of transformers for such tasks.</p><p>Constructions of transformers. <ref type="bibr">Aky&#252;rek et al. (2022)</ref>; Von <ref type="bibr">Oswald et al. (2023)</ref> showed by construction that multi-layer transformers can be viewed as multiple steps of gradient descent for linear regression. <ref type="bibr">Aky&#252;rek et al. (2022)</ref> also showed that constructed transformers can implement closed-form ridge regression. <ref type="bibr">Guo et al. (2023)</ref> showed that constructed transformers can perform in-context learning with representations. <ref type="bibr">Bai et al. (2024)</ref> proved that constructed transformers can perform various statistical machine learning algorithms through in-context gradient descent and showed that constructed transformers can perform in-context model selection. <ref type="bibr">Lin et al. (2023)</ref> demonstrated that constructed transformers can approximate several in-context reinforcement learning algorithms. <ref type="bibr">Fu et al. (2023)</ref>; <ref type="bibr">Giannou et al. (2024)</ref> further proved that constructed transformers can perform higher-order optimization algorithms like Newton's method. <ref type="bibr">Pathak et al. (2023)</ref> showed that transformers can learn mixtures of linear regressions. <ref type="bibr">Giannou et al. (2023)</ref> proved that looped transformers that can emulate various in-context learning algorithms. <ref type="bibr">Cheng et al. (2023)</ref> showed that transformers can perform functional gradient descent for learning non-linear functions in context. <ref type="bibr">Zhang et al. (2024)</ref> showed that a linear attention layer followed by a linear layer can learn and encode a mean signal vector for in-context linear regression.</p><p>Training dynamics of transformers. <ref type="bibr">Mahankali et al. (2023)</ref>; <ref type="bibr">Ahn et al. (2024)</ref> proved that the global minimizer of the in-context learning loss of linear transformer can be equivalently viewed as one-step preconditioned gradient descent for linear regression. <ref type="bibr">Zhang et al. (2023a)</ref> proved the convergence of gradient flow on a single-layer linear transformer and discussed how training and test prompt length will influence the prediction error of transformers for linear regression. <ref type="bibr">Huang et al. (2023)</ref> proved the convergence of gradient descent on a single-layer transformer with softmax attention with certain orthogonality assumptions on the data features. <ref type="bibr">Li et al. (2023c)</ref> showed that trained transformers can learn topic structure. <ref type="bibr">Wu et al. (2023)</ref> analyzed the task complexity bound for pretraining single-layer linear transformers on in-context linear regression tasks. <ref type="bibr">Tarzanagh et al. (2023)</ref> built the connections between single-layer transformers and support vector machines (SVMs). <ref type="bibr">Nichani et al. (2024)</ref> showed that transformers trained via gradient descent can learn causal structure. <ref type="bibr">Chen et al. (2024)</ref> proved the convergence of gradient flow on a multi-head softmax attention model for in-context multi-task linear regression. <ref type="bibr">Kim &amp; Suzuki (2024)</ref>; <ref type="bibr">Yang et al. (2024)</ref> proved that trained transformers can learn nonlinear features in context. <ref type="bibr">Bu et al. (2024)</ref> studied the training convergence of transformer for tasks encoded with multiple cross-concept semantics. <ref type="bibr">Li et al. (2024b)</ref> proved that a one-layer transformer can be trained to learn one-nearest neighbor for binary classification in context. <ref type="bibr">Li et al. (2024a)</ref> studied the training dynamics of a single layer transformer for in-context classification problems. However, they only studied the binary classification tasks with finite patterns. They generated their data as x = &#181; j + &#954;v k , where {&#181; j } M1 j=1 are in-domain-relevant patterns and {&#957; k } M2 k=1 are in-domain-irrelevant patterns, M 1 g M 2 and these patterns are all pairwise orthogonal. Thus, the possible distribution of their data is finite and highly limited. In contrast, our work explores the ICL capabilities of transformers for both binary and multi-class classification of Gaussian mixtures. Specifically, our data is drawn according to P b (&#181; 0 , &#181; 1 , &#923;) or P m (&#181;, &#923;), and the range and possible distributions of our data are infinite. Recently, <ref type="bibr">(Frei &amp; Vardi, 2024</ref>) also studied the the ICL of a linear transformer model for classifying Gaussian mixtures and showed that trained transformers can exhibit benign overfitting in-context. However, their analysis relies on additional assumptions, such as a sufficiently large signal-to-noise ratio. In contrast, our work does not rely on such assumptions. Additionally, compared to <ref type="bibr">(Frei &amp; Vardi, 2024)</ref>, we consider a more general multi-class setting. We believe these distinctions highlight the independent contributions of our work. Some works also studied the ICL from other perspectives. To name a few, <ref type="bibr">Xie et al. (2021)</ref> explained the ICL as implicit Bayesian inference; <ref type="bibr">Wang et al. (2023)</ref> explained the LLMs as latent variable models; <ref type="bibr">Zhang et al. (2023b)</ref> explained the ICL abilities of transformers as implicitly implementing a Bayesian model averaging algorithm; and <ref type="bibr">Li et al. (2023b)</ref> studied the generalization and stability of the ICL abilities of transformers. <ref type="bibr">Hahn &amp; Goyal (2023)</ref> showed that ICL can arise through recombination of compositional structure found in linguistic data. <ref type="bibr">Lin &amp; Lee (2024)</ref> studied the dual operating modes for in-context classification of Gaussian mixtures. However, the analyses of both <ref type="bibr">Hahn &amp; Goyal (2023)</ref> and <ref type="bibr">Lin &amp; Lee (2024)</ref> are based on the idealized optimal next-token predictor for ICL tasks and did not discuss the training dynamics of transformer models.</p><p>Apart from studies focusing on the training convergence properties of transformers in in-context learning (ICL), many other works have investigated the convergence behavior of transformers when learning different tasks. For example, <ref type="bibr">(Jelassi et al., 2022)</ref> and <ref type="bibr">(Li et al., 2023a)</ref> theoretically analyzed how Vision Transformers learn and converge. <ref type="bibr">(Wang et al., 2024)</ref> showed that transformers can provably learn sparse token selection, whereas fully-connected networks cannot. <ref type="bibr">(Zhang et al., 2025)</ref> demonstrated that transformers can learn optimal variable selection in group-sparse classification. <ref type="bibr">(Gao et al., 2024)</ref> studied the global convergence of large-scale transformers under gradient flow dynamics.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>B. Additional notations</head><p>We denote X &#8764; Bin(n, p) if a random variable X follows the binomial distribution with parameters n &#8712; N and p &#8712; [0, 1], which means</p><p>where x * = argmin x f (x).</p><p>Lemma C.2 ( <ref type="bibr">(Bubeck, 2015)</ref>). Suppose f : R d &#8594; R is &#945;-strongly convex and &#946;-smooth for some 0 &lt; &#945; f &#946;. Then, the gradient descent iterating w t+1 = w t -&#951;&#8711;f (w t ) with learning rate &#951; = 1/&#946; and initialization w 0 &#8712; R d satisfies that for any t g 1,</p><p>where &#954; = &#946;/&#945; is the condition number of f , and w * = argmin w&#8712;R d f (w) is the minimizer of f .</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>D. Training procedure for in-context binary classification</head><p>In this section, we present the proof of Theorem 3.3.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>D.1. Proof sketch</head><p>First, we prove in Lemma D.2 that the expected loss function L(W ) in ( <ref type="formula">7</ref>) is strictly convex w.r.t. W and is strongly convex in a compact set of R d&#215;d . Moreover, we prove L(W ) has one unique global minimizer W * . Then, in Lemma D.3, by analyzing the Taylor expansion of L(W ), we prove that as N &#8594; &#8734;, our loss function L(W ) point wisely converges to L(W ) (defined in (25)), and the global minimizer W * converge to 2&#923; -1 . We denote W * = 2(&#923; -1 + G), and prove &#8741;G&#8741; max = O(N -1/2 ). Next, in Lemma D.4, by further analyzing the Taylor expansion of the equation &#8711;L(W * ) = 0 at the point 2&#923; -1 , we establish a tighter bound &#8741;G&#8741; max = O(N -1 ). In Lemma D.5, we prove that our loss function is l-smooth and provide an upper bound for l. Thus, in a compact set R W , our loss function is &#945;-strongly convex and l-smooth. Finally, leveraging the standard results from convex optimization, we prove Theorem 3.3 in subsection D.4.</p><p>In this section, we use the following notations.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>D.2. Notations</head><p>Recall the expected loss function ( <ref type="formula">7</ref>) is</p><p>where</p><p>is the output of the transformer, and the label of the data follows the distribution</p><p>In this section, we introduce the following notations to analyze (7). We denote &#181; = &#181; &#964;,1 -&#181; &#964;,0 , &#181; 1 = &#181; &#964;,1 , &#181; 0 = &#181; &#964;,0 and q = x &#964;,query . Then with probability P (y &#964;,query = 1) = 1/2 we have q = &#181; 1 +v, and with probability P (y &#964;,query = 0) = 1/2 we have q = &#181; 0 + v, where v &#8764; N(0, &#923;). We define p = 2 N N i=1 y &#964;,i x &#964;,i . Since with probability P (y &#964;,i = 1) = 1/2 we have x &#964;,i = &#181; 1 + v i , and with probability P (y &#964;,i = 0) = 1/2 we have x &#964;,i = &#181; 0 + v i , where v i &#8764; N(0, &#923;), we known</p><p>Then, the expected loss function ( <ref type="formula">7</ref>) can be expressed as</p><p>The gradient of the loss function ( <ref type="formula">7</ref>) can be expressed as</p><p>Moreover, we define a function L(W ) as</p><p>In Lemma D.3, we show that as N &#8594; &#8734;, L(W ) will point wisely converge to L(W ).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>D.3. Lemmas</head><p>Lemma D.1. Suppose N 1 &#8764; Bin(N, 1/2). Defining h = N 1 /N -1/2, we have</p><p>We can compute the moment-generating function of h as follows:</p><p>Thus, we know the coefficients of t, t 2 , t 3 are 0, 1/(8N ), 0 respectively, and the coefficients of t n , n g 4 are O(1/N 2 ). We have</p><p>Moreover, according to the Jensen's inequality, we have</p><p>Lemma D.2. For the loss function L(W ) (7), we have</p><p>Additionally, L(W ) has one unique global minimizer on R d&#215;d .</p><p>For L(W ) defined in (25), we also have &#8711; 2 L(W ) { 0. For any compact set R W of R d&#215;d , when W &#8712; R W , we have &#8711; 2 L(W ) { &#947;I d for some &#947; &gt; 0. Additionally, L(W ) has one unique global minimizer on R d&#215;d .</p><p>Proof. We vectorize W as Vec(W ) &#8712; R d 2 , where Vec(W ) i = W t1(i),t2(i) , t 1 (x) = +(x -1)/d, + 1, t 2 (x) = ((x -1) mod d) + 1. Then, we have</p><p>The Hessian matrix of the loss function ( <ref type="formula">7</ref>) is</p><p>Considering z &#8712; R d 2 such that z &#824; = 0, we have</p><p>where f pq (p, q) are the probability density function (PDF) function of p, q. Since for any p, q, &#963;(p &#166; W q/2)(1&#963;(p &#166; W q/2)) &gt; 0, we have z &#166; &#8711; 2 L(W )z g 0. Thus, &#8711; 2 L(W ) &#176;0 and L(W ) is convex.</p><p>Moreover, for any z &#824; = 0, we denote</p><p>Then, we define region &#8486;(a, b)</p><p>min</p><p>we have S(&#8486;, W ) &gt; 0. Since with probability P (y &#964;,query = 1) = 1/2, q = &#181; 1 + v, with probability P (y &#964;,query = 0) = 1/2, q = &#181; 0 + v, where v &#8764; N(0, &#923;) and p = &#181; + hu + g, where g &#8764; N(0, 4&#923;/N ), v &#8764; N(0, &#923;), &#181; 0 &#8764; N(0, I d ), the covariance matrices of p, q are positive definite and we have f pq (p, q) &gt; 0 for all p, q &#8712; R d . Moreover, &#8486;(a, b) are non-zero measures on R d&#215;d . Thus, we have C(&#8486;) &gt; 0. Then, for any z &#824; = 0, we have</p><p>Thus, we have &#8711; 2 L(W ) { 0. L(W ) is strictly convex.</p><p>Moreover, for any compact set R W of R d&#215;d , for any W &#8712; R W , we have</p><p>Then, for any W &#8712; R W , for any z &#824; = 0, we have</p><p>Thus, when W &#8712; R W , where R W is a compact set, we have &#8711; 2 L(W ) { C(&#8486;)S(&#8486;)I d /4 and the loss function L(W ) is &#947;-strongly convex, where &#947; = C(&#8486;)S(&#8486;)/4.</p><p>Because our loss function is strictly convex in R d&#215;d , it has at most one global minimizer in R d&#215;d . Next, we prove all level sets of our loss function are compact, i.e. V &#945; = {W &#8712; R d&#215;d | L(W ) f &#945;} is compact for all &#945;. We prove it by contradiction. Suppose V &#945; is not compact for some &#945;. Since our loss function is continuous and convex, V &#945; is an unbounded convex set. Since the dimension of</p><p>Thus, we have</p><p>We define</p><p>we have S(&#8486; 0 ) &gt; 0. Since &#8486; 0 are non-zero measures for p, q, we have C(&#8486; 0 ) &gt; 0. Then, we have</p><p>This contradicts the assumption L(W &#945; + tW k ) f &#945;. Thus, all level sets of the loss function L(W ) are compact, which means there exists a global minimizer for L(W ). Together with the fact that L(W ) is strictly convex, L(W ) has one unique global minimizer on R d&#215;d .</p><p>Similarly, we can prove the same conclusions for L(W ).</p><p>Lemma D.3. Denoting the global minimizer of the loss function (7) as W * , we have W * = 2(&#923; -1 + G), where</p><p>Proof. Let a = &#181; &#166; &#923; -1 q, s = &#181; &#166; W q/2, r = (hu + g) &#166; W q/2. Performing the Taylor expansion on (7), we have</p><p>where &#958;(s, r) are real numbers between s and s + r. According to Lemma D.1, we have E [r] = E (hu + g) &#166; W q/2 = 0. Thus, we have</p><p>Moreover, we have <ref type="bibr">j,k,l&#8712;[d]</ref> g i g k W kl q l W ij q j = (gg &#166; W q) &#166; W q and E[gg &#166; ] = 4&#923;/N . C l is a constant independent of N and W . Thus, we have</p><p>This shows that L(W ) point wisely converges to L(W ).</p><p>According to Lemma D.2, L(W ) has one unique global minimizer. Consider the equation:</p><p>We can easily find that &#8711; L(2&#923; -1 ) = 0 and W = 2&#923; -1 is the global minimizer of L(W ).</p><p>Here &#961; W , C W are some positive finite constants. Then, we have</p><p>where</p><p>W is a constant independent of N and W . This shows that, for W &#8712; R W , our loss function L(W ) uniformly converge to L(W ).</p><p>Denote W * as the global minimizer of the loss function L(W ) with prompt length N . Then, we show that, when N is sufficiently large, W * &#8712; R W . We first denote &#8706;R W = {W | &#8741;W -2&#923; -1 &#8741; F = &#961; W } and &#8710; = min W &#8712;&#8706;R W L(W ) -L(2&#923; -1 ) &gt; 0. Then, for N g 4C &#8242; l /&#8710;, and for any W &#8712; R W , we have</p><p>Then, we have</p><p>According to Lemma D.2, for W &#8712; R W , we have &#8711; 2 L(W ) { &#947;I d , where &#947; is a positive constant independent of N . Thus, L(W ) is &#947;-strongly convex in R W . According to Lemma C.1, we have</p><p>Thus, when N &#8594; &#8734;, we have</p><p>Lemma D.4. The global minimizer of the loss function ( <ref type="formula">7</ref>) is W * = 2(&#923; -1 + G), where</p><p>Proof. According to Lemma D.2, the loss function L(W ) has a unique global minimizer W * . We have</p><p>The Taylor expansion of &#963;(a + b) at point a with an Lagrange form of remainder is</p><p>where &#958;(a, b) are real numbers between a and a + b. Thus, our equation ( <ref type="formula">27</ref>) become</p><p>Note that E[&#963; &#8242; (a)bpq &#166; ] = E &#181;,u,q &#963; &#8242; (a)E g,h bpq &#166; . For E g,h [bpq &#166; ], according to Lemma D.1 and g &#8764; N(0, 4&#923;/N ), we have</p><p>Then, we have</p><p>Similarly for E[&#963; &#8242;&#8242; (a)b 2 pq &#166; /2], we have</p><p>.</p><p>For each term in (i), it contains two G. Thus, their max norms are at most smaller than O(&#8741;G&#8741; 2 max ). For each term in (ii), it contains one G and h 2 or contains one G and two g. According to E[h 2 ] = 1/(4N ) in Lemma D.1, the max norm of terms with one G and h 2 are smaller than O(&#8741;G&#8741; max /N ). Defining &#7713; = N 1/2 &#923; -1/2 g/2, we have &#7713; &#8764; N(0, I d ) and g = 2N -1/2 &#923; 1/2 &#7713;. Thus, converting two g to &#7713;, we have a coefficient of N -1 . Therefore, the max norms of terms with one G and two g are also smaller than O(&#8741;G&#8741; max /N ). Therefore, for terms (i), (ii), we have</p><p>For term (iii), according to Lemma D.1 and g &#8764; N(0, 4&#923;/N ), we have</p><p>For E[&#963; &#8242;&#8242;&#8242; (&#958;(a, b))b 3 pq &#166; /3!], we have</p><p>.</p><p>For terms in ( * ) containing two or three G, these terms' expected absolute values are at most smaller than O(&#8741;G&#8741; 2 max ). For terms in ( * * ) containing one G, these terms must contain n 1 number of h and n 2 number of elements of g, where n 1 + n 2 = 2, 3, 4, n 1 , n 2 &#8712; N. According to Lemma D.1, we know that for n 1 = 1, 2, 3, 4, E|h n1 | f O(N -n1/2 ). Defining &#7713; = N 1/2 &#923; -1/2 g/2, we have &#7713; &#8764; N(0, I d ) and g = 2N -1/2 &#923; 1/2 &#7713;. Converting g to &#7713;, we have a coefficient of N -n2/2 . Thus, for terms in ( * * ), these terms' expected absolute values are at most smaller than O(&#8741;G&#8741; max N -(n1+n2)/2 ) f O(&#8741;G&#8741; max N -1 ). For terms in ( * * * ) without G, these terms must contain n 1 number of h and n 2 number of elements of g, we have n 1 + n 2 = 3, 4, n 1 , n 2 &#8712; N. Similarly, these term's expected absolute values are at most smaller than O(N -(n1+n2)/2 ) f O(N -3/2 ). Therefore, we have</p><p>Moreover, we have</p><p>where</p><p>, where S ij = s t1(i),t2(i),t1(j),t2(j) = E&#963; &#8242; (a)&#181; t1(i) q t2(i) &#181; t1(j) q t2(j) . Then ( <ref type="formula">36</ref>) can be expressed as</p><p>Note that S = 4&#8711; 2 L(2&#923; -1 ). According to Lemma D.2, S is positive definite. Thus, combining ( <ref type="formula">28</ref>), ( <ref type="formula">29</ref>), ( <ref type="formula">30</ref>), ( <ref type="formula">31</ref>), ( <ref type="formula">32</ref>), ( <ref type="formula">34</ref>), ( <ref type="formula">35</ref>), (37), we have</p><p>Lemma D.5. The loss function (7) is l-smooth, where l f</p><p>Proof. The Hessian matrix of the loss function is</p><p>where (a) is due to the Cauchy-Schwarz inequality. Thus, &#8711; 2 L(W ) &#175;lI d and L(W ) is l-smooth, where l is a constant smaller than 1 D.4. Proof of Theorem 3.3</p><p>Proof. According to Lemma D.4, the global minimizer of L(W ) is W * = 2(&#923; -1 + G), where</p><p>Here &#945; &gt; 0 is a positive constant number. Thus, L(W ) is &#945;-strongly convex in R W . Moreover, according to Lemma D.5, L(W ) is l-smooth. Then according to Lemma C.2, applying gradient descent with &#951; = 1/l, for any t g 1, we have</p><p>where &#954; = l/&#945;.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>E. In-context inference of binary classification E.1. Notations</head><p>In this section, we use the following notations. We denote</p><p>E.2. Proof of Theorem 3.6</p><p>Proof. The output of the trained transformer is</p><p>The probability of y query = 1 given x query is</p><p>Defining a = &#181; &#166; &#923; -1 q, b = (&#181; + hu + g) &#166; Gq + (hu + g) &#166; &#923; -1 q, we have</p><p>where &#958; are real numbers between a and a + b. Thus, we have</p><p>We first consider the term &#963; &#8242; (a)E <ref type="bibr">[|b|]</ref>. Defining &#7713; = &#923; -1/2 M 1/2 g/2, we have</p><p>where (a) is due to</p><p>For E[b 2 ], we have</p><p>Notice that terms in E [(&#181; + hu + g) &#166; Gq] 2 contain two G. Thus, they are at most smaller than</p><p>Terms in E [(hu + g) &#166; &#923; -1 q] 2 /2 contain two h, or two g, or one h and one g. According to Lemma D.1, we have</p><p>Converting one g to &#7713;, we have a coefficient of M -1/2 . Thus, terms in E [(hu + g) &#166; &#923; -1 q] 2 /2 contain two h, or two g, or one h and one g are O(1/M ). Terms in E (&#181;+hu+g) &#166; Gq(hu+g) &#166; &#923; -1 q contain at least one G and one h or one G and one g. Thus, they are at most smaller than </p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>F. Training procedure for in-context multi-class classification</head><p>In this section, we present the proof of Theorem 4.3.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>F.1. Proof sketch</head><p>First, we prove in Lemma F.3 that the expected loss function L(W ) (16) is strictly convex w.r.t. W and is strongly convex in a compact set of R d&#215;d . Moreover, we prove L(W ) has one unique global minimizer W * . Then, in Lemma F.4, by analyzing the Taylor expansion of L(W ), we prove that as N &#8594; &#8734;, our loss function L(W ) point wisely converges to L(W ) (defined in (44)), and the global minimizer W * converge to 2&#923; -1 . Thus, we denote W * = 2(&#923; -1 + G), and prove &#8741;G&#8741; max = O(N -1/4 ). Next, in Lemma F.5, by further analyzing the Taylor expansion of the equation &#8711;L(W * ) = 0 at the point 2&#923; -1 , we establish a tighter bound &#8741;G&#8741; max = O(cN -1 ). In Lemma F.6, we prove that our loss function is l-smooth and provide an upper bound for l. Thus, in a compact set R W , our loss function is &#945;-strongly convex and l-smooth. Finally, leveraging the standard results from the convex optimization, we prove Theorem 4.3 in subsection F.3.</p><p>In this section, we use the following notations.</p><p>Proof. Since (N 1 , N 2 , . . . , N c ) &#8764; Multin(N, 1/c), the moment-generating function of (N 1 , N 2 , . . . , N c ) is</p><p>We can compute the moment-generating function of h = (h 1 , h 2 , . . . , h c ) as follows:</p><p>Observing the coefficients of h, we have</p><p>Iteratively applying the H&#246;lder's inequality, we have</p><p>Moreover, we have</p><p>For any</p><p>Thus, with the results from Lemma F.1, for any n 1k , n 2ki satisfying</p><p>Moreover, according to the Jensen's inequality, we have</p><p>Thus, with the results from Lemma F.1, for any</p><p>Lemma F.3. For the loss function L(W ) (16), we have &#8711; 2 L(W ) { 0. For any compact set R W , when W &#8712; R W , we have &#8711; 2 L(W ) { &#947;I d for some &#947; &gt; 0. Additionally, L(W ) has one unique global minimizer on R d&#215;d .</p><p>For L(W ) defined in ( <ref type="formula">44</ref>), we also have &#8711; 2 L(W ) { 0. For any compact set R W , when W &#8712; R W , we have &#8711; 2 L(W ) { &#947;I d for some &#947; &gt; 0. Additionally, L(W ) has one unique global minimizer on R d&#215;d .</p><p>Proof. We vectorize W as Vec(W ) &#8712; R d 2 , where Vec(W</p><p>where a k = -log( l=1,...,c,l&#824; =k exp ((p l -p k )W q/c)). For &#8711;a k , we have</p><p>and (&#8711;softmax(P &#166; W q/c) k ) j = l=1,...,c,l&#824; =k softmax(P &#166; W q/c) k softmax(P &#166; W q/c) l (p k -p l ) t1(j) q t2(j) /c. We can express the Hessian matrix of the loss function with the following form:</p><p>Since for any P, q, k, l, softmax(P &#166; W q/c) k softmax(P &#166; W q/c) l &gt; 0, we have z &#166; &#8711; 2 L(W )z g 0. Thus, &#8711; 2 L(W ) &#176;0 and L(W ) is convex.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>On the Training Convergence of Transformers for In-Context Classification of Gaussian Mixtures</head><p>Defining p = p 1 -p 2 , we have</p><p>z a pt1(a) q t2(a)</p><p>&#63734; &#63736; 2 f P q (P, q)dP dq where f P q (P, q) are the PDF function of P, q. For any z &#824; = 0, we denote</p><p>we have S(&#8486;, W ) &gt; 0. Since we have f P q (P, q) &gt; 0 for all P, q and &#8486;(a, b) are non-zero measures for P, q. Thus, we have C(&#8486;) &gt; 0. Then, for any z &#824; = 0, we have</p><p>Moreover, for any compact set R W of R d&#215;d , for any W &#8712; R W , we have</p><p>Then, for any W &#8712; R W , for any z &#824; = 0, we have</p><p>. Performing the Taylor expansion on (16), we have</p><p>where the last inequality is due to Lemma F.1, F.2. C l is a constant independent of N and W . This shows that L(W ) point wisely converge to L(W ).</p><p>According to Lemma D.2, L(W ) has one unique global minimizer. Considering the equation:</p><p>We can easily find that &#8711; L(c&#923; -1 ) = 0 and W = c&#923; -1 is the global minimizer of L(W ).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>Considering a compact set R</head><p>Here &#961; W , C W are some positive finite constants. Then, we have</p><p>Denote W * as the global minimizer of L(W ) with prompt length N . Then, we show that, when N is sufficiently large,</p><p>l /&#8710;) 2 , and for any W &#8712; R W , we have</p><p>On the Training Convergence of Transformers for In-Context Classification of Gaussian Mixtures</p><p>Then, we have</p><p>According to Lemma D.2, for W &#8712; R W , we have &#8711; 2 L(W ) { &#947;I d , where &#947; is a positive constant independent of N . Thus, L(W ) is &#947;-strongly convex in R W . According to Lemma C.1, we have</p><p>Thus, when N &#8594; &#8734;, we have</p><p>Lemma F.5. The global minimizer of the loss function ( <ref type="formula">16</ref>) is W * = c(&#923; -1 + G). We have</p><p>where a = &#181; &#166; &#923; -1 q, a k = &#181; &#166; k &#923; -1 q, S = c 2 &#8711; 2 L(c&#923; -1 ). Ignoring constants other than c, N , we have &#8741;G&#8741; max f O(c/N ).</p><p>Proof. According to Lemma F.3, the loss function L(W ) has a unique global minimizer W * . We have &#8706;&#950; k (a) &#8706; 2 &#950; k (a) &#8706;a l &#8706;a n &#966;1&#8712;{&#181; l ,ch l &#181; l ,g l },&#966;2&#8712;{&#181;n,chn&#181;n,gn} &#966; &#166; 1 Gq&#966; &#166; 2 Gqp k q &#166; (i) + &#966;1&#8712;{&#181; l ,ch l &#181; l ,g l },&#966;2&#8712;{chn&#181;n,gn}</p><p>.</p><p>For terms (i) having two G, their max norms are at most smaller than O(&#8741;G&#8741; 2 max ). For terms (ii) having one G, define &#7713;l = &#923; -1/2 g l , these terms must contain n 1j number of h j and n 2ji number of (&#7713; j ) i , we have j&#8712;[c],i&#8712; <ref type="bibr">[d]</ref> n 1j + n 2ji = n t , n t = 1, 2, 3. According to Lemma F.2, we know that for n t = 1, 2, 3,</p><p>Thus, the max norm of expectations of terms in (ii) are at most smaller than O(&#8741;G&#8741; max N -1 ). Therefore, for terms (i), (ii), we have</p><p>For terms (iii) without G, we have</p><p>where the last inequity is due to Lemma F.1, F.2.</p><p>For the third term </p><p>&#966; &#166; 1 Gq&#966; &#166; 2 Gq&#966; &#166; 3 &#923; -1 q(p k4 ) l q m ( * )</p><p>&#966; &#166; 1 Gq&#966; &#166; 2 &#923; -1 q&#966; &#166; 3 &#923; -1 q(p k4 ) l q m ( * * )</p><p>.</p><p>For terms in ( * ) having two or three G, these terms' expected absolute values are at most smaller than O(&#8741;G&#8741; 2 max ). For terms in ( * * ) having one G, these terms must contain n 1j number of h j and n 2ji number of (&#7713; j ) i , we have j&#8712;[c],i&#8712; <ref type="bibr">[d]</ref> n 1j +n 2ji = n t , n t = 2, 3, 4. According to Lemma F.2, for n t = 2, 3, 4, we have</p><p>Thus, these term's expected absolute values are at most smaller than O(&#8741;G&#8741; max N -1 ). For terms in ( * * * ) without G, these terms must contain n 1j number of h j and n 2ji number of (&#7713; j ) i , we have j&#8712;[c],i&#8712; <ref type="bibr">[d]</ref> n 1j + n 2ji = n t , n t = 3, 4.</p><p>According to Lemma F.2, for n t = 3, 4, we have</p><p>|h n 1k k (&#7713; j ) </p><p>where s ijnm = E c k=2 k-1 l=1 &#950; k (a)&#950; l (a)(&#181; k -&#181; l ) i (&#181; k -&#181; l ) n q m q j . We vectorize G as Vec(G) i = G t1(i),t2(i) . Define S &#8712; R d 2 &#215;d 2 , where S ij = s t1(i),t2(i),t1(j),t2(j) = E c k=2 k-1 l=1 &#950; k (a)&#950; l (a)(&#181; k -&#181; l ) t1(i) q t2(i) (&#181; k -&#181; l ) t1(j) q t2(j) , (54) can be expressed as</p><p>Note that S = c 2 &#8711; 2 L(c&#923; -1 ). According to Lemma F.3, S is positive definite. Thus, combining (47), ( <ref type="formula">48</ref>), ( <ref type="formula">49</ref>), ( <ref type="formula">50</ref>), ( <ref type="formula">51</ref>), ( <ref type="formula">52</ref>), ( <ref type="formula">53</ref>), (55), we have</p><p>Ignoring constants other than c, N , we have &#8741;G&#8741; max f O(c/N ).</p><p>Lemma F.6. The loss function (7) is l-smooth, where l f 1</p></div><note xmlns="http://www.tei-c.org/ns/1.0" place="foot" n="4" xml:id="foot_0"><p>i&#8712;[d 2 ] E[(p t1(i) q t2(i) ) 2 ].</p></note>
		</body>
		</text>
</TEI>
