           Nonlinear transformers can perform inference-time feature learning


                  Naoki Nishikawa * 1 2 Yujin Song * 1 2 Kazusato Oko 2 3 Denny Wu 4 5 Taiji Suzuki 1 2


                            Abstract                                 contain input-output pairs exhibiting certain functional rela-
                                                                     tionships. For instance, a substantial body of research (Garg
        Pretrained transformers have demonstrated the
                                                                     et al., 2022; Von Oswald et al., 2023; Ahn et al., 2023;
        ability to implement various algorithms at infer-
                                                                     Mahankali et al., 2023a; Zhang et al., 2023; Gatmiry et al.,
        ence time without parameter updates. While the-
                                                                     2024) has demonstrated that linear transformers can perform
        oretical works have established this capability
                                                                     linear regression in-context. As for nonlinear transform-
        through constructions and approximation guaran-
                                                                     ers, which possess greater expressive power to implement
        tees, the optimization and statistical efficiency as-
                                                                     more complex algorithms (Bai et al., 2023; Cheng et al.,
        pects remain understudied. In this work, we inves-
                                                                     2023; Guo et al., 2023; Kim et al., 2024), existing optimiza-
        tigate how transformers learn features in-context –
                                                                     tion analyses generally do not provide end-to-end statistical
        a key mechanism underlying their inference-time
                                                                     guarantees for in-context learning of nontrivial nonlinear
        adaptivity. We focus on the in-context learning of
                                                                     function classes (Kim & Suzuki, 2024a; Yang et al., 2024;
        single-index models y = σ∗ (⟨x, β⟩), which are
                                                                     Bu et al., 2024). A notable exception is Oko et al. (2024b),
        low-dimensional nonlinear functions parameter-
                                                                     which characterizes the optimization and sample complexity
        ized by feature vector β. We prove that transform-
                                                                     of in-context learning for Gaussian single-index models us-
        ers pretrained by gradient-based optimization can
                                                                     ing a shallow transformer. Specifically, they showed that for
        perform inference-time feature learning, i.e., ex-
                                                                     a degree-P single-index function class of dimension r, the
        tract information of the target features β solely
                                                                     required in-context sample size of the pretrained transformer
        from test prompts (despite β varying across differ-
                                                                     scales as rΘ(P ) , which is comparable to the performance of
        ent prompts), hence achieving an in-context sta-
                                                                     kernel methods on an r-dimensional subspace.
        tistical efficiency that surpasses any non-adaptive
        (fixed-basis) algorithms such as kernel methods.
                                                                     Inference-Time Feature Learning. Our starting point
        Moreover, we show that the inference-time sam-
                                                                     is the observation that for learning low-dimensional tar-
        ple complexity surpasses the Correlational Statis-
                                                                     get functions (e.g., single-index models) on isotropic data,
        tical Query (CSQ) lower bound, owing to nonlin-
                                                                     kernel methods and, more generally, non-adaptive (fixed-
        ear label transformations naturally induced by the
                                                                     feature) estimators are statistically suboptimal. Numerous
        Softmax self-attention mechanism.
                                                                     prior studies have shown that neural networks can outper-
                                                                     form kernel methods due to feature learning (Ghorbani et al.,
                                                                     2019; Ba et al., 2022; Damian et al., 2022; Abbe et al., 2022),
1       Introduction                                                 where model parameters adapt to the low-dimensional struc-
Large language models (LLMs) are capable of In-Context               ture of the learning problem during gradient-based training.
Learning (ICL) (Brown et al., 2020), where they construct            In the ICL analysis of Oko et al. (2024b), transformers im-
variable inference-time algorithms based on examples pro-            plement a kernel-like inference algorithm on a nonlinear
                                                                                          m
vided in the test prompt, without updating the model param-                    P {fj (·)}j=1 fixed across tasks, constructing the
                                                                     feature map
eters. Recent theoretical studies have shown that pretrained         predictor j aj fj (·) by fitting the coefficients aj in-context.
transformers (Vaswani et al., 2017) can implement regres-            In contrast, we expect that better sample complexity can be
sion algorithms in their forward passes when test prompts            achieved by an algorithm that adaptively selects the feature
    *
                                                                     map at inference time, i.e., varying {fj (·)}mj=1 based on the
    Equal contribution 1 The University of Tokyo, Tokyo, Japan       in-context examples.
2
  RIKEN AIP, Tokyo, Japan 3 Unversity of California, Berkeley
4
  New York University 5 Flatiron Institute. Correspondence to:       Motivated by the importance of adaptivity in the statistical
Naoki Nishikawa <nishikawa-naoki259@g.ecc.u-tokyo.ac.jp>,            efficiency of neural networks (Bach, 2017; Suzuki, 2019),
Yujin Song <y.song.research@gmail.com>.                              in this work we theoretically study inference-time feature
Proceedings of the 42 nd International Conference on Machine         learning – the ability to adaptively extract latent features of
Learning, Vancouver, Canada. PMLR 267, 2025. Copyright 2025          the ground truth from test prompts without any parameter
by the author(s).                                                    updates. We ask the following question.

                                                                 1
                              Nonlinear transformers can perform inference-time feature learning

  Q1: Can pretrained transformers implement in-context                  expansion of σ∗ (see Definition 2). This sample complex-
         algorithms capable of feature learning,                        ity improves upon kernel methods, and the exponential
  and outperform non-adaptive methods such as kernel                    dependence on the IE aligns with the CSQ lower bound
                        models?                                         (Damian et al., 2022; Abbe et al., 2023).

We study the Gaussian single-index model setting where the            • SQ algorithms. For learners that access full statistical
class of target functions is given by f∗ : Rd → R, f∗ (x) =             queries (i.e., in the form of E[ϕ(x, y)]), the complexity
σ∗ (⟨β, x⟩). Here, σ : R → R is a nonlinear link func-                  of single-index learning is governed by the generative
tion, and f∗ depends only on the projection along β ∈ Rd ,              exponent ge(σ∗ ) ≤ ie(σ∗ ) defined as the lowest possible
referred to as the feature vector. The transformer model                information exponent after arbitrary L2 label transforma-
is provided with test prompts (in-context examples) in the              tion (Damian et al., 2024); in particular, ge(σ∗ ) ≤ 2 for
following format:                                                       any polynomial link function. Recent works have shown
                                                                        that gradient-based training on transformed labels can
                x , y , ..., x , y , x ,
                | 1 1 {z N N} |{z}                                      achieve a sample complexity of n ≳ dΘ(ge(σ∗ )) , which
                        examples         query                          improves upon the CSQ rate (Dandi et al., 2024; Lee et al.,
                                                                        2024; Arnaboldi et al., 2024; Joshi et al., 2024).
where the labels satisfy yi ≃ σ∗ (⟨β, xi ⟩) with feature vector
β varying across different prompts. In this setup, inference-         The ICL mechanism in Oko et al. (2024b) operates as a ker-
time feature learning refers to the model extracting β by             nel regression algorithm, which entails that the in-context
examining in-context examples and using it to estimate the            sample complexity depends on deg(σ∗ ). We expect this
label σ∗ (⟨β, x⟩) – all without any parameter updates.                dependency to improve with inference-time feature learning.
                                                                      Indeed, drawing from prior works showing that linear trans-
This single-index setting captures scenarios where the
                                                                      formers can implement single-step GD in-context (Von Os-
ground truth exhibits low-dimensional structure, and has
                                                                      wald et al., 2023; Ahn et al., 2023; Mahankali et al., 2023a;
been extensively studied in deep learning theory to demon-
                                                                      Zhang et al., 2023) – which corresponds to a CSQ-like al-
strate the adaptivity of neural networks (Ba et al., 2022;
                                                                      gorithm – it is natural to conjecture that a sufficient sample
Bietti et al., 2022; Berthier et al., 2023; Mahankali et al.,
                                                                      size in our single-index setting scales as rΘ(ie(σ∗ )) . That
2023b). Furthermore, following Oko et al. (2024b) we as-
                                                                      being said, when considering the effect of nonlinear soft-
sume that the feature vectors are drawn from some r ≤ d
                                                                      max attention, transformers can also introduce nonlinear
dimensional subspace, which implies that if pretraining iden-
                                                                      label transformations at inference time, hence potentially
tifies the support of the target function class, the in-context
                                                                      achieving a statistical efficiency that depends only on ge(σ∗ )
sample complexity should only scale with the subspace
                                                                      and surpasses the limitations of CSQ-based methods. This
dimensionality r instead of the ambient dimensionality d.
                                                                      motivates us to investigate the following question regarding
Sample Complexity of Feature Learning. The sample                     the ICL sample complexity.
complexity of learning single-index models on isotropic
Gaussian data in Rd has been extensively studied in prior                Q2: Can transformers with nonlinear self-attention
works. For kernel methods, the dimension dependence can                         implement inference-time algorithms
be sharply characterized, whereas for adaptive procedures             that surpass the statistical barrier imposed by CSQ lower
such as gradient-based feature learning, the statistical com-                                   bounds?
plexity can be characterized by (variants of) statistical query
                                                                      1.1   Our Contributions
(SQ) lower bounds (Kearns, 1998; Reyzin, 2020). We sum-
marize these prior results as follow.                                 We establish end-to-end optimization and statistical guaran-
                                                                      tees for the in-context learning of the Gaussian single-index
• Kernel methods. If σ∗ is a polynomial of degree deg(σ∗ ),           function class using a transformer with softmax attention.
  then kernel methods using fixed feature maps require                Our main result is the following.
  n ≳ ddeg(σ∗ ) samples to learn f∗ with low estimation
  error (Ghorbani et al., 2021; Donhauser et al., 2021).              Theorem 1 (informal). Consider the learning of single-
                                                                      index polynomials σ∗ (⟨β, x⟩) where the feature vector β is
• CSQ algorithms. For learners that make correlational                drawn from an r-dimensional subspace. If we optimize a
  queries to the target (i.e., in the form of E[ϕ(x)y]),              single-layer transformer with softmax attention via gradient-
  such as one-pass SGD on the squared/correlation loss                based pretraining (Algorithm 1) using Tpt = Ω̃(dΘ(ie(σ∗ )) )
  (Ben Arous et al., 2021; Damian et al., 2023) or single-            tasks, where for each task the prompt length satisfies
  step GD (Damian et al., 2022; Ba et al., 2023), prior               Npt = Ω̃(dΘ(ie(σ∗ )) ), then the model achieves od (1) in-
  works have established a sufficient sample complexity of            context prediction risk if the number of in-context examples
  n ≳ dΘ(ie(σ∗ )) , where ie(σ∗ ) ≤ deg(σ∗ ) is the informa-          satisfies Ntest = Ω̃(rΘ(ge(σ∗ )) ), where ge(σ∗ ) ≤ 2 is the
  tion exponent defined as the lowest degree in the Hermite           generative exponent of σ∗ .

                                                                  2
                             Nonlinear transformers can perform inference-time feature learning

We make the following remarks on the main theorem.                   head mechanisms emerge via associative memory obtained
                                                                     through gradient descent.
• While the pretraining sample complexity scales with the
  ambient dimension d, the required in-context sample size           Learning Functions with Sparse Feature. Other than
  depends only on the support dimension of the target func-          single-index models, various function classes with sparse
  tions r ≤ d. This aligns with the findings of Oko et al.           features have been studied, and neural networks’ adaptivity
  (2024b), which show that transformers can adapt to low-            to such features via gradient descent have been explored in
  dimensional structure of the target function class through         standard (non-ICL) settings. These function classes include
  pretraining, thereby enhancing inference efficiency. We            multi-index models (Damian et al., 2022; Abbe et al., 2022;
  note that while Oko
                  √ et al. (2024b) restricts the analysis to         2023; Bietti et al., 2023a; Mousavi-Hosseini et al., 2023a),
  the regime r ≲ d, our results applies to arbitrary r ≤ d.          additive models (Oko et al., 2024a; Ren et al., 2025), parity
                                                                     functions (Barak et al., 2022; Suzuki et al., 2023; Glasgow,
• The inference-time sample complexity of rΘ(ge(σ∗ )) is
                                                                     2024). Kim & Suzuki (2024b) showed that chain-of-thought
  independent of both the degree and the information expo-
                                                                     reasoning of transformers helps solve parity functions effi-
  nent of the link function σ∗ ; in other words, pretrained
                                                                     ciently, albeit not in an ICL setting.
  transformers can implement SQ algorithms in-context
  with statistical efficiency that surpasses both kernel meth-
  ods and CSQ learners. Consequently, our ICL complexity             2     Preliminaries
  improves upon Oko et al. (2024b) in all regimes.                   Notations. ∥v∥ denotes the ℓ2 norm of a vector v. For
• Our analysis explicitly shows that softmax self-attention          matrix A, we denote its ℓ2 operator norm and Frobenius
  can extract the inner product ⟨β, x⟩, where β varies across        norm as ∥A∥2 and ∥A∥F , respectively. Let Hei (z) =
                                                                              z2   i     −z 2
                                                                                 d
  tasks, by computing the correlation between nonlinear              (−1)i e 2 dz  ie
                                                                                      2  be the degree-i (probabilist’s) Hermite
  transformations of both the input x and the label. This            polynomial. P  Given the Hermite expansion of a function f ,
  mechanism is analogous to the tensor partial trace algo-           i.e., f (z) = i≥0 ci!i Hei (z), we define H(f, i) := ci as its
  rithm studied in Damian et al. (2024); see Section 5 for           degree-i coefficient. Sd−1 denotes the unit sphere in Rd .
  detailed explanation.                                              I(A) is the indicator function. diag(a1 , . . . , an ) represents
On the technical level, we demonstrate that: (i) the Softmax         the n × n diagonal matrix whose (i, i)-th element is ai .
attention can be pretrained to compute ⟨β, x⟩ for each
                                                                     2.1    Preliminaries on In-Context Learning (ICL)
prompt, and (ii) the nonlinearity in the attention reduces
the information exponent of the link function σ∗ , which is          We consider the setting of learning functional relationships
shown through a careful analysis of the nonlinear correlation        in-context as introduced in Akyürek et al. (2022); Garg
computed by the attention scores. Mechanism (i) enables              et al. (2022). The input consists of N labeled example pairs
inference-time feature learning, whereas mechanism (ii)              (xi , yi ) ∈ Rd × R for i = 1, . . . , N , referred to as context
leads to an information exponent-free sample complexity.             or in-context examples, along with a query x ∈ Rd . The
                                                                     entire input sequence (x1 , y1 , . . . , xN , yN , x) is referred to
1.2   Related Work                                                   a prompt, which we sometimes shorten to (X, y, x) where
                                                                                                                             ⊤
In-context Learning of Functions. ICL abilities of linear            X := x1 · · · xN and y := y1 · · · yN . The
transformers have been extensively studied in terms of both          learner is tasked to predict the corresponding output y ∈ R
expressivity and optimization. They are shown to imple-              for the query x. The inputs x1 , . . . , xN , x are i.i.d. sam-
ment linear regression algorithms, including one gradient            ples drawn from a specific distribution Dx , and the outputs
descent step (Von Oswald et al., 2023; Ahn et al., 2023;             y1 , . . . , yN are generated as
Mahankali et al., 2023a; Zhang et al., 2023), multi-step gra-
dient descent (Ahn et al., 2023; Gatmiry et al., 2024), and                            yi = f∗ (xi ) + ζi (i = 1, . . . , N ),
sparse regression (Bai et al., 2023). (Zhang et al., 2024)
                                                                     where f∗ : Rd → R is a function associated with each
showed that linear transformer can adapt to the prior mean
                                                                     prompt, and ζ1 , . . . , ζN ∼ Dζ are i.i.d. noise. The target
of the coefficient vector. We note several related works on
                                                                     function f∗ varies across prompts and is drawn from Df∗ for
ICL of nonlinear transformers that were not discussed in
                                                                     each prompt. Our goal is to obtain a model f (X, y, x; θ)
the introduction: Huang et al. (2023); Chen et al. (2024)
                                                                     with parameters θ, which takes the prompt as input and
analyzed in-context linear regression of softmax transform-
                                                                     predicts the query output f∗ (x) without updating any pa-
ers, including optimization analysis, while Li et al. (2024)
                                                                     rameters during inference time.
investigated a classification problem (which is also essen-
tially linear). Nichani et al. (2024) examined the ability of        We divide learning into two stages: pretraining and infer-
optimized softmax transformers to learn causal structures            ence. In the pretraining stage, the model is optimized on a
                                                                                                                                     Tpt
in-context. Bietti et al. (2023b) demonstrated that induction                                                     t
                                                                     training set {((xt1 , y1t , . . . , xtNpt , yN pt
                                                                                                                       , xt ), y t )}t=1 , which

                                                                 3
                               Nonlinear transformers can perform inference-time feature learning

includes Tpt distinct tasks from Df∗ . In the inference                  Note that, by definition, ge(σ∗ ) ≤ ie(σ∗ ) ≤ deg(σ∗ ). It
stage, we present a prompt (x1 , y1 , . . . , xNtest , yNtest , x)       is known that for polynomial link functions, there exists a
with context length Ntest to the pretrained model, which                 monomial transformation σ∗ → σ∗j that reduces the infor-
aims to predict the label f∗ (x). To evaluate the model’s                mation exponent to 1 or 2.
average performance at inference, we use test ICL error                  Lemma 3 (Lee et al. (2024), Proposition 6). It holds that
defined as                                                                                   (
RICL                                                                                           1 (if σ∗ is not even)
 Ntest (θ) = EDx ,Df∗ ,Dζ [|f (X1:Ntest , y1:Ntest , x; θ) − y|].                 ge(σ∗ ) =                           .
                                                           (2.1)                               2 (if σ∗ is even)
Based on this setup, we emphasize that there are two distinct
                                                                         Moreover, ge(σ∗ ) = minj≥1 ie(σ∗j ) holds.
notions of “sample complexity” in ICL:
• The pretraining task (sample) complexity refers to the                 Sample complexity of learning f∗ . The sample com-
  task (sample) size Tpt (Npt ) used by the pretraining algo-            plexity of various learning algorithms are dictated by
  rithm to optimize the parameters θ.                                    the quantities in Definition 2. Linear/kernel models on
                                                                         fixed basis require ddeg(σ∗ ) samples to learn f∗ (Ghor-
• The inference sample complexity refers to the context                  bani et al., 2021; Donhauser et al., 2021). Online
  length Ntest required at inference time to ensure small                SGD (Ben Arous et al., 2021; Damian et al., 2023) or
  RICL
    Ntest , characterizing the statistical complexity of the             single-step gradient descent (Damian et al., 2022; Ba
  constructed in-context learning algorithm.                                    2023; Dandi et al., 2023) on two-layer neural net-
                                                                         et al.,P
                                                                                  m
We consider the regime where Npt , Tpt and Ntest are poly-               work j=1 aj σ(⟨wj , x⟩ + bj ), which can adaptively select
nomial in the dimensionality d, and track the dimension                  feature maps {σ(⟨wj , ·⟩ + bj )}m j=1 , achieves a better sam-
dependence in the sample complexity for both the pretrain-               ple complexity of Õ(dΘ(ie(σ∗ )) ) — such dependence on the
ing and inference phase.                                                 information exponent also appears in correlational statistical
                                                                         query (CSQ) lower bounds (Damian et al., 2022). Recent
2.2     Single-index Models                                              works have shown that data reuse (Arnaboldi et al., 2024;
For the class of target functions f∗ , we consider Gaussian              Lee et al., 2024) or loss modification (Joshi et al., 2024)
single-index models where the function value depends only                can introduce nonlinear label transformations such that
on a single direction β in the d-dimensional input space.                the “effective” information exponent is reduced to ge(σ∗ ).
This setting reflects the scenario where learners have to cap-           Consequently, the sample complexity can be improved to
ture the unknown feature vector β from high-dimensional                  Õ(dge(σ∗ )−1∨1 ) which matches the SQ lower bound Ω(d)
input in Rd , and hence has been extensively studied in fea-             (for polynomial σ∗ ) up to polylogarithmic factors.
ture learning theory literature (Bai & Lee, 2019; Ba et al.,             ICL sample complexity. For the ICL setting, (Oko et al.,
2022; Bietti et al., 2022; Mousavi-Hosseini et al., 2023a;
Mahankali et al., 2023b; Berthier et al., 2024).
                                                                         2024b) studied the single-index function class where   √β
                                                                         is uniformly drawn from the unit sphere in an r(≲ d)-
Definition 2. Let x ∼ N (0, Id ). (Gaussian) single-index                dimensional linear subspace of Rd . The authors derived
models refer to functions of the form                                    a pretraining task and sample complexity of Õ(dΘ(ie(σ∗ )) )
                                                                         and inference-time sample complexity of Õ(rΘ(deg(σ∗ )) ).
             f∗ : Rd → R, f∗ (x) = σ∗ (⟨β, x⟩),
                                                                         Note that this inference complexity matches that of kernel
where σ∗ : R → R is the link function and β is the fea-                  methods on the r-dimensional subspace. Our focus (see
ture vector. We assume σ∗ is a polynomial and satisfies                  Q1 and Q2 in the introduction) is to investigate whether
Ez∼N (0,1) [σ∗ (z)] = 0. We define three key properties:                 transformers can be pretrained to achieve an inference com-
1. deg(σ∗ ) denotes the (polynomial) degree of σ∗ .                      plexity that surpasses kernel methods or CSQ algorithms.

2. The information exponent (Dudeja & Hsu, 2018;
   Ben Arous et al., 2021) is defined as
                                                                         3     Problem Setting
                                                                         3.1   Task Setup
                 ie(σ∗ ) := min{i | H(σ∗ , i) ̸= 0}.
                                                                         We define the task distribution as follows.
3. The generative exponent (Damian et al., 2024) is                      Assumption 4. Let τ = Od (1) be the noise level. A prompt
           ge(σ∗ ) := min2 min{i | H(h ◦ σ∗ , i) ̸= 0},                  (x1 , y1 , . . . , xN , yN , x) is generated as:
                       h∈L
                                                                                 x1 , . . . , xN , x ∼ Dx = N (0, Id ),
             2
      where L denotes the set of all L2 (PY )-measurable
      transformations from R to R for PY = σ∗# N (0, 1)                          yi = f∗ (xi ) + ζi ,   ζi ∼ Unif({−τ, τ }),
      where σ∗# is the push-forward by σ∗ .                                      f∗ (xi ) = σ∗ (⟨β, xi ⟩).

                                                                     4
                             Nonlinear transformers can perform inference-time feature learning

                                                                               =a⊤ σ W F Attn(E):,N +1 + b ,
                                                                                                          
For the true function f∗ , we make the following assumptions:                                                                          (3.1)
 • σ∗ is a polynomial that remains fixed across tasks. We as-
                                                                     where σ is applied entry-wise.
   sume the normalization conditions Ez∼N (0,1) [σ∗ (z)] =
   0 and Ez∼N (0,1) [σ∗2 (z)] = 1.                                   We further introduce some simplifications: we merge pa-
                                                                     rameters as W KQ := (W K )⊤ W Q ∈ R(d+1)×(d+1) and
 • Sr denotes an r-dimensional linear subspace of Rd for
                                                                     W F V := W F W V ∈ Rm×(d+1) , and write
   r ≤ d. For each prompt, β is drawn uniformly from the
   unit sphere Supp(β) := {β | β ∈ Sr , ∥β∥ = 1} in Sr .                           
                                                                                      Γ    0d×1
                                                                                                
                                                                        W KQ =                   , W F V = Om×d v ,
                                                                                                                     
Remark 5. In Assumption 4, a feature vector β is newly                              01×d    1
drawn for each task. We allow for scenarios where β has
limited (r-dimensional) support in Rd , and we will show that        where Γ ∈ Rd×d and v ∈ Rm×1 . Similar simplifications
the inference-time sample complexity adapts to this support.         (zeroing out specific sub-matrices) have been adopted in re-
Note that unlike (Oko et al., 2024b) which established simi-         cent theoretical works on the expressivity and optimization
lar adaptivity, we do not assume low-dimensionality (r =             of transformers (Ahn et al., 2023; Mahankali et al., 2023a;
o(d)); instead our result holds for any 1 ≤ r ≤ d.                   Wu et al., 2023; Kim & Suzuki, 2024a).
                                                                     Consequently, fTF can be rewritten as
3.2   Student Model and Pretraining Algorithm
Student Model. We train a single-layer trans-                                fTF (X, y, x; Γ, v, b, a)
                                                                                                                       !
former (Vaswani et al., 2017) with SoftMax attention.                         m          PN          yi /ρ x⊤
                                                                                                          e i Γx/ρ
                                                                                            i=1 yi e
                                                                             X
For a prompt (x1 , y1 , . . . , xN , yN , x), we construct the             =     aj σ vj PN                        + bj ,              (3.2)
                                                                                                   yi /ρ ex⊤
                                                                                                           i Γx/ρ
embedding E ∈ R(d+1)×(N +1) as                                               j=1             i=1 e


                                                                     with the new parameters (Γ, v, b, a): see Appendix A for
                                   
            x · · · xN x
      E= 1                            ∈ R(d+1)×(N +1) .              the derivation. Hereafter, we refer to Γ as the attention
             y1 · · · yN 1
                                                                     matrix and consider (v, b, a) as the MLP parameters.
We first convert E to Attn(E) through the Softmax atten-             Pretraining Algorithm. In Algorithm 1, we specify our
tion layer defined as                                                gradient-based pretraining algorithm to optimize the pa-
                                                                     rameters (Γ, v, b, a) . The algorithm uses Tpt pretraining
      Attn(E)                                                                   t        t                  Tpt
                                                                     tasks {(X1:N  pt
                                                                                      , y1:Npt
                                                                                               , xt , y t )}t=1 and optimizes the (ℓ2
  =W V E · Softmax(Mask(ρ−1 · (W K E)⊤ W Q E)),                      regularized) squared loss

where ρ > 0 is the temperature, and W K , W Q , W V ∈                    Li (Γ, v, b, a)
R(d+1)×(d+1) are attention parameters. The Softmax func-                       Ti−1 +Ti
tion is applied to each column vector, while the Mask                     1      X
                                                                                                  t        t
                                                                     =                     (fTF (X1:N   , y1:N    , xt ; Γ, v, b, a) − y t )2
function replaces all entries in the final row of ρ−1 ·                  2Ti
                                                                               t=Ti−1 +1
                                                                                                     pt        pt


(W K E)⊤ W Q E ∈ R(N +1)×(N +1) with −∞.
Remark 6. Observe that the first N rows of ρ−1 ·                     for i = 1, 2; here T0 = 0 and T1 + T2 = Tpt . The training
(W K E)⊤ W Q E represent the correlations between x and              procedure is divided into two stages.
xi for i ∈ [N ], while the last row corresponds to the corre-        • In Stage I, we perform a single gradient descent step on the
lation between x and itself.
                           √ Consequently, the last row is             attention matrix Γ using the ℓ2 -regularized squared loss
(typically) approximately d times larger in magnitude than             L1 (Γ, v, b, a) + λ21 ∥Γ∥22 computed over T1 independent
the others. Thus, we apply masking to avoid the Softmax                pretraining tasks. This optimization problem is nonconvex
attention from focusing on the uninformative final row.                with respect to Γ. This single gradient descent update
Then, we apply a position-wise multi-layer perceptron                  originates from theoretical studies on feature learning Ba
(MLP) with activation function σ(·) and parameters W F ∈               et al. (2022); Damian et al. (2022), where it is shown
Rm×(d+1) , b ∈ Rm , and a ∈ Rm , where m is the network                that the first gradient update captures low-dimensional
width. Throughout this paper, we set σ(z) = max{z, 0}                  features of the true function. More recent results have
(ReLU activation). We use the (N + 1)-th element of the                highlighted that one gradient step in transformers can
MLP output as the prediction for the query output. Overall,            encode information for implementing algorithms such as
the model’s prediction fTF is given by                                 kernel methods on low-dimensional subspaces (Oko et al.,
                                                                       2024b) or induction heads (Bietti et al., 2023b).
         fTF (X, y, x; W K , W Q , W V , W F , a, b)                 • In Stage II, we optimize the MLP parameters. Specifically,
       =MLP ◦ Attn(E):,N +1                                            we randomize the weight v and bias b, and perform ridge

                                                                 5
                                     Nonlinear transformers can perform inference-time feature learning

  Algorithm 1 Gradient-based training of transformer                         4.2   Implications of the Main Theorem
  Input : Learning rate η1 , η2 , regularization rate λ1 , λ2 ,              Our main theorem suggests the statistical capabilities and
                           √ α, temperature ρ m
            initialization scale                                             optimization properties of transformers (see Table 4.1).
1 Initialize Γ(0) ∼ Id / d, v(0) ∼ Unif({±1} ), b(0) =
   0m , a(0) = α1m                                                           (i) Inference-Time Feature Learning. First, consider the
2 Stage I: Gradient descent on Attention Matrix                              standard case where r = d: the inference-time sample com-
3     Γ∗ ← Γ(0) − η1 ∇Γ (L1 (Γ(0), v(0), b(0), a(0)) +                       plexity is dΘ(ge(σ∗ )) . Since ge(σ∗ ) ≤ deg(σ∗ ) always holds,
        λ1     2
        2 ∥Γ∥F )                                                             our derived inference-time sample complexity surpasses the
4   Stage II: Optimization of MLP Layer                                      lower bound dΘ(deg(σ∗ )) for non-adaptive algorithms based
5      Initialize b∗j ∼ Unif([−1, 1]) ,v ∗ = v(0).                           on fixed basis such as kernel methods. This implies that
        a∗ ← arg mina L2 (Γ∗ , v ∗ , b∗ , a) + λ22 ∥a∥2 .                    pretrained transformers can implement an algorithm capable
                                                                             of inference-time feature learning, that is, they can adapt to
    Output :Prediction fTF (X, y, x; Γ∗ , v ∗ , b∗ , a∗ ).                   the feature vector β of single-index functions, which varies
                                                                             across test tasks. Beyond merely establishing the inference-
                                                                             time sample complexity, we verify in Section 5 that the
        regression on the output weights a. Note that the only role          attention mechanism indeed captures the feature vector β.
        of the MLP layer is to fit the polynomial link function σ∗ .
        Since our primary focus is the optimization of attention             Moreover, when β is restricted to an r ≤ d-dimensional sub-
        matrix, we adopt this simpler algorithm for MLP which                space in Rd (see Assumption 4), the inference-time sample
        admits a closed-form solution due to the convex objective.           complexity depends only on r. In other words, transformers
                                                                             can significantly reduce the inference-time sample complex-
                                                                             ity when the support of β is low-dimensional, i.e., r ≪ d.
    4      Main Result: Transformer Performs
           Inference-Time Feature Learning                                   (ii) Beyond CSQ. Our result further shows that the
                                                                             inference-time sample complexity can surpass the sample
    4.1     Main Theorem
                                                                             complexity lower bound die(σ∗ )/2∨1 for CSQ algorithms.
    Now we present our main theorem, which establishes an                    For instance, the sample complexity upper bounds for
    optimization guarantee for Algorithm 1 and a bound on the                one-step gradient descent (Ba et al., 2023) and one-pass
    inference-time sample complexity.                                        SGD (Ben Arous et al., 2021) on two-layer neural networks
    Theorem 1. Let fTF (X, y, x; Γ∗ , v ∗ , b∗ , a∗ ) be a                   all depends exponentially on the information exponent. In
    transformer pretrained via Algorithm 1 with MLP                          contrast, in our analysis, the single-layer transformer im-
    width m = Ω̃(r2ge(σ∗ ) ) and initialization scale                        plements an in-context algorithm that is statistically more
    α = O(m−1 r−1 d−(ie(σ∗ )+1)/2 log−Cα d) for constant Cα .                efficient than CSQ learners, due to the nonlinear attention.
    Then, there exist hyperparameters λ1 , λ2 , η1 , and η2 such
    that the following hold with probability at least 0.99 over              (iii) Optimization Guarantee. While recent works have
    the training data and random initialization:                             revealed that nonlinear transformers can implement rich al-
                                                                             gorithms by constructing specific parameter configurations,
    1. (Optimization) Suppose that the pretraining task size                 our result provides an optimization guarantee for pretrain-
       and the pretraining context length satisfy T1 , Npt =                 ing along with the pretraining task/sample complexity of
       Ω̃(r2 die(σ∗ )+2 ) and T2 = Ω̃(r3ge(σ∗ )/2 ) (i.e., Tpt =             dΘ(ie(σ∗ )) for Tpt and Npt (see 1. in Theorem 1). We estab-
       Ω̃(r2 die(σ∗ )+2 ∨ r3ge(σ∗ )/2 )). Then, Algorithm 1 yields           lish this by proving that a single gradient descent step can
       parameters (Γ∗ , v ∗ , b∗ , a∗ ) such that the empirical loss         construct an attention matrix that approximates E[ββ ⊤ ],
                                                                             which enables inference-time feature learning, and that the
             T +T
             1 2
          1 X                                                                MLP layer can successfully fit the link function σ∗ .
                 y t −fTF (X t , y t , xt , Γ∗ , v ∗ , b∗ , a∗ ) = od (1).
          T2
            t=T1 +1                                                          Remark 7. For simplicity of analysis, we assume that the
                                                                             link function σ∗ is fixed across tasks. Task-specific link
          Moreover, we have ∥a∗ ∥ = Õ(r3ge(σ∗ )/4 m−1/2 ).                  functions may be accommodated by adding an additional
    2. (Inference-time sample complexity) At inference time,                 attention layer to fit the link function adaptively from the
       if the (in-context )test prompt length satisfies                      test prompt, as done in (Oko et al., 2024b). An alternative
                                                                             could be to fit the MLP parameter a using each test sample:
                           Ntest = Ω̃(r3ge(σ∗ )/2 ),                         such test-time training constitutes a relatively lightweight
                                                                             optimization, where it only involves training the MLP layer,
                                            ∗   ∗ ∗     ∗
          then the ICL error (2.1) RICL
                                    Ntest (Γ , v , b , a ) =                 since the inner attention layers have already extracted the
          od (1).                                                            relevant feature information ⟨β, x⟩.

                                                                         6
                                Nonlinear transformers can perform inference-time feature learning


                  Regression on test prompt                              the Softmax attention module leads to both (i) inference-
                                                                         time feature learning capability, and (ii) statistical effi-
        Kernel              CSQ                SQ                        ciency that surpasses CSQ algorithms. Observe that the
      dΘ(deg(σ∗ ))        dΘ(ie(σ∗ ))       dΘ(ge(σ∗ ))                                ⊤
                                                                         term eyi /ρ exi Γx/ρ appears in the architecture (3.2), where
                                                                            ⊤
                      In-context learning                                exi Γx/ρ generates a series of polynomials in x via a Her-
        (Oko et al., 2024b)               This work                      mite expansion, which enables detection of the feature di-
                       Θ(ie(σ∗ ))                                        rection β from the nonlinearly transformed signal eyi /ρ ,
       Pretraining: d                Pretraining: dΘ(ie(σ∗ ))
                   Θ(deg(σ∗ ))
                                                                         yielding (i). On the other hand, the factor eyi /ρ reduces
      Inference: r             [*1] Inference: rΘ(ge(σ∗ )) [*2]          the information exponent of σ∗ to its generative exponent
Table 4.1. Comparison of (inference-time) sample complexity.             ge(σ∗ ) through the exponential transformation e·/ρ , yield-
Here, r denotes the dimensionality of the support from which             ing (ii). Hereafter, we outline our analysis step by step.
the task vector β√is drawn (See Assumption 4). [*1] is only appli-
cable when r ≲ d, whereas [*2] holds for any r ≤ d.                      5.1   Gradient Descent on Attention Matrix
                                                                         Assuming that fTF is sufficiently small at initialization, we
4.3    Comparison Against Prior Work                                     can approximate the population (expected) gradient by the
Most recent studies on single-index models have focused                  population correlational gradient E[y∇Γ fTF ]. We show
on the standard supervised regression setting rather than in-            that the magnitude of this correlation is O(d−(ie(σ∗ )−1)/2 ).
context learning, with the exception of (Oko et al., 2024b)              A standard matrix concentration argument then yields the re-
which investigates the ICL complexity of single-index learn-             quired pretraining task and sample complexity of dΘ(ie(σ∗ )) ,
ing under a low-dimensional assumption. Here we highlight                ensuring that the correlational signal is not hidden within
the distinction from the work; see Table 4.1 for the compari-            the noise due to finite sample size.
son of relevant sample complexities.                                     Furthermore, we demonstrate that the single-step gradient
(i) Improved ICL sample complexity. In (Oko et al.,                      on Γ is approximately proportional to E[ββ ⊤ ]. This implies
2024b), the derived inference-time sample complexity is                  that the attention matrix acquires information about the r-
O(rΘ(deg(σ∗ )) ), which corresponds to the complexity of                 dimensional support of β via pretraining, leading to an
non-adaptive methods (for instance, kernel methods) on                   inference-time sample complexity independent of d.
an r-dimensional subspace. In contrast, we establish an
                                                                         5.2   Feature Extraction by Softmax Attention
improved sample complexity of O(rΘ(ge(σ∗ )) ).
                                                                         Next we show that the pretrained attention module can
(ii) Removal of low-dimensional assumption. (Oko                         extract the feature information ⟨β, x⟩ directly from ob-
et al., 2024b) assumed that the dimensionality r of pre-                                  prompt. Recall that the model output is
                                                                         serving the test P
training task distribution is much smaller than the ambient                                 m
                                                                         given by fTF = j=1 aj σ(vj g(X, y, x; Γ∗ ) + bj ), where
dimensionality d, whereas our analysis do not rely on this                                                   yi /ρ x⊤
                                                                                            N −1                  e i Γx/ρ
                                                                                                   PN
                                                                                                    i=1 yi e
assumption.                                                              g(X, y, x; Γ) :=        −1
                                                                                                    PN             ⊤
                                                                                                           yi /ρ exi Γx/ρ
                                                                                                                             is the attention
                                                                                             N       i=1 e
(iii) Technical innovations. To derive the improved                      output. We establish the following proposition, which
inference-time sample complexity, we demonstrate that the                demonstrates that g contains the feature information:
nonlinear transformation applied to the output label {yi } re-           Proposition 8 (Informal). Suppose Ntest = Ω̃(r3ge(σ∗ )/2 ).
duces the information exponent of the link function σ∗ to its            For Γ∗ optimized in Algorithm 1, we have
generative exponent. This requires a careful tracking of the
                                                                                                                            ge(σ∗ )
corresponding Hermite coefficients through a SoftMax at-                                                            ⟨x, β⟩
tention block, which constitutes one of the most technically                    g(X, y, x; Γ∗ ) ≃ Ca + Cb            √
                                                                                                                        r
challenging parts of the analysis. This goes beyond (Oko
et al., 2024a) where the authors showed that a linear atten-             with high probability over the prompt, where Ca and Cb are
tion computes correlations on the raw label {yi } and a fixed            Θ(1/poly log d) quantities independent of the data.
kernel basis {ϕ(xi )} (constructed by a fixed MLP block).
                                                                         We see that the nonlinearity introduced by the Softmax
See the next section for the technical overview.
                                                                         attention plays a key role in deriving the proposition above.

5     Proof Overview                                                     Warm-Up: Linear Attention Module. First consider
                                                                         the counterpart of g with  PN a linear attention module
We provide a proof sketch for our main Theorem 1, where                  glin (X, y, x; Γ) := N −1 i=1 yi (yi + x⊤ i Γx). If the con-
the main goal is to show that the self-attention mechanism               text length N is sufficiently large, the second term con-
provably extracts the feature vector β for each prompt.                  centrates around E[yx⊤ ]Γx. Moreover, it is known that
The key idea is that the exponential transformation in                   if Ez∼N (0,1) [zσ∗ (z)] ̸= 0, or equivalently, ie(σ∗ ) = 1,

                                                                     7
                                    Nonlinear transformers can perform inference-time feature learning

then E[yx⊤ ] = β ⊤ is satisfied. Overall, the attention mod-                  Finally, we bound the discrepancy between the training and
ule successfully computes β ⊤ Γx ≃ β ⊤ x in-context, if Γ                     test errors via the Rademacher complexity of the class of
is (nearly) spanned by β. However, if ie(σ∗ ) > 1, then                       transformers, leveraging a norm bound on ∥a∗ ∥ derived
E[yx⊤ ] = 0 and the direction β is not identified. Thus we                    from that of ∥a′ ∥. See Appendices D and E for details.
must exploit the nonlinearity to handle high-information-
exponent scenarios.                                                           6                  Synthetic Experiment
Exploiting Softmax. To consider the nonlinear attention,                      We conduct numerical experiments on synthetic data to
we first show that the exponential transformation can reduce                  compare the in-context learning algorithm implemented by
the information exponent of σ∗ to its generative exponent.                    nonlinear transformers against non-adaptive kernel methods.
Specifically, we show the following:                                          We train a 6-layer GPT-2 model (Radford et al., 2019) to
Lemma 9 (Informal). The information exponent of exp(σ̄∗ )                     learn the Gaussian single-index task. See Appendix G for
and σ̄∗ exp(σ̄∗ ) is equal to ge(σ∗ ), where σ̄∗ is a clipped                 detailed settings of the experiments.
version of σ∗ /ρ (see Appendix B).                                                                     1.4
Based on this property, we show that Softmax attention                                                 1.2
can compute ⟨x, β⟩ in-context for any polynomial link σ∗ ;
                                               ⊤
                                                                                                       1.0



                                                                                Generalization error
                                  PN
consider the denominator N −1 i=1 eyi /ρ exi Γx/ρ of g.
For N sufficiently large, the quantity approximates
                                                                                                       0.8
   Ex1 ∼N (0,Id ) [exp σ¯∗ (⟨β, x1 /ρ⟩)exp (⟨Γx, x1 ⟩ /ρ)] .
                                                                                                       0.6
Now we consider Hermite expansions of exp σ¯∗ (⟨β, x1 /ρ⟩)
                                                                                                       0.4     d=4
and exp (⟨Γx, x1 ⟩ /ρ), and apply the property                                                                 d=8
Ex1 [Hei (⟨w, x1 ⟩)Hej (⟨w′ , x1 ⟩)] ∝ I(i = j) ⟨w, w′ ⟩.                                              0.2     d=12
Fortunately, exp (⟨Γx, x1 ⟩ /ρ) contains all degrees                                                           d=16
of Hermite components, and from the lemma above,                                                       0.0   20     40      60       80   100     120
exp σ¯∗ (⟨β, x1 /ρ⟩) has a nonzero coefficient for Hege(σ∗ ) .                                                           Context length
                                              ge(σ∗ )
Thus, the attention module computes ⟨β, x⟩            if Γ is                                         1.4
nearly spanned by β. Crucially, since the correlational                                                                                         d=4
signal strength depends only on the generative exponent                                               1.2                                       d=8
ge(σ∗ ), the required context length N does not scale with                                                                                      d=12
                                                                                                      1.0                                       d=16
                                                                               Generalization error




ie(σ∗ ).
We also show that the numerator of g retains this feature                                             0.8
information. The remaining technical challenge is to ensure
that the information is not lost due to the correlation between                                       0.6
the denominator and numerator: we tackle this through a
careful order analysis. See Appendix B for details.                                                   0.4
                                                                                                      0.2
5.3    Fitting the MLP Layer and Test Error Analysis
To complete the optimization analysis, we show that the                                               0.0    20    40       60       80   100     120
MLP layer can fit the unknown link function via ridge re-                                                                Context length
gression (line 5 in Algorithm 1). First, we construct an MLP
                                                                              Figure 6.1. Generalization error versus test prompt length for ker-
parameter a′ such that
                                                                              nel ridge regression (Top) and pretrained GPT-2 model (Bottom).
            1 +T2
           TX
      1                                                              2
                     y t − fTF (X t , y t , xt , Γ∗ , v ∗ , b∗ , a′ )
      T2                                                                      6.1                      Comparison with Non-Adaptive Algorithm
           t=T1 +1
                                                                              For each test task t, we generate data as xt1 , . . . , xtNtest , x ∼
is sufficiently small. Let ℓ(a′ ) be the quantity above:
                                                                              N (0, Id ), β t ∼ Unif(Sd−1 ) (i.e., r = d),with yit =
thanks to the equivalence between the ℓ2 -regularized con-
                                                                              σ∗ (⟨β t , xti ⟩) = He3 (⟨β t , xti ⟩) for i ∈ [N ]. We compare
vex optimization and its norm-constrained counterpart, we
                                                                              the performance of two approaches:
can show that there exists a ridge parameter λ2 such that
ℓ(a∗ ) ≤ ℓ(a′ ) and ∥a∗ ∥ ≤ ∥a′ ∥ hold, where a∗ is the                       • In-context learning using a 6-layers GPT-2 model, con-
parameter obtained by solving ridge regression.                                 figured as in (Garg et al., 2022; Oko et al., 2024b). We

                                                                          8
                                                                Nonlinear transformers can perform inference-time feature learning

  pretrain the GPT-2 model using on synthetic datasets                                               that the Softmax attention can extract feature information
      t         t                 Tpt
  {X1:N  pt
            , y1:N pt
                      , xt , y t }t=1 , and evaluate its estimation                                  by leveraging nonlinear transformations applied to labels.
          1        Ttest t                   t          t
                                                                 , xt ))2
                P
  error Ttest t=1 (y − fGPT2 (X1:N              test
                                                     , y1:N test
                                                                                                     We outline several future directions. First, the pretraining
  across different values of Ntest and d.                                                            procedure and its current sample complexity of dΘ(ie(σ∗ ))
• Kernel method based on the Gaussian RBF kernel                                                    may potentially be improved to dΘ(ge(σ∗ )) by going beyond
  k(x, x′ ) = exp −∥x − x′ ∥2 /σ 2 . For each task, the                                              one gradient step (Dandi et al., 2024; Arnaboldi et al., 2024;
  kernel is trained from scratch using the test prompt                                               Lee et al., 2024). Second, extending our analysis to broader
     t
  (X1:N          t
             , y1:N      ) as training data.                                                         function classes – such as non-polynomial σ∗ , multi-index
        test        test
                                                                                                     targets, or anisotropic covariates (Ghorbani et al., 2020; Re-
We set d = 4, 8, 12, 16 and measure the test error at Ntest =                                        finetti et al., 2021; Mousavi-Hosseini et al., 2023b) – is an-
⌊2k − 1⌋ (k = 2, 2.5, . . . , 7). In Figure 6.1 we observe that                                      other interesting direction. Finally, while our study demon-
the performance of kernel models deteriorates rapidly due to                                         strates both “memorization” of the r-dimensional support of
the sample complexity lower bound ddeg(σ∗ ) = d3 , whereas                                           the target function class and inference-time feature learning,
the pretrained transformer exhibits a much more favorable                                            it remains an open question whether a tradeoff or certain
dimension scaling in the in-context sample complexity.                                               interaction exists between these two mechanisms.
6.2                                   Sample Complexity Scaling
                                                                                                     Acknowledgements
To further validate our theoretical claim that pretrained trans-
formers can achieve test-time sample complexity beyond the                                           NN was partially supported by JST ACT-X (JPMJAX24CK)
CSQ lower bound, we conduct a sample complexity probing                                              and JST BOOST (JPMJBS2418). YS was partially sup-
experiment under the same setting as in Section 6.1. In                                              ported by JST CREST (JPMJCR2115). TS was partially
Figure 6.2, we vary the input dimensionality d and measure                                           supported by JSPS KAKENHI (24K02905) and JST CREST
the minimal number of samples required to reach specified                                            (JPMJCR2015). This research is supported by the National
test error thresholds. The estimated inference-time sample                                           Research Foundation, Singapore and the Ministry of Dig-
complexity scales approximately as n ≃ d1.1 , outperform-                                            ital Development and Information under the AI Visiting
ing both the kernel lower bound of d3 and the CSQ lower                                              Professorship Programme (award number AIVP-2024-004).
bound of n ≳ d1.5 for the link function σ∗ (·) = He3 (·)                                             Any opinions, findings and conclusions or recommenda-
which has information exponent 3.                                                                    tions expressed in this material are those of the author(s)
                                                                                                     and do not reflect the views of National Research Founda-
                                                                                                     tion, Singapore and the Ministry of Digital Development
 First N_test to achieve threshold




                                        102                                                          and Information.

                                                                                                     Impact Statement
                                     6 × 101
                                                                                                     This paper presents work whose goal is to advance the field
                                                                                                     of Machine Learning. There are many potential societal
                                     4 × 101   slope=1.16
                                                                               threshold=0.05        consequences of our work, none which we feel must be
                                               slope=1.14                      threshold=0.075       specifically highlighted here.
                                     3 × 101   slope=1.13                      threshold=0.1
                                               slope=1.15                      threshold=0.125
                                                                 101
                                                            Input dimensionality d                   References
                                                                                                     Abbe, E., Adsera, E. B., and Misiakiewicz, T. The merged-
Figure 6.2. Sample complexity of pretrained GPT-2 on the degree-                                       staircase property: a necessary and nearly sufficient con-
3 single-index task y = He3 (⟨β, x⟩). We plot the minimal test-                                        dition for sgd learning of sparse functions on two-layer
time sample size Ntest required to achieve test error thresholds                                       neural networks. In Conference on Learning Theory, pp.
(0.05, 0.075, 0.1, 0.125) against input dimensionality d on log-log                                   4782–4887. PMLR, 2022.
scale. The slope of each plot is estimated using least squares.
                                                                                                     Abbe, E., Adsera, E. B., and Misiakiewicz, T. SGD learning
                                                                                                       on neural networks: leap complexity and saddle-to-saddle
7                                    Conclusion and Future Direction
                                                                                                       dynamics. In Conference on Learning Theory, pp. 2552–
We studied in-context learning of single-index polynomi-                                               2623. PMLR, 2023.
als and demonstrated that pretrained transformers achieve
inference-time sample complexity that surpasses both kernel                                          Ahn, K., Cheng, X., Daneshmand, H., and Sra, S. Trans-
methods and CSQ lower bounds. Our analysis highlights                                                  formers learn to implement preconditioned gradient de-

                                                                                                 9
                             Nonlinear transformers can perform inference-time feature learning

  scent for in-context learning. Advances in Neural Infor-           Bietti, A., Bruna, J., and Pillaud-Vivien, L. On learning
  mation Processing Systems, 36, 2023.                                 Gaussian multi-index models with gradient flow. arXiv
                                                                       preprint arXiv:2310.19793, 2023a.
Akyürek, E., Schuurmans, D., Andreas, J., Ma, T., and
  Zhou, D. What learning algorithm is in-context learn-              Bietti, A., Cabannes, V., Bouchacourt, D., Jegou, H., and
  ing? investigations with linear models. arXiv preprint               Bottou, L. Birth of a transformer: A memory view-
  arXiv:2211.15661, 2022.                                              point. In Thirty-seventh Conference on Neural Infor-
                                                                       mation Processing Systems, 2023b. URL https://
Arnaboldi, L., Dandi, Y., Krzakala, F., Pesce, L., and
                                                                       openreview.net/forum?id=3X2EbBLNsk.
  Stephan, L. Repetita iuvant: Data repetition allows sgd
  to learn high-dimensional multi-index functions. arXiv             Brown, T., Mann, B., Ryder, N., Subbiah, M., Kaplan, J. D.,
  preprint arXiv:2405.15459, 2024.                                     Dhariwal, P., Neelakantan, A., Shyam, P., Sastry, G.,
                                                                       Askell, A., et al. Language models are few-shot learners.
Ba, J., Erdogdu, M. A., Suzuki, T., Wang, Z., Wu, D., and
                                                                       Advances in Neural Information Processing Systems, 33,
  Yang, G. High-dimensional asymptotics of feature learn-
                                                                       2020.
  ing: How one gradient step improves the representation.
  Advances in Neural Information Processing Systems, 35,             Bu, D., Huang, W., Han, A., Nitanda, A., Suzuki, T., Zhang,
  2022.                                                                Q., and Wong, H.-S. Provably transformers harness multi-
                                                                       concept word semantics for efficient in-context learning.
Ba, J., Erdogdu, M. A., Suzuki, T., Wang, Z., and Wu, D.
                                                                       arXiv preprint arXiv:2411.02199, 2024.
  Learning in the presence of low-dimensional structure: A
  spiked random matrix perspective. Advances in Neural               Chen, S., Sheen, H., Wang, T., and Yang, Z. Training
  Information Processing Systems, 36, 2023.                            dynamics of multi-head softmax attention for in-context
Bach, F. Breaking the curse of dimensionality with convex              learning: Emergence, convergence, and optimality. arXiv
  neural networks. Journal of Machine Learning Research,               preprint arXiv:2402.19442, 2024.
  18(19):1–53, 2017.                                                 Cheng, X., Chen, Y., and Sra, S. Transformers implement
Bai, Y. and Lee, J. D. Beyond linearization: On quadratic              functional gradient descent to learn non-linear functions
  and higher-order approximation of wide neural networks.              in context. arXiv preprint arXiv:2312.06528, 2023.
  arXiv preprint arXiv:1910.01619, 2019.                             Damian, A., Lee, J., and Soltanolkotabi, M. Neural net-
Bai, Y., Chen, F., Wang, H., Xiong, C., and Mei, S. Trans-             works can learn representations with gradient descent. In
  formers as statisticians: Provable in-context learning with          Conference on Learning Theory, pp. 5413–5452. PMLR,
  in-context algorithm selection. Advances in Neural Infor-            2022.
  mation Processing Systems, 36, 2023.                               Damian, A., Nichani, E., Ge, R., and Lee, J. D. Smoothing
Barak, B., Edelman, B., Goel, S., Kakade, S., Malach, E.,              the landscape boosts the signal for SGD: Optimal sample
  and Zhang, C. Hidden progress in deep learning: Sgd                  complexity for learning single index models. Advances
  learns parities near the computational limit. Advances in            in Neural Information Processing Systems, 36, 2023.
  Neural Information Processing Systems, 35, 2022.
                                                                     Damian, A., Pillaud-Vivien, L., Lee, J. D., and Bruna, J. The
Ben Arous, G., Gheissari, R., and Jagannath, A. Online                 computational complexity of learning gaussian single-
  stochastic gradient descent on non-convex losses from                index models. arXiv preprint arXiv:2403.05529, 2024.
  high-dimensional inference. The Journal of Machine
                                                                     Dandi, Y., Krzakala, F., Loureiro, B., Pesce, L., and Stephan,
  Learning Research, 22(1):4788–4838, 2021.
                                                                       L. How two-layer neural networks learn, one (giant) step
Berthier, R., Montanari, A., and Zhou, K. Learning time-               at a time. arXiv preprint arXiv:2305.18270, 2023.
  scales in two-layers neural networks. arXiv preprint
                                                                     Dandi, Y., Troiani, E., Arnaboldi, L., Pesce, L., Zdeborová,
  arXiv:2303.00055, 2023.
                                                                       L., and Krzakala, F. The benefits of reusing batches for
Berthier, R., Montanari, A., and Zhou, K. Learning time-               gradient descent in two-layer networks: Breaking the
  scales in two-layers neural networks. Foundations of                 curse of information and leap exponents. arXiv preprint
  Computational Mathematics, pp. 1–84, 2024.                           arXiv:2402.03220, 2024.

Bietti, A., Bruna, J., Sanford, C., and Song, M. J. Learn-           Donhauser, K., Wu, M., and Yang, F. How rotational invari-
  ing single-index models with shallow neural networks.                ance of common kernels prevents generalization in high
  Advances in Neural Information Processing Systems, 35,               dimensions. In International Conference on Machine
  2022.                                                                Learning, pp. 2804–2814. PMLR, 2021.

                                                                10
                            Nonlinear transformers can perform inference-time feature learning

Dudeja, R. and Hsu, D. Learning single-index models in           Kim, J. and Suzuki, T. Transformers learn nonlinear fea-
  gaussian space. In Conference On Learning Theory, pp.            tures in context: Nonconvex mean-field dynamics on the
 1887–1930. PMLR, 2018.                                            attention landscape. arXiv preprint arXiv:2402.01258,
                                                                   2024a.
Garg, S., Tsipras, D., Liang, P. S., and Valiant, G. What
  can transformers learn in-context? a case study of sim-        Kim, J. and Suzuki, T. Transformers provably solve parity
  ple function classes. Advances in Neural Information             efficiently with chain of thought, 2024b. URL https:
  Processing Systems, 35, 2022.                                    //arxiv.org/abs/2410.08633.

Gatmiry, K., Saunshi, N., Reddi, S. J., Jegelka, S., and         Kim, J., Nakamaki, T., and Suzuki, T. Transformers are min-
  Kumar, S. Can looped transformers learn to implement             imax optimal nonparametric in-context learners. arXiv
  multi-step gradient descent for in-context learning? In          preprint arXiv:2408.12186, 2024.
  International Conference on Machine Learning, 2024.
                                                                 Kingma, D. P. and Ba, J. Adam: A method for stochastic
Ghorbani, B., Mei, S., Misiakiewicz, T., and Monta-                optimization. In International Conference on Learning
  nari, A. Limitations of lazy training of two-layers              Representations, 2015.
  neural network.      In Wallach, H., Larochelle, H.,
                                                              Lee, J. D., Oko, K., Suzuki, T., and Wu, D. Neural
  Beygelzimer, A., d'Alché-Buc, F., Fox, E., and Garnett,
                                                                network learns low-dimensional polynomials with sgd
  R. (eds.), Advances in Neural Information Process-
                                                                near the information-theoretic limit. arXiv preprint
  ing Systems, volume 32. Curran Associates, Inc.,
                                                                arXiv:2406.01581, 2024.
  2019. URL https://proceedings.neurips.
  cc/paper_files/paper/2019/file/                             Li, H., Wang, M., Lu, S., Cui, X., and Chen, P.-Y. Training
  c133fb1bb634af68c5088f3438848bfd-Paper.                       nonlinear transformers for efficient in-context learning:
  pdf.                                                          A theoretical learning and generalization analysis. CoRR,
                                                                abs/2402.15607, 2024. URL https://doi.org/10.
Ghorbani, B., Mei, S., Misiakiewicz, T., and Montanari, A.
                                                                48550/arXiv.2402.15607.
  When do neural networks outperform kernel methods?
  Advances in Neural Information Processing Systems, 33:      Mahankali, A., Hashimoto, T. B., and Ma, T. One step of
  14820–14830, 2020.                                            gradient descent is provably the optimal in-context learner
                                                                with one layer of linear self-attention. arXiv preprint
Ghorbani, B., Mei, S., Misiakiewicz, T., and Montanari, A.      arXiv:2307.03576, 2023a.
  Linearized two-layers neural networks in high dimension.
  The Annals of Statistics, 49(2):1029–1054, 2021.            Mahankali, A., Zhang, H., Dong, K., Glasgow, M., and Ma,
                                                                T. Beyond ntk with vanilla gradient descent: A mean-
Glasgow, M. SGD finds then tunes features in two-layer          field analysis of neural networks with polynomial width,
  neural networks with near-optimal sample complexity:          samples, and time. Advances in Neural Information Pro-
  A case study in the XOR problem. In The Twelfth               cessing Systems, 36, 2023b.
  International Conference on Learning Representations,
  2024. URL https://openreview.net/forum?                     Mousavi-Hosseini, A., Park, S., Girotti, M., Mitliagkas, I.,
  id=HgOJlxzB16.                                                and Erdogdu, M. A. Neural networks efficiently learn low-
                                                                dimensional representations with SGD. In International
Guo, T., Hu, W., Mei, S., Wang, H., Xiong, C., Savarese,        Conference on Learning Representations, 2023a.
  S., and Bai, Y. How do transformers learn in-context
  beyond simple functions? a case study on learning with      Mousavi-Hosseini, A., Wu, D., Suzuki, T., and Erdogdu,
  representations. arXiv preprint arXiv:2310.10616, 2023.       M. A. Gradient-based feature learning under structured
                                                                data. Advances in Neural Information Processing Sys-
Huang, Y., Cheng, Y., and Liang, Y. In-context convergence      tems, 36, 2023b.
  of transformers. arXiv preprint arXiv:2310.05249, 2023.
                                                              Nichani, E., Damian, A., and Lee, J. D. How transform-
Joshi, N., Misiakiewicz, T., and Srebro, N. On the com-         ers learn causal structure with gradient descent. arXiv
  plexity of learning sparse functions with statistical and     preprint arXiv:2402.14735, 2024.
  gradient queries. arXiv preprint arXiv:2407.05622, 2024.
                                                              Oko, K., Song, Y., Suzuki, T., and Wu, D. Learning sum
Kearns, M. Efficient noise-tolerant learning from statistical   of diverse features: computational hardness and efficient
  queries. Journal of the ACM (JACM), 45(6):983–1006,           gradient-based training for ridge combinations. arXiv
  1998.                                                         preprint arXiv:2406.11828, 2024a.

                                                            11
                            Nonlinear transformers can perform inference-time feature learning

Oko, K., Song, Y., Suzuki, T., and Wu, D. Pretrained trans-         Yang, T., Huang, Y., Liang, Y., and Chi, Y. In-context
  former efficiently learns low-dimensional target func-              learning with representations: Contextual generalization
  tions in-context, 2024b. URL https://arxiv.org/                     of trained transformers. arXiv preprint arXiv:2408.10147,
  abs/2411.02544.                                                     2024.

Radford, A., Wu, J., Child, R., Luan, D., Amodei, D., and           Zhang, R., Frei, S., and Bartlett, P. L. Trained trans-
  Sutskever, I. Language models are unsupervised multitask            formers learn linear models in-context. arXiv preprint
  learners. 2019.                                                     arXiv:2306.09927, 2023.

Refinetti, M., Goldt, S., Krzakala, F., and Zdeborová, L.          Zhang, R., Wu, J., and Bartlett, P. L. In-context learn-
  Classifying high-dimensional gaussian mixtures: Where               ing of a linear transformer block: Benefits of the mlp
  kernel methods fail and neural networks succeed. In                 component and one-step gd initialization. arXiv preprint
  International Conference on Machine Learning, pp. 8936–             arXiv:2402.14951, 2024.
  8947. PMLR, 2021.

Ren, Y., Nichani, E., Wu, D., and Lee, J. D. Emergence and
  scaling laws in sgd learning of shallow neural networks.
  arXiv preprint arXiv:2504.19983, 2025.

Reyzin, L.    Statistical queries and statistical algo-
  rithms: Foundations and applications. arXiv preprint
  arXiv:2004.00557, 2020.

Suzuki, T. Adaptivity of deep reLU network for learning
  in besov and mixed smooth besov spaces: optimal rate
  and curse of dimensionality. In International Conference
  on Learning Representations, 2019. URL https://
  openreview.net/forum?id=H1ebTsActm.

Suzuki, T., Wu, D., Oko, K., and Nitanda, A. Feature learn-
  ing via mean-field langevin dynamics: classifying sparse
  parities and beyond. In Oh, A., Naumann, T., Globerson,
  A., Saenko, K., Hardt, M., and Levine, S. (eds.), Advances
  in Neural Information Processing Systems, volume 36,
  pp. 34536–34556. Curran Associates, Inc., 2023.

Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones,
  L., Gomez, A. N., Kaiser, L. u., and Polosukhin, I. At-
  tention is all you need. In Guyon, I., Luxburg, U. V.,
  Bengio, S., Wallach, H., Fergus, R., Vishwanathan, S.,
  and Garnett, R. (eds.), Advances in Neural Information
  Processing Systems, volume 30. Curran Associates, Inc.,
  2017.

Von Oswald, J., Niklasson, E., Randazzo, E., Sacramento,
  J., Mordvintsev, A., Zhmoginov, A., and Vladymyrov,
  M. Transformers learn in-context by gradient descent.
  In International Conference on Machine Learning, pp.
  35151–35174. PMLR, 2023.

Wainwright, M. J. High-Dimensional Statistics: A Non-
 Asymptotic Viewpoint. Cambridge University Press, 2019.

Wu, J., Zou, D., Chen, Z., Braverman, V., Gu, Q., and
 Bartlett, P. L. How many pretraining tasks are needed for
 in-context learning of linear regression? arXiv preprint
 arXiv:2310.08391, 2023.

                                                               12
                             Nonlinear transformers can perform inference-time feature learning

A     Preliminaries
A.1   High Probability Events
We frequently use the term “with high probability” or “w.h.p.”:
Definition 10. We state that an event A occurs with high probability, when

                                                     P[A] ≥ 1 − d−Cwhp

holds for a sufficiently large constant Cwhp . Here, Cwhp depends on neither d nor r.
An illustrative example is Gaussian tail bound: for z ∼ N (0, 1) and t ≥ 0, it holds that

                                                 P[z > t] ≤ exp −t2 /2 .
                                                                 

                                                                                                                 −Cwhp
           p                                                p
Plugging 2Cwhp log d into t above, √ we can see that z ≤ 2Cwhp log d holds with probability at least 1 − d              . In
this situation, we say that “z ≤ O( log d) with
                                             √   high probability”—this means   that we can redefine Cwhp to be sufficiently
large, by changing the hidden constant in O( log d).
Throughout this paper, whenever we take the intersection of high-probability events A1 , . . . , Am , m = O(polyd) is always
ensured. Thus, (by redefining Cwhp ,) we can state that A1 ∩ · · · ∩ Am also occurs with high probability.
Moreover, we consider the high-dimensional setting, i.e., our result holds for all d ≥ Chd where Chd is a constant
independent of both d and r.
Unless otherwise specified, the notations O, Θ, Ω, Õ, Θ̃, Ω̃ are considered with respect to d. Note that we allow r to scale
with d, while treating deg(σ∗ ) as an O(1) quantity.

A.2   Estimator Constructed by Single-Layer Transformer
We now show that the estimator constructed by the transformer (3.1) is explicitly written as in (3.2), given our parameter
configuration                                              
                                                 Γ     0d×1
                                   W KQ =                    , W F V = Om×d v .
                                                                                     
                                               01×d     1
                                                                                                               
                                                                                             x1 · · · xN x
From (3.1) and the configuration above, the estimator fTF is written as, recalling that E =                      ,
                                                                                              y1 · · · yN 1

                      fTF = a⊤ σ(W F V ESoftmax(Mask(ρ−1 E ⊤ W KQ E:,N +1 )) + b)
                                                      ⊤                     
                                                           x1 Γx/ρ + y1 /ρ
                                                               ..           
                          = a⊤ σ W F V ESoftmax 
                                                                .        + b
                                                                               
                                                     x⊤ Γx/ρ + yN /ρ        
                                                            N
                                                                 −∞
                                                                     ⊤                   
                                                                        x1 Γx/ρ + y1 /ρ
                                                                          ..            
                          = a⊤ σ  vy1 · · · vyN v Softmax                   .
                                                          
                                                                                         + b
                                                                                         
                                                                    x⊤ Γx/ρ + yN /ρ      
                                                                         N
                                                                             −∞
                             m
                                                                     !
                                                  yi /ρ x⊤
                                       PN
                                             y  e      e  i Γx/ρ
                                              i
                            X
                          =     aj σ vj Pi=1
                                          N
                                                                 + bj .
                                                yi /ρ ex⊤i Γx/ρ
                            j=1           i=1 e

Hence we obtain (3.2).

B     In-Context Feature Extraction via Softmax Self-Attention Module
We show that the softmax self-attention has the ability to extract the feature vector β of the single-index function σ∗ (⟨x, β⟩)
(this section precedes the optimization analysis, as the techniques developed here are later utilized in the optimization
theory). Crucially, we show that the nonlinear transformation applied to y via softmax attention module reduces the effective

                                                              13
                                  Nonlinear transformers can perform inference-time feature learning

information exponent. Consequently, the generative exponent (Damian et al., 2024) of the link function σ∗ governs the
inference-time complexity, which surpasses the CSQ limit (Damian et al., 2022). Let

                                                                            yi /ρ x⊤
                                                                 PN
                                                                   i=1 yi e      e i Γx/ρ
                                              g(X, y, x; Γ) :=    PN y /ρ x⊤ Γx/ρ                                           (B.1)
                                                                    i=1 e       e i
                                                                           i



be the output of the attention layer. The goal of this section is to show the following Proposition 11, stating that g can extract
the inner product between x and β which varies across tasks.
Proposition 11. Let ρ = Θ(logCρ d) and κ = Θ(logCκ d) where Cρ and Cκ are any constants satisfying Cρ ≥ deg(σ∗ )/2+
                                                                                                                 1
1 and Cκ ≥ max{2Cρ ege(σ∗ ) (σ∗ ) + 1, 4 deg(σ∗ ) − 4} (ei (σ∗ ) is defined in Definition 14). Suppose Γ = κ√      r
                                                                                                                     G for a
matrix G written as
                                                         G = U ⊤ DU + N ,                                              (B.2)
                                                                                                                 √
where D := diag(1, . . . , 1, 0, . . . , 0), U is an orthogonal matrix, and N is a matrix satisfying ∥N ∥F = O(1/ d).
                  | {z } | {z }
                        r           d−r
                   3ge(σ∗ )/2
Now, if N = Ω̃(r                ), then with high probability over length-N prompts (X1:N , y1:N , x), it holds that

                                 g(X, y, x; Γ)
                                                  ge(σ∗ )
                                           ⟨Gx, β⟩
                                =P1 + P2      √             + od (P2 r−3ge(σ∗ )/4 log−2 deg(σ∗ )+2 d).                      (B.3)
                                                r

Here, P1 and P2 are independent of the data and satisfies P1 = od (1) and P2 = Θd (log d)−CP2 , where CP2 is a constant
                                                                                                       

dependent on σ∗ but is uniformly upper bounded using deg(σ∗ ) and odd(σ∗ ) := Ez∼N (0,1) [σ∗,odd (z)2 ], where σ∗,odd (·) is
a polynomial constructed by extracting only the odd parts of σ∗ .
                                                                           √                              √
Remark 12. Later we will show that Γ after pretraining satisfies Γ ≃ rEβ [ββ ⊤ ] = U ⊤ DU / r, which matches the
condition of Proposition 11. Since U is spanned by the basis of the support of β in this case, ⟨Gx, β⟩ in (B.3) satisfies
⟨Gx, β⟩ ≃ ⟨x, β⟩. This implies that, if the context length at inference time is Ω̃(rge(σ∗ ) ), then the pretrained attention layer
can extract the feature vector β which varies across different prompts and compute ⟨x, β⟩. This highlights the inference-time
feature learning ability of the pretrained attention layer. Moreover, the inference-time sample complexity depends on
neither deg(σ∗ ) nor ie(σ∗ ), which surpasses kernel and CSQ methods. The factor log−2 deg(σ∗ )+2 d in the residual term is
introduced just for compatibility with later stages.

Preparations. We use the following property, which states that there exists a polynomial transformation which reduces
the information exponent of σ∗ to its generative exponent. Recall that H(f, i) denotes the degree-i Hermite coefficient of f
(that is, f (z) = i≥0 H(f,i)
                 P
                        i! Hei (z)).
Lemma 13 ((Lee et al., 2024), Proposition 6). The following holds:

   • If ge(σ∗ ) = 1, then there exists i ≤ C1 (deg(σ∗ ), odd(σ∗ )) such that |H(σ∗i , 1)| ≥ D1 (deg(σ∗ ), odd(σ∗ )).

   • If ge(σ∗ ) = 2, then there exists i ≤ C2 (deg(σ∗ )) such that |H(σ∗i , 2)| ≥ D2 (deg(σ∗ )).

Here, C1 (deg(σ∗ ), odd(σ∗ )) and D1 (deg(σ∗ ), odd(σ∗ )) are constants which only depend on deg(σ∗ ) and odd(σ∗ ) :=
Ez∼N (0,1) [σ∗,odd (z)2 ] where σ∗,odd (·) is a polynomial constructed by extracting only the odd parts of σ∗ . Similarly,
C2 (deg(σ∗ )) and D2 (deg(σ∗ )) are constants depending only on deg(σ∗ ).
Definition 14. For i ≥ 1, let ei (σ∗ ) be the minimal j ≥ 1 such that H(σ∗j , i) ̸= 0 holds. If such j does not exist, then define
ei (σ∗ ) = ∞. (Especially from Lemma 13, ege(σ∗ ) (σ∗ ) can be uniformly upper bounded using the degree and the odd part of
σ∗ .)

Another key property is that y is bounded with high probability.
Lemma 15 ((Oko et al., 2024b), Corollary 17). If ∥β∥ = 1 and x ∼ N (0, Id ), then |σ∗ (⟨β, x⟩)| ≲ (log d)deg(σ∗ )/2 holds
with high probability.

                                                                  14
                                Nonlinear transformers can perform inference-time feature learning
                                                                                (                                             
                                                                                        σ∗ (z)             σ∗ (z)
                                                                                          ρ           if     ρ      ≤ log1 d
This motivates us to introduce a new function σ¯∗ (z) :=                                                                           . Note that σ¯∗ (⟨β, x⟩) =
                                                             0 (otherwise)
σ∗ (⟨β, x⟩)/ρ holds with high probability from Lemma 15 and the condition of ρ.
Here we show the following lemma appeared in Section 5, stating that the nonlinear transformation exp(·) can reduce the
information exponent.
                                                                                          
Lemma 9. For p ≥ 1, if ep (σ∗ ) < ∞, then H(exp(σ¯∗ ), p) = Θ (log d)C1ρ ep (σ∗ ) and H(σ¯∗ exp(σ¯∗ ), p) =
                    
Θ (log d)C1ρ ep (σ∗ ) holds. Here, the hidden constants in Θ notations may depend on σ∗ and p. If ei (σ∗ ) = ∞, then
H(exp(σ¯∗ ), i) can be taken to be of O(d−C ) where C is a sufficiently large constant.
This immediately implies that the information exponent of exp(σ̄∗ ) and σ̄∗ exp(σ̄∗ ) is equal to ge(σ∗ ).

Proof. We consider H(exp(σ¯∗ ), p) for ep (σ∗ ) < ∞. The other cases can be derived similarly. From the Taylor expansion,
we obtain
                                                                      Cρ ep (σ∗ )
                                        1                               X          1                      X           1
                H(exp(σ¯∗ ), p) =             H(σ¯∗ ep (σ∗ ) , p) +                   H(σ¯∗ i , p) +                     H(σ¯∗ i , p) .
                                    ep (σ∗ )!                                      i!                                 i!
                                    |          {z               } i=ep (σ∗ )+1                       i≥Cρ ep (σ∗ )+1
                                                (I)                 |             {z             } |               {z               }
                                                                                           (II)                                    (III)

For (I),

           H(σ¯∗ ep (σ∗ ) , p) = Ez∼N (0,1) [Hep (z)σ¯∗ ep (σ∗ ) (z)]
                                    1                                    1
                               = e (σ ) E[Hep (z)σ∗ ep (σ∗ ) (z)] − e (σ ) E[Hep (z)σ∗ ep (σ∗ ) (z)I(|σ∗ (z)| ≥ ρ(log d)−1 )]
                                 ρ p  ∗                               ρ p  ∗



holds. Here, from Hölder’s inequality, we know

 E[Hep (z)σ∗ ep (σ∗ ) (z)I(|σ∗ (z)| ≥ ρ(log d)−1 )] ≤ E[Hep (z)4 ]1/4 E[σ∗ 4ep (σ∗ ) (z)]1/4 E[I(|σ∗ (z)| ≥ ρ(log d)−1 )]1/2 (B.4)

Moreover, E[I(|σ∗ (z)| ≥ ρ(log d)−1 )] = O(d−1 ) holds due to the high probability property. Consequently, (I) is of
Θ((log d)−Cρ ep (σ∗ ) ).
                                                       1
For (II), note that i!1 H(σ¯∗ i , p) is dominated by i!ρ              i
                                                         i E[Hep (z)σ∗ (z)] from the similar argument as above. Moreover, we can

see from Hölder’s inequality that

                                          1                           1 p
                                            i
                                              E[Hep (z)σ∗ i (z)] ≲        E[σ∗ 2i (z)].
                                        i!ρ                         i!ρi
                                               p
Here, as M (σ∗ ) = maxep (σ∗ )+1≤i≤Cρ ep (σ∗ ) E[σ∗ 2i (z)] is the constant depending only on σ∗ and p, we can state that (II)
is of O((log d)−Cρ (ep (σ∗ )+1) ).
Finally, let us bound (III). From the definition of σ¯∗ , we get

                                              1                 1
                                                                   q             q
                                                 H(σ¯∗ i , p) ≤      E[Hep (z)2 ] E[σ¯∗ 2i (z)]
                                              i!                i!
                                                                1
                                                              ≲ (log d)−i .
                                                                i!
Moreover, from the bound of residual terms of the Taylor expansion,
                                                 X            1
                                                                 (log d)−i ≲ (log d)−Cρ ep (σ∗ )−1
                                                              i!
                                           i≥Cρ ep (σ∗ )+1

is satisfied.                                                                  
                                                                   1
Overall, we conclude that H(exp(σ¯∗ ), p) = Θ              (log d)Cρ ep (σ∗ )
                                                                                    .

                                                                          15
                                           Nonlinear transformers can perform inference-time feature learning

Lemma 9 does not deal with the case where p = 0. Here we treat this case:
Lemma 16. H(σ¯∗ exp σ¯∗ , 0) = ρ12 (1 + od (1)) and H(exp σ¯∗ , 0) = 1 + od (1) holds.

Proof. Note that H(σ∗ /ρ, 0) = 0 and H((σ∗ /ρ)2 , 0) = ρ12 from Assumption 4. For σ∗ exp σ̄∗ =                                                    1 i+1
                                                                                                                                          P
                                                                                                                                              i≥0 i! σ̄∗ and
exp σ̄∗ = i≥0 i!1 σ̄∗i , conducting the same argument as Lemma 9 yields the assertion.
         P


Let us derive bounds for some important quantities.
                                                                                                                                      ⊤       ′
Lemma 17. Suppose x, x′ ∼ N (0, Id ) and β ∼ Supp(β) := {β | β ∈ Sr , ∥β∥ = 1}. Then, xρκGx
                                                                                         √
                                                                                          r
                                                                                            = o(1) and
 ⊤
          √
β Gx = O( log d) holds with high probability.

Proof. First we can confirm that

                                                x⊤ Gx′                 √               √
                                                   √ = x⊤ U ⊤ DU x′ /ρκ r + x⊤ N x′ /ρκ r = o(1)
                                                 ρκ r

holds with high probability: from the rotational invariance, y = U x and y ′ = U x′ are standard Gaussian vectors. Then,
the first term is o(1) with high probability from Lemma 29 and ρκ = Ω(log d). To show that the second term is o(1), we
can again use Lemma 29 for the case r = d and the fact ∥N ∥2 = O(d−1/2 ).
Next we show                                                                                 p
                                                         β ⊤ Gx = β ⊤ U ⊤ DU x + β ⊤ N x = O( log d).
For the first term, note that ∥β ⊤ U ⊤ DU ∥ ≤ 1 holds. Then, (for any fixed  ⊤ ⊤
                                                                      √ β) β U DU x is the Gaussian with variance at
                                                      ⊤ ⊤
most one. Thus, Gaussian tail bound indicates that β U DU x ≲ log d with high probability. The second term can be
also derived using the fact that ∥N x∥ = O(1) holds with high probability from Lemma 28.

Lemma 18. With high probability over the prompt (X, y, x),
                   N
                                                         x⊤
                                                                                                         ⊤    
                   X                  yi                  i Gx                                        ζ1        x1 Gx            1
                                                                                                                                    
         N −1               exp                exp          √          − Ex1 ,ζ1 exp σ¯∗ (⟨β, x1 ⟩) +      exp     √     = Õ N − 2
                      i=1
                                      ρ                  ρκ r                                         ρ         ρκ r

and
                  N 
                                                                  x⊤
                                                                                                                                    ⊤    
             −1
                  X   yi                       yi                  i Gx                                                           ζ1        x1 Gx
         N                         exp                  exp          √        − Ex1 ,ζ1       σ¯∗ (⟨β, x1 ⟩) exp σ¯∗ (⟨β, x1 ⟩) +      exp     √
                  i=1
                            ρ                  ρ                  ρκ r                                                            ρ         ρκ r
             1
                
      =Õ N − 2

holds.

Proof. Let us show the first assertion: the second one is derived in the same manner.
                                     PN                               √                         PN
From       Lemma      17,      N −1 i=1 exp(yi /ρ)exp(x⊤    i Gx/ρκ r)          = ( N −1 i=1 exp(σ¯∗ (⟨β, xi ⟩) +
                            √                                                         x (if |x| ≤ c)
ζi /ρ)exp(clip(x⊤ i Gx/ρκ r, 1)) with high probability where clip(x, c) =                            . Conditioned on
                                                                                      0 (if |x| > c)
this, with high probability,
                            N
                      −1
                            X                           √                                                    √ 
                                  exp(yi /ρ)exp(x⊤                                                    ⊤
                                                                     
                  N                              i Gx/ρκ r) − Ex1 ,ζ1 exp(σ¯∗ (⟨β, x1 ⟩) + ζ1 /ρ)exp(x1 Gx/ρκ r)
                            i=1
                            N                                        √              h                                   √     i
                            X                                 ⊤                                                  ⊤
             = N −1               eσ¯∗ (⟨β,xi ⟩)+ζi /ρ eclip(xi Gx/ρκ r,1) − Ex1 ,ζ1 eσ¯∗ (⟨β,x1 ⟩)+ζ1 /ρ eclip(x1 Gx/ρκ r,1)
                            i=1
                  |                                                                  {z                                                   }
                                                                                     (I)


                                                                                      16
                             Nonlinear transformers can perform inference-time feature learning
                        h                           ⊤      √    i         h                       ⊤      √ i
              + Ex1 ,ζ1 eσ¯∗ (⟨β,x1 ⟩)+ζ1 /ρ eclip(x1 Gx/ρκ r,1) − Ex1 ,ζ1 eσ¯∗ (⟨β,x1 ⟩)+ζ1 /ρ ex1 Gx/ρκ r
                |                                             {z                                            }
                                                             (II)

                             1
holds. (I) is of Õ(N − √ ) with high probability from Hoeffding’s inequality, noting that exp(σ¯∗ (⟨β, xi ⟩) +
                          2

ζi /ρ)exp(clip(x⊤
                i Gx/ρκ    r, 1)) is O(1)-bounded. (II) is upper-bounded as, using Hölder’s inequality,
                                                              √                 √
         Ex1 exp(σ¯∗ (⟨β, x1 ⟩) + ζ1 /ρ)(1 − exp(x⊤                   ⊤
                                                                                           
                                                    1 Gx/ρκ r))I((x1 Gx/ρκ r) ≥ 1)
                                         1/4                          √ 4 1/4                    √
       ≤Ex1 exp(σ¯∗ (⟨β, x1 ⟩) + ζ1 /ρ)4      Ex1 (1 − exp(x⊤                     E[I((x⊤                2 1/2
                                                 
                                                              1 Gx/ρκ r))                1 Gx/ρκ r) ≥ 1) ]
                                    √ 4 1/4          ∗
       ≤Ex1 (1 − exp(x⊤                        · O(d−C )
              
                        1 Gx/ρκ r))

where C ∗ is a constant which can be taken to be sufficiently large √
                                                                     from the definition of high probability events. We conclude
                                                          ⊤                4
that (II) is negligible by  showing that Ex   (1 −  exp(x 1 Gx/ρκ      r))    = O(1) with high probability over x. It suffices to
                                    √ l 1                             √ 
show that Ex1 (exp(x⊤                                       ⊤
                                                   
                           1 Gx/ρκ    r))   =  E x1  exp(lx 1 Gx/ρκ      r)   = O(1) with high probability for l ∈ [4]. Here, it
holds that
                                             √ 
                      Ex1 exp(lx⊤
                           
                                   1 Gx/ρκ r)
                                                            √                       √ 
                    =Ex1 ∼N (0,Id ) exp(lx⊤     ⊤                        ⊤
                                   
                                            1 U DU x/ρκ r)exp(lx1 N x/ρκ r)
                                                         √ 1/2                                       √ 1/2
                    ≤Ex1 ∼N (0,Id ) exp(2lx⊤                       Ex1 ∼N (0,Id ) exp(2lx⊤
                                                                                 
                                             1 DU x/ρκ r)                                   1 N x/ρκ r)         .           (B.5)
                     √                        √
Note that ∥2lDU x/ρκ r∥ ≤ 1 and ∥2lN x/ρκ r∥ ≤ 1 holds with high probability over x ∼ N (0, Id ): for the former
one, we can use Lemma 28 as√U x ∼ N (0, Id ). For the latter one, we again apply Lemma 28 (for the case where r = d),
together with ∥N ∥F = O(1/ d). In this case, (B.5) can be upper-bounded by

                                      Ez∼N (0,1) [exp(λ1 z)]1/2 Ez∼N (0,1) [exp(λ2 z)]1/2

where λ1 , λ2 ≤ 1, which is known to be O(1). This completes the proof.

Proof of Proposition 11. Now we prove Proposition 11. We first naively evaluate the denominator and numerator of (B.1)
separately, and deal with their correlation afterwards.

Proof. Plugging the parameter values into (B.1) yields
                                                    PN                                      √
                                             N −1                             ⊤
                                                   i=1 (yi /ρ)exp(yi /ρ)exp(xi Gx/ρκ r)
                                 (B.1) = ρ            N                           √     .
                                               N −1 i=1 exp(yi /ρ)exp(x⊤
                                                    P
                                                                           i Gx/ρκ r)

                                                   PN                            √
First, let us evaluate the denominator N −1 i=1 exp(yi /ρ)exp(x⊤          i Gx/ρκ r). Note that, with high probability over the
                                                                             PN                                           √
distribution of (x1 , . . . , xN ), this is equal to the clipped version N −1 i=1 exp(σ¯∗ (⟨β, xi ⟩) + ζi /ρ)exp(x⊤
                                                                                                                  i Gx/ρκ r).
                                                                                P     exp(λ2 /2) i
Its expectation (assume x is fixed now) is calculated as, using exp(λz) = i≥0              i!   λ Hei (z),
                                                                      √ 
               Ex1 ,ζ1 exp(ζ1 /ρ)exp(σ¯∗ (⟨β, x1 ⟩))exp(x⊤
                      
                                                           1 Gx/ρκ r)
                                                                                                        
                                                                                                  ⊤
                                                                                                      
               1                                   X1                                       ∥Gx∥ x  Gx
              = (exp(τ /ρ) + exp(−τ /ρ)) Ex1             H(exp σ¯∗ , i)Hei (⟨β, x1 ⟩)exp     √ · 1      
               2                                       i!                                   ρκ r ∥Gx∥
                                                   i≥0
                                            |                                 {z                         }
                                                                               (∗)


and
                                                                                                
             X1                               X 1  ∥Gx∥ j     
                                                                  ∥Gx∥   2
                                                                           
   (∗) =Ex1     H(exp σ¯∗ , i)Hei (⟨β, x1 ⟩)         √     exp              Hej (⟨x1 , Gx/∥Gx∥⟩)
              i!                                j! ρκ r           2ρ2 κ2 r
                i≥0                                 j≥0


                                                               17
                                   Nonlinear transformers can perform inference-time feature learning
                                        i
                                                 ∥Gx∥2
                                                        
             X1                  ∥Gx∥
         =           H(exp σ¯∗ , i) √      exp              (⟨β, Gx/∥Gx∥⟩)i (Lemma 34)
              i!                 ρκ r            2ρ2 κ2 r
          i≥0
                                                                          ge(σ∗ )
                              ∥Gx∥2                                                       ∥Gx∥2
                                                                                               
                                            H(exp σ¯∗ , ge(σ∗ )) ∥Gx∥
         =H(exp σ¯∗ , 0)exp              +                            √            exp               (⟨β, Gx/∥Gx∥⟩)ge(σ∗ )
                              2ρ2 κ2 r           ge(σ∗ )!          ρκ r                   2ρ2 κ2 r
                                               i
                                                          ∥Gx∥2
                                                                 
                 X       H(exp σ¯∗ , i) ∥Gx∥
          +                                 √     exp                (⟨β, Gx/∥Gx∥⟩)i .                                  (B.6)
                              i!         ρκ r             2ρ2 κ2 r
            i≥ge(σ∗ )+1
            |                                    {z                                     }
                                                           =:Ξ


We can upper bound the final term Ξ: indeed, as ∥Gx∥
                                                  √ ≤ 1 with high probability,
                                                ρκ r

                                                                               i
                                                                                              ∥Gx∥2
                                                                                                       
                                          X        H(exp σ¯∗ , i)       ∥Gx∥
                          |Ξ| =                                           √         exp                      (⟨β, Gx/∥Gx∥⟩)i
                                                       i!               ρκ r                  2ρ2 κ2 r
                                   i≥ge(σ∗ )+1
                                      X            H(exp σ¯∗ , i)           √
                              ≲                                   ( β, Gx/ρκ r )i
                                                       i!
                                  i≥ge(σ∗ )+1

holds. Moreover, from Lemma 33, we know that
                                      2 X                  2
                        H(exp σ¯∗ , i)      (H(exp σ¯∗ , i))
                                         ≤                     = Ez∼N (0,1) [(exp σ¯∗ (z))2 ] ≤ e2 .
                            i!                   i!
                                                        i≥0

Then, we get
                   X         H(exp σ¯∗ , i)           √                        X                     √               √ ge(σ∗ )+1
    |Ξ| ≲                                   ( β, Gx/ρκ r )i ≲                              | β, Gx/ρκ r |i ≲ β, Gx/ρκ r
                                 i!
               i≥ge(σ∗ )+1                                                i≥ge(σ∗ )+1

with high probability.
Overall, letting kρ := 12 (exp(τ /ρ) + exp(−τ /ρ)) = Θd (1) (recall that we assumed τ = O(1)), with high probability we
obtain from Lemma 18 that
           N
           X                             √
    N −1           exp(yi /ρ)exp(x⊤
                                  i Gx/ρκ r)
             i=1
                                 ∥Gx∥2                                                  ∥Gx∥2                    √
                                                                                                
                                                     H(exp σ¯∗ , ge(σ∗ ))
  =kρ H(exp σ¯∗ , 0)exp                         + kρ                      exp                          ( β, Gx/ρκ r )ge(σ∗ ) + Ξ + Õ(N −1/2 ).
                                 2ρ2 κ2 r                ge(σ∗ )!                       2ρ2 κ2 r
                                                           PN                                   √
Next we turn to the numerator: the expectation of N −1 i=1 (yi /ρ)exp(yi /ρ)exp(x⊤      i Gx/ρκ r) is
                                                                                                 √ 
                      Ex1 ,ζ1 (σ¯∗ (⟨β, x1 ⟩) + ζ1 /ρ)exp(ζ1 /ρ)exp(σ¯∗ (⟨β, x1 ⟩))exp(x⊤
                             
                                                                                          1 Gx/ρκ r)
                                                                                             
                                                                                     ⊤
                                                                                           
                               X1                                            ∥Gx∥   x1  Gx
                    =kρ Ex1           H(σ¯∗ exp σ¯∗ , i)Hei (⟨β, x1 ⟩)exp     √ ·            
                                    i!                                       ρκ r ∥Gx∥
                               i≥0
                                                                                             
                                                                                      ⊤
                                                                                           
                           ′
                                   X1                                        ∥Gx∥   x 1 Gx
                      + kρ Ex1            H(exp σ¯∗ , i)Hei (⟨β, x1 ⟩)exp     √ ·            
                                        i!                                   ρκ r ∥Gx∥
                                            i≥0


where kρ′ := 12 τρ (exp(τ /ρ) − exp(−τ /ρ)) = Θd (τ 2 /ρ2 ). Hence, by the same procedure as the analysis of the denominator,
we obtain
         N
         X                                  √
  N −1         (yi /ρ)exp(yi /ρ)exp(x⊤
                                     i Gx/ρκ r)
         i=1

                                                                          18
                                   Nonlinear transformers can perform inference-time feature learning

                            ∥Gx∥2                                           ∥Gx∥2                √
                                                                                  
                                            H(σ¯∗ exp σ¯∗ , ge(σ∗ ))
=kρ H(σ¯∗ exp σ¯∗ , 0)exp     2 2
                                      + kρ                           exp      2   2
                                                                                       ( β, Gx/ρκ r )ge(σ∗ )
                            2ρ κ r                 ge(σ∗ )!                 2ρ κ r
                                  2                                             2              √
                                                                               
                            ∥Gx∥            H(exp  σ¯∗ , ge(σ ∗ ))       ∥Gx∥
 + kρ′ H(exp σ¯∗ , 0)exp      2 2
                                      + k ′
                                          ρ                        exp     2  2
                                                                                    ( β, Gx/ρκ r )ge(σ∗ ) + Ξ′ + Õ(N −1/2 ),
                            2ρ κ r                ge(σ∗ )!               2ρ κ r
                              √ ge(σ∗ )+1
where |Ξ′ | ≲ ⟨β, Gx/ρκ r⟩                  with high probability. Let us derive the claim of the proposition by an-
alyzing the correlation between the numerator and the denominator. Let A0 = H(σ¯∗ exp σ¯∗ , 0), Age(σ∗ ) =
                   ∗ ))/(ge(σ∗ )!), B0 = H(exp σ¯∗ , 0), Bge(σ∗ ) = H(exp σ¯∗ , ge(σ∗ ))/(ge(σ∗ )!). Note that Age(σ∗ ) and
H(σ¯∗ exp σ¯∗ , ge(σ
                                   1
Bge(σ∗ ) are of Θ           Cρ ege(σ ) (σ∗ )   and then
                     (log d)        ∗



                                         √ ge(σ∗ )+1
                    |Ξ|, |Ξ′ | ≲ β, Gx/ρκ r
                               ∈ O(logge(σ∗ )/2+1/2 d · (ρκ)−ge(σ∗ ) · (ρκ)−1 r−ge(σ∗ )/2−1/2 ) (∵ Lemma 17)
                               ∈ O(ρ−1 logge(σ∗ )/2+1/2 d · (ρκ)−ge(σ∗ ) · κ−1 r−3ge(σ∗ )/4 ) (∵ ge(σ∗ ) ≤ 2)
                               ∈ o((ρκ)−ge(σ∗ ) · κ−1 r−3ge(σ∗ )/4 ) (∵ ρ = ω(logge(σ∗ )/2+1/2 d))

holds from Lemma 17. Moreover, set N = Ω̃(r3ge(σ∗ )/2 ) to ensure that N −1/2 term is also of o((ρκ)−ge(σ∗ ) ·
κ−1 r−3ge(σ∗ )/4 ). In this case, Ξ, Ξ′ , N −1/2 are all of o((ρκ)−ge(σ∗ ) Age(σ∗ ) r−3ge(σ∗ )/4 κ−1/2 ) from the condition
                                                            √
κ1/2 = ω(A−1ge(σ∗ ) ). Then we get, letting z = ⟨β, Gx⟩ /(ρκ r),


          g(X, y, x; Γ)
             kρ′ B0 + kρ A0 + kρ′ Bge(σ∗ ) z ge(σ∗ ) + kρ Age(σ∗ ) z ge(σ∗ ) + (h.o.t.)
        =ρ
                            kρ B0 + kρ Bge(σ∗ ) z ge(σ∗ ) + (h.o.t.)
             kρ′ B0 + kρ A0 + kρ′ Bge(σ∗ ) z ge(σ∗ ) + kρ Age(σ∗ ) z ge(σ∗ ) + (h.o.t.)
        =ρ                             Bge(σ∗ ) ge(σ )
                               kρ B0 (1 +  B0 z
                                                       ∗ + (h.o.t.))


             kρ′ B0 + kρ A0 + kρ′ Bge(σ∗ ) z ge(σ∗ ) + kρ Age(σ∗ ) z ge(σ∗ ) + (h.o.t.)
                                                                                                              
                                                                                    Bge(σ∗ ) ge(σ∗ )
        =ρ                                                                                  1−
                                                                                            z        + (h.o.t.)
                                     kρ B0                                            B0
            ′
            kρ B0 + kρ A0   kρ B0 Age(σ∗ ) + kρ′ B0 Bge(σ∗ ) − (kρ′ B0 Bge(σ∗ ) + kρ A0 Bge(σ∗ ) ) ge(σ∗ )
                                                                                                                      
        =ρ                +                                                                       z        + (h.o.t.)
                kρ B0                                       kρ B02
            ′
            kρ B0 + kρ A0   kρ B0 Age(σ∗ ) − kρ A0 Bge(σ∗ ) ge(σ∗ )
                                                                               
        =ρ                +                                  z       + (h.o.t.)
                kρ B0                   kρ B02

Where (h.o.t.) means the terms of o((ρκ)−ge(σ∗ ) Age(σ∗ ) r−3ge(σ∗ )/4 κ−1/2 ). Finally, let us care about the correlation
between the numerator and the denominator, that is, verify that kρ B0 Age(σ∗ ) − kρ A0 Bge(σ∗ ) does not vanish. Here
recall that A0 = ρ12 (1 + od (1)) and B0 = 1 + od (1) from Lemma 16, and that Age(σ∗ ) and Bge(σ∗ ) are of the same
order. Hence, kρ B0 Age(σ∗ ) = Θ(Age(σ∗ ) ) and kρ A0 Bge(σ∗ ) = Θ((1/ρ2 )Age(σ∗ ) ) holds. Then we can conclude that
kρ B0 Age(σ∗ ) = Θ(Age(σ∗ ) ) dominates these terms. Then, taking

                                                                   kρ′ B0 + kρ A0
                                                          P1 = ρ
                                                                        kρ B0

and
                                                kρ B0 Age(σ∗ ) − kρ A0 Bge(σ∗ )
                        P2 = ρ(ρκ)−ge(σ∗ )                                      (= Θ(ρ(ρκ)−ge(σ∗ ) Age(σ∗ ) ))
                                                            kρ B02

yields the assertion. Finally, the order of ρ·(h.o.t) is o(P2 r−3ge(σ∗ )/4 κ−1/2 ). Using κ1/2 = Ω(log2 deg(σ∗ )−2 d) completes
the proof.

We are ready to show the following Proposition 8 outlined in Section 5.

                                                                    19
                                Nonlinear transformers can perform inference-time feature learning

Proposition 8 (Formal). Suppose N, ρ and κ are satisfying the condition in Proposition 11. Let

                                                                  rEβ [ββ ⊤ ] + N
                                                          Γ=             √
                                                                        κ r
                                         √
for some matrix N satisfying ∥N ∥F = O(1/ d). Then,
                                                                 ge(σ∗ )
                                                         ⟨x, β⟩
                      g(X, y, x; Γ) = P1 + P2             √                  + od (P2 r−3ge(σ∗ )/4 log−2 deg(σ∗ )+2 d)
                                                             r

holds with high probability over the distribution of the prompt (X, y, x), where P1 = od (1) and P2 = Θd (log d)−CP2 .
                                                                                                                    


Proof. From the assumption on the support of β (Assumption 4), there exists a d × d orthogonal matrix U such that
U β ∼ Unif{(α1 , α2 , . . . , αr , 0, . . . , 0)|α12 + · · · + αr2 = 1}. Here note that E[U ββ ⊤ U ⊤ ] = r−1 diag(1, . . . , 1, 0, . . . , 0)
                                                                                                                  | {z } | {z }
                                                                                                                            r        d−r
holds: then, Γ satisfies the decomposition (B.2) with G = rEβ [ββ ⊤ ] + N .
                            ge(σ∗ )
Let us simplify ⟨Gx,β⟩ √
                         r
                                      in (B.3). Note that rEβ [ββ ⊤ ]x, β                    = β ⊤ U ⊤ diag(1, . . . , 1, 0, . . . , 0)U x =
                                                                                                            | {z } | {z }
                                                                                                                   r       d−r
β ⊤ U ⊤ U x = ⟨x, β⟩. Moreover, ⟨N√x,β⟩
                                    r
                                        = o(r−1/2 log−2 deg(σ∗ )+1 d) holds with high probability from Lemma 30.
Overall,
                                                                        ge(σ∗ )
                                         ⟨x, β⟩
      g(X, y, x; Γ) = P1 + P2             √ + o(r−1/2 log−2 deg(σ∗ )+1 d)         + od (P2 r−ge(σ∗ )/2 log−2 deg(σ∗ )+2 d)
                                             r

is satisfied. Then, the case where ge(σ∗ ) = 1 is derived immediately. For the case where ge(σ∗ ) = 2, noting that
⟨x,β⟩
  √
    r
       = o(r−1/2 log d) with high probability, we can use (p + q)2 − p2 = q(2p + q) for the second term.

C    Optimizing the Attention Matrix
In this section we develop the optimization guarantee for the attention matrix Γ: see Section 5 for the proof sketch. We
show that one gradient descent step contains information about E[ββ ⊤ ], to satisfy the conditions in Proposition 8.
If fTF is sufficiently small at the initialization, we can approximate the full gradient using the correlational
            PT1 t
gradient T11 t=1  y ∇Γ fTF (X t , y t , xt ; Γ, v(0), b(0), a(0)) . Hence, we first analyze the model gradient
                                                                             Γ=Γ(0)
∇Γ fTF (X t , y t , xt ; Γ, v(0), b(0), a(0)), utilizing the technique developed in Appendix B.
Lemma 19. Let
                                       N                      √                 N               √
                                    1 X                  ⊤                   1 X yi /ρ x⊤
                             ξ1 :=       (yi /ρ)eyi /ρ exi x/ρ d xi , ξ2 :=        e     e i x/ρ d xi .
                                   N i=1                                    N i=1
                                                                                  (                            
                                                                                    σ∗ (z)      σ∗ (z)      1
                                                                                      ρ      if   ρ     ≤ log d
Also, let Ai = H(σ¯∗ exp σ¯∗ , i), Bi = H(exp σ¯∗ , i) for i ≥ 0 where σ¯∗ (z) :=                                               .
                                                                                    0 (otherwise)
Then, using kρ := 12 (exp(τ /ρ) + exp(−τ /ρ)) = Θd (1), kρ′ := 12 τρ (exp(τ /ρ) − exp(−τ /ρ)) = Θd (τ 2 /ρ2 ) and z :=
⟨β,x⟩
  √ , it holds that
 ρ d


                                                                                              
                                         ∥x∥2                                   2
                                                                                X
                                             X Ai+1               k ρ       ∥x∥           A i
                      ξ1 =kρ exp                    z i  β + √ exp                         zi x
                                         2ρ2 d   i!              ρ   d      2ρ2 d         i!
                                             i≥0                                      i≥0
                                                                                                 
                                          2                             ′          2
                                                                      k
                                                                                  
                                      ∥x∥       X Bi+1                  ρ      ∥x∥       X Bi
                          + kρ′ exp                     z i  β + √ exp                         zi x
                                      2ρ2 d         i!               ρ d       2ρ2 d           i!
                                                      i≥0                                              i≥0


                                                                      20
                                   Nonlinear transformers can perform inference-time feature learning
                                                
                                 + Õ d1/2 N −1/2 ,

and
                                                                    
                                                          2
                                                             
                                               ∥x∥      X   Bi+1 i 
                                    ξ2 =kρ exp                    z β
                                               2ρ2 d           i!
                                                         i≥0
                                                                       
                                                         2
                                                           X
                                            kρ       ∥x∥         Bi i          
                                                                                    1/2 −1/2
                                                                                             
                                        + √ exp                       z   x + Õ   d   N
                                           ρ d       2ρ2 d         i!
                                                                  i≥0


with high probability over the data distribution 1 .
                                                           PN                     ⊤
                                                                                        √
Proof. Let us analyze ξ2 first. Note that ξ2 = N1 i=1 eσ¯∗ (⟨β,xi ⟩)+ζi /ρ exi x/ρ d xi holds with high probability. The
expectation of this quantity is calculated as
                    h                       ⊤
                                                 √     i
                 Ex1 eσ¯∗ (⟨β,x1 ⟩)+ζi /ρ ex1 x/ρ d x1
                      h                  ⊤
                                               √    i
             =kρ Ex1 eσ¯∗ (⟨β,x1 ⟩) ex1 x/ρ d x1
                                                              
                         X Bi                       ⊤
                                                         √
             =kρ Ex1             Hei (⟨β, x1 ⟩)ex1 x/ρ d x1 
                               i!
                         i≥0
                                                                                                                
                            X Bi+1                       ⊤
                                                              √          x        X Bi                     ⊤
                                                                                                                 √
             (a)
             =kρ βEx1                  Hei (⟨β, x1 ⟩)ex1 x/ρ d  + kρ √ Ex1              Hei (⟨β, x1 ⟩)ex1 x/ρ d 
                                   i!                                  ρ   d            i!
                            i≥0                                                   i≥0
                                                                                        
                          ∥x∥2 X Bi+1 i                              ∥x∥2 X Bi i 
                                                                          
            (b)                                              kρ                                       p      
            =kρ exp                              z    β  +   √   exp                     z   x   + Õ     d/N   .
                           2ρ2 d              i!            ρ d        2ρ2 d          i!
                                      i≥0                                        i≥0


Here we used Stein’s lemma to derive (a), and the argument to derive (B.6) for (b). Finally, the deviation from the expectation
is upper-bounded using the exactly same technique as the proof of Lemma 18: the only difference p        is that we now treat
d-dimensional vectors, meaning that the bound coming from Hoeffding’s inequality is of Õ           d/N (Lemma 31).
Similarly, we can analyze ξ1 as
                    h                                              ⊤
                                                                        √     i
               Ex1 (σ¯∗ (⟨β, x1 ⟩) + ζi /ρ)eσ¯∗ (⟨β,x1 ⟩)+ζi /ρ ex1 x/ρ d x1
                       h                             ⊤
                                                         √      i           h                ⊤
                                                                                                   √    i
             =kρ Ex1 σ¯∗ (⟨β, x1 ⟩)eσ¯∗ (⟨β,x1 ⟩) ex1 x/ρ d x1 + kρ′ Ex1 eσ¯∗ (⟨β,x1 ⟩) ex1 x/ρ d x1
                                                                                           
                         ∥x∥2 X Ai+1 i                                ∥x∥2 X Ai i 
                                                                           
                                                           kρ
             =kρ exp                          z β + √ exp                                  z x
                         2ρ2 d            i!              ρ d           2ρ2 d           i!
                                   i≥0                                             i≥0
                                                                                                
                                2                                ′              2
                                                               k
                                  X                                             X
                            ∥x∥             Bi+1                 ρ         ∥x∥             B  i
                                                                                                            p     
                + kρ′ exp                         z i
                                                        β +     √    exp                       z i
                                                                                                     x + Õ    d/N   .
                            2ρ2 d            i!               ρ d          2ρ2 d            i!
                                      i≥0                                             i≥0




                                  √
Lemma 20. Let Γ(0) = Id / d and v(0), b(0) and a(0) are determined in Algorithm 1. Then, assuming Npt =
Ω̃(r2 die(σ∗ )+2 ), with high probability over the data (X1:Npt , y1:Npt , x) (simply written as (X, y, x)), it holds that

                                   ∇Γ fTF (X, y, x; Γ, v(0), b(0), a(0))|Γ=Γ(0)=Id /√d
   1
       For a vector v, v = Õ(· · · ) means ∥v∥ = Õ(· · · ).

                                                                  21
                                        Nonlinear transformers can perform inference-time feature learning

                                =αLm (P0 + P1 z + · · · + Pie(σ∗ )−1 z ie(σ∗ )−1 + · · · )βx⊤ + αLm nx⊤

where Lm := |{j ∈ [m] | vj (0) = 1}|, P0 , . . . , Pie(σ∗ )−2 = O(1), Pie(σ∗ )−1 = Θ(ρ−1 ) and ∥n∥ ≤
O(r−1 d−(ie(σ∗ )+1)/2 log−Cn d) (where Cn can be taken to be sufficiently large).

Proof. For simplicity we define N := Npt . We can calculate the model gradient as

                                          ∇Γ fTF (X, y, x; Γ, v(0), b(0), a(0))|Γ=Id /√d
                                                                              √ !
                                             m        PN         yi /ρ x⊤
                                                            y  e      e  i x/ρ d
                                                             i
                                            X
                                         =α     σ ′ vj Pi=1
                                                         N
                                                                             √    · vj s(X, y, x, y)x⊤ ,
                                                             e yi /ρ ex⊤i x/ρ d
                                            j=1          i=1

where

    s(X, y, x, y)
     PN                   ⊤
                               √       PN            ⊤
                                                          √       PN                   ⊤
                                                                                            √    PN            ⊤
                                                                                                                    √
    ( i=1 (yi /ρ)eyi /ρ exi x/ρ d xi )( i=1 eyi /ρ exi x/ρ d ) − ( i=1 (yi /ρ)eyi /ρ exi x/ρ d )( i=1 eyi /ρ exi x/ρ d xi )
  =                                                 PN            ⊤
                                                                       √                                                    .
                                                   ( i=1 eyi /ρ exi x/ρ d )2

First, we can see from the same procedure as the Proposition 11 (with r = d) that the content of σ ′ (·) above
   dominated by P1 (1 + od (1)) with high probability, where P1 in Proposition 11 is positive, which means that
is 
                            ⊤   √
             y eyi /ρ exi x/ρ       d
        PN
σ ′ vj Pi=1
         N
            i
                    ⊤
                        √
              y /ρ x x/ρ d
                                          = 1 if and only if vj = 1. Then,
          i=1 e       e i
                  i



                                ∇Γ fTF (X, y, x; Γ, v(0), b(0), a(0))|Γ=Id /√d = αLm s(X, y, x, y)x⊤

holds with high probability. We proceed to calculate s(X, y, x, y) above. From the proof of Proposition 11 and Lemma 19,
we have


          s(X, y, x, y) = (π1 (X, y, x, y)ξ2 (X, y, x, y) − π2 (X, y, x, y)ξ1 (X, y, x, y))(π2 (X, y, x, y))−2 ,          (C.1)

where
                                                                                             
                                                       ∥x∥2                    2
                                                                               X
                                                 X Ai                      ∥x∥          B i
             π1 (X, y, x, y) = kρ exp                   z i  + kρ′ exp                   z i  + Õ(N −1/2 ),
                                                       2ρ2 d
                                                      i!                   2ρ2 d        i!
                                                  i≥0                               i≥0
                                                            
                                        ∥x∥2 X Bi i 
                                             
             π2 (X, y, x, y) = kρ exp                    z + Õ(N −1/2 ),
                                        2ρ2 d         i!
                                                                       i≥0


                                                                                                  
                                               ∥x∥2                                 2
                                                                                    X
                                               X Ai+1               k ρ         ∥x∥           A  i i
                        ξ1 =kρ exp                       z i  β + √ exp                        z x
                                               2ρ2 d i!            ρ   d        2ρ2 d          i!
                                               i≥0                                        i≥0
                                                                                                     
                                            2                             ′            2
                                                                        k
                                              X                                        X
                                        ∥x∥            B i+1 i           ρ        ∥x∥            B  i i
                            + kρ′ exp                        z β + √ exp                            z x
                                        2ρ2 d           i!             ρ    d      2ρ2 d           i!
                                                  i≥0                                        i≥0
                                              
                             + Õ d1/2 N −1/2 ,

and
                                                                                    
                                                               ∥x∥2
                                                                          X Bi+1
                                         ξ2 =kρ exp                               zi β
                                                               2ρ2 d           i!
                                                                             i≥0


                                                                                   22
                              Nonlinear transformers can perform inference-time feature learning
                                                                             
                                                            2
                                                               
                                       kρ               ∥x∥          X Bi                         
                                     + √ exp                             z i  x + Õ d1/2 N −1/2
                                      ρ d               2ρ2 d          i!
                                                                        i≥0


(recall z := ⟨β,x⟩
               √ ).
              ρ d


  Before proceeding to the further analysis, we note the intuition for the goal of this calculation. We can see that terms
  proportional   to x will be canceled out in (C.1). Therefore, we canP      expect that (C.1) can be expanded using z as
             k                                                                          k     ⊤
  P
         c
     k≥0 k z   · β. Thus, ∇   f
                             Γ TF (X,  y, x; Γ,  v(0), b(0), a(0)) ≃  αL  m     k≥0 ck z · βx holds. Then, to√calculate the
                                                                                   ⊤
                         gradient E[y∇Γ fTF ], it suffices to calculate
  expected correlational √                                        √ k−1 E[y·z k βx√  ] = E[σ∗ (⟨β, x⟩)(β ⊤ x/ρ d)k βx⊤ ] =
      ′             ⊤         k    ⊤                       ⊤                  ⊤
  E[σ∗ (⟨β, x⟩)(β x/ρ d) ββ ] + E[σ∗ (⟨β, x⟩)k(β x/ρ d)                   ββ /ρ d].
                                               ′             ⊤
                                                                   √ k ⊤
  Now, if k < ie(σ∗ ) − 1, the first term E[σ∗ (⟨β, x⟩)(β x/ρ d) ββ ] is zero because a degree-k polynomial does
  not have Hermite component of degree ≥ ie(σ∗′ ) = ie(σ∗ ) − 1. If k = ie(σ∗ ) − 1, then the expectation is nonzero and
  proportional to E[ββ ⊤ ], as desired. We can also show that this is the leading term in the entire gradient. Therefore, we
  focus on checking z ie(σ∗ )−1 term in (C.1).


Let us proceed with the strategy above. Set N = Ω̃(r2 die(σ∗ )+2 ) to ensure that all the noise terms in π1 , π2 , ξ1 , ξ2
are of O(r−1 d−(ie(σ∗ )+1)/2 log−C d) for sufficiently large C. Then, we can simplify s(X, y, x, y) as s(X, y, x, y) =
r(X, y, x, y)β + O(r−1 d−(ie(σ∗ )+1)/2 log−C d), where

                       r(X, y, x, y)
                       "  ie(σ∗ )−1               
                                                      ie(σ∗ )−1
                                                                              
                                                                                 ie(σ∗ )−1
                                                                                                
                                 X Ai                    X Bi                       X Bi+1
                      = kρ             z i  + kρ′              z i   · kρ              zi
                                 i=0
                                      i!                 i=0
                                                                i!                  i=0
                                                                                           i!
                         |                     {z                        } |            {z      }
                                                 (a1 )                                      (a2 )
                                                                                     #
                                ie(σ∗ )−1      ie(σ∗ )−1                ie(σ∗ )−1
                                  X B i i  
                                                  X      A i+1 i 
                                                                           X      B i+1 i 
                        − kρ          z    kρ                z + kρ′                 z
                               i=0
                                    i!            i=0
                                                          i!               i=0
                                                                                   i!
                          |      {z      }|                        {z                      }
                                    (b1 )                                       (b2 )
                                                                                            

                         · (kρ B0 )−2 (1 − 2w + 3w2 + · · · + (−1)ie(σ∗ )−1 wie(σ∗ )−1 ) + O(z ie(σ∗ ) )
                                                                                        
                            |                         {z                               }
                                                            (c)
                                                                                                                                
                                                B                                                                        ∥x∥2
where w := B           B2 2                    ie(σ∗ )−1
               B0 z + 2B0 z + · · · + (ie(σ∗ )−1)!B0 z
                1                                           ie(σ∗ )−1
                                                                      . Here we used the fact that π2 / exp              2ρ2 d       =
                                                           
          B1      B2 2              Bie(σ∗ )−1    ie(σ∗ )−1
kρ B0 1 + B0 z + 2B0 z + · · · + (ie(σ∗ )−1)!B0 z             + O(z ie(σ∗ ) ).

There are a lot of terms of degree z ie(σ∗ )−1 above, but we can show that the terms
                                                                                                      
          ′            Bie(σ∗ )                        −2              Aie(σ∗ )       ′    Bie(σ∗ )
(kρ A0 +kρ B0 )·kρ                 z ie(σ∗ )−1    ρ
                                               ·(k B0 ) −kρ B0 kρ                  + kρ                  z ie(σ∗ )−1 ·(kρ B0 )−2 ,
                    (ie(σ∗ ) − 1)!                                  (ie(σ∗ ) − 1)!      (ie(σ∗ ) − 1)!
                                                                                                                           (C.2)
made from the first term of (a1 ) (and (b1 )), the last term of (a2 ) (and (b2 )), and the first term of (c), dominates over other
terms, i.e., other terms having degree z ie(σ∗ )−1 are of od ((C.2)) considering the coefficients.
                                                                                      
First we calculate the order of (C.2). From Lemma 9, Ai , Bi = Θ ρei1(σ∗ ) (i ≥ 1) holds where ei is defined in
Definition 14. Moreover, from Lemma 16 it holds that A0 = Θ(ρ−2 ) and B0 = Θ(1). Note that from the definition of ei
and the information exponent, we can see that eie(σ∗ ) = 1 and then Aie(σ∗ ) , Bie(σ∗ ) = O(ρ−1 ) holds. Thus, noting that
                                                                    A
kρ = Θ(1) and kρ′ = O(ρ−2 ), indeed the term kρ B0 kρ (ie(σie(σ ∗)
                                                            ∗ )−1)!
                                                                    (kρ B0 )−2 = Θ(ρ−1 ) dominates over other terms.
Next we show the superiority of this term over other z ie(σ∗ )−1 terms (in terms of the degree of ρ in coefficients): all the
terms are made by multiplying a term in (a1 ) (or (b1 )), a term in (a2 ) (or (b2 )), and a term in (c). Let us see the ρ factor in

                                                                        23
                               Nonlinear transformers can perform inference-time feature learning

the coefficients: note that again from the definition of the information exponent, ei (σ∗ ) > 1 (and then Ai , Bi = O(ρ−2 )) if
1 ≤ i < ie(σ∗ ). Hence, to be comparable to ρ−1 we should pick out the zeroth-order term from (a1 ) and (b1 ). Here the only
optimal way is to pick out the z ie(σ∗ )−1 term in (a2 ) and (b2 ), which is nothing but (C.2). Otherwise, we should pick out
also the zeroth-order term in (a2 ) and (b2 ). In this case, we should use z ie(σ∗ )−1 term in (c), but this is suboptimal because
Bi /B0 in w is already O(ρ−2 ).
Getting back to (C.1), we now showed that

            s(X, y, x, y) = (P0 + P1 z + · · · + Pie(σ∗ )−1 z ie(σ∗ )−1 + · · · )β + O(r−1 d−(ie(σ∗ )+1)/2 log−Cn d)

where Pie(σ∗ )−1 = Θ(ρ−1 ), which completes the proof.
                                  √
Lemma 21. Let Γ(0) = Id / d and v(0), b(0) and a(0) are determined in Algorithm 1. Then, assuming Npt =
Ω̃(r2 die(σ∗ )+2 ), with high probability over the data (X, y, x), it holds that
                            T1
                        1 X                                                     2
                  ∇Γ           fTF (X t , y t , xt ; Γ, v(0), b(0), a(0)) − y t
                       2T1 t=1
                                                                                     Γ=Γ(0)
                                                                                                                 √
              =Θ(αmd      −(ie(σ∗ )−1)/2 −(ie(σ∗ ))
                                         ρ                  ⊤
                                                      )Eβ [ββ ] + O(αmr    −1 −ie(σ∗ )/2
                                                                                d            log−Cn d) + Õ(α2 m2 d)

with high probability over the pretraining data distribution and random initialization, where Cn is a sufficiently large
constant.

Proof. Now we have
                       T1                                                                        T1              T1
                   1 X                                                     2                1 X             1 X
             ∇Γ           fTF (X t , y t , xt ; Γ, v(0), b(0), a(0)) − y t               =          f t Gt −        y t Gt
                  2T1 t=1                                                                    T1 t=1          T1 t=1
                                                                                Γ=Γ(0)


where f t := fTF (X t , y t , xt ; Γ(0), v(0), b(0), a(0)) and Gt = ∇Γ fTF (X t , y t , xt ; Γ, v(0), b(0), a(0))|Γ=Γ(0) . We first
                                    PT1 t t
upper-bound the first term T11 t=1         f G . From Lemma 15, with high probability yit = Õ(1) holds for all i and t.
Therefore,
                                                                     PNpt                 ⊤
                               t    t   t                                   yi ecyi /ρ exi Γx/ρ
                   |fTF (X , y , x ; Γ, v(0), b(0), a(0))| ≤ αm Pi=1     Npt cy /ρ x⊤ Γx/ρ
                                                                                                   = Õ(αm)
                                                                         i=1 e        e i
                                                                                 i



holds with high probability.
Also, from Lemma 20, we have

                               ∇Γ fTF (X, y, x; Γ, v(0), b(0), a(0))|Γ=Γ(0)=Id /√d
                            =αLm (P0 + P1 z + · · · + Pie(σ∗ )−1 z ie(σ∗ )−1 + · · · )βx⊤ + αLm nx⊤

where P0 , . . . , Pie(σ∗ )−2 = O(1), Pie(σ∗ )−1 = Θ(ρ−1 ) and ∥n∥ ≤ O(r−1 d−(ie(σ∗ )+1)/2 log−Cn d). Moreover, ∥x∥ =
  √                                                                          √
O( d) holds with high probability from Lemma 28, meaning ∥Gt ∥F = O(αm d). Overall,
                                                        T
                                                  1 X  1
                                                                             √
                                                ∥        f t Gt ∥F = Õ(α2 m2 d)                                             (C.3)
                                                  T1 t=1

is ensured with high probability.
Next let us calculate
                                                                                                                    
         T1                    T1
      1  X            αLm     X                                                             
             y t Gt =                                                            + · · · )β t (xt )⊤ + y t nt (xt )⊤  .
                              t            t                         t ie(σ )−1
                              y (P0 + P1 (z ) + · · · + Pie(σ∗ )−1 (z ) ∗
                                                                                                                     
      T1 t=1           T1 t=1 |                            {z                                }
                                                                   =:mt


                                                                  24
                             Nonlinear transformers can perform inference-time feature learning
                                                                                    PT1
Note that the norm of mt is Õ(1) with high probability. Then, αL               T1
                                                                                  m        t   t ⊤             1
                                                                                      t=1 m (x ) − E[αLm m (x ) ]
                                                                                                                  1 ⊤
                                                                                                                       =
         √                                                                                                 t  t ⊤
Õ(αmd/ T1 ) holds with high probability from Corollary 32.                                Moreover, ∥n (x ) ∥F        ≤
    −1 −ie(σ∗ )/2     −Cn       deg(σ∗ )/2                          deg(σ∗ )/2
O(r d             log     d log            d) holds (additional log            d comes from the order of y; see Lemma 15.
Hereafter we absorb this by retaking Cn ). Thus, if T1 = Ω̃(r2 die(σ∗ )+2 ) then
                                 T1
                             1 X
                                    y t Gt = αLm E[mx⊤ ] + O(αmr−1 d−ie(σ∗ )/2 log−Cn d)                               (C.4)
                             T1 t=1
                                                                       √                         k
is satisfied. It remains to calculate the expectation E[yz k βx⊤ ] = (ρ d)−k E[σ∗ (⟨β, x⟩) ⟨β, x⟩ βx⊤ ] to analyze E[mx⊤ ].
From Stein’s lemma, we have
                     √                               k
                   (ρ d)−k Eβ,x [σ∗ (⟨β, x⟩) ⟨β, x⟩ βx⊤ ]
                     √ −k                              k
                                                                    √                              k−1
                 =(ρ d) Eβ [Ex [σ∗′ (⟨β, x⟩) ⟨β, x⟩ ]ββ ⊤ ] + (ρ d)−k kEβ [Ex [σ∗ (⟨β, x⟩) ⟨β, x⟩      ]ββ ⊤ ],
                                                                                                  k
and from Lemma 34 and the definition of the information exponent, Ex [σ∗′√       (⟨β, x⟩) ⟨β, x⟩ ] is zero if k < ie(σ∗′ ) =
                                                                                                                 k
ie(σ    − 1 and nonzero if k = ie(σ∗ ) − 1. If k = ie(σ∗ ) − 1, then (ρ d)−k Eβ [Ex [σ∗′ (⟨β, x⟩) ⟨β, x⟩ ]ββ ⊤ ] ≍
  √ ∗ )−(ie(σ
(ρ d)         ∗ )−1)
                     Eβ [ββ ⊤ ] is satisfied from Lemma 34. We can observe that other terms are also proportional to E[ββ ⊤ ]
but dominated by this term. From Lm ≍ m with high probability and Pie(σ∗ )−1 = Θ(ρ−1 ), we have

                                αLm E[mx⊤ ] = Θ(αmd−(ie(σ∗ )−1)/2 ρ−(ie(σ∗ )) )Eβ [ββ ⊤ ].                             (C.5)

Putting (C.3), (C.4) and (C.5) together completes the proof.

Setting the hyperparameters for Lemma 21 immediately yields the following conclusion of the optimization of Γ:
Proposition 22. By setting the hyperparameters as αm = O(r−1 d−(ie(σ∗ )+1)/2 log−Cα d), Npt , T1 = Ω̃(r2 die(σ∗ )+2 ),
η1 = Θ(α−1 m−1 d(ie(σ∗ )−1)/2 log−Cη1 d)r1/2 and λ1 = η1−1 for constants Cη1 and Cα , after one gredient descent step
(Line 3 in Algorithm 1) it holds that
                                                        1
                                           Γ∗ =                        ⊤
                                                                               
                                                          C
                                                               rEβ [ββ   ] + N
                                                  r1/2 log κ d
                                                                       √
with high probability over the data distribution, where ∥N ∥F = Od (1/ d) holds, where Cκ can be taken to be sufficiently
large.
This proposition can be immediately connected to Proposition 8.

D    Optimizing the MLP Layer
In this section, we give an optimization guarantee for the MLP layer. We begin with constructing the output layer parameter
a ∈ Rm yielding a sufficient approximation guarantee.
Lemma 23 (Construction of Continuous Output Layer). Let l = 1 or 2 and assume ge(σ∗ ) = l. Suppose that there exists
g(x) such that
                                                              (⟨β, x⟩)l
                                           g(x) = P1 + P2               + n(x),
                                                                rl/2
where P1 = od (1), P2 = Θd (log d)−CP2 , and |n(x)| = od (P2 r−3l/4 log−2 deg(σ∗ )+2 d) holds (these conditions are
                                            

indeed identical to the conclusion of Proposition 8). Then, there exists π(v, b) such that

                           Ev∼Unif{±1},b∼[−1,1] [π(v, b)σ(v · g(x) + b)] − σ∗ (⟨β, x⟩) = od (1)

with high probability over x ∼ N (0, Id ). Moreover, supv,b |π(v, b)| = Õ(rl ) holds.

Proof. Note that if l = 2, then σ∗ is even: this means that there exists a polynomial ς∗ such that σ∗ (z) = ς∗ (z l ) for
                             Pdeg(ς )
l = 1, 2. Here let ς∗ (z) = k=0 ∗ sk z k . Now from Lemma 9 in Damian et al. (2022), there exists πk′ (v, b) such that
supv,b |πk′ (v, b)| = O(1) and
                                      Ev∼Unif{±1},b∼[−1,1] [πk′ (v, b)σ(vz + b)] = z k

                                                               25
                                         Nonlinear transformers can perform inference-time feature learning

for any |z| ≤ 1. If we define
                                                                 deg(ς∗ )
                                                                  X              πk′ (v, bα−1 log−2 d)
                                                  π ′ (v, b) =              sk                         log2k d,
                                                                  k=0
                                                                                         α log2 d
                  −l/2
where α = P2 r           , then

                 Ev∼Unif{±1},b∼[−α log2 d,α log2 d] [π ′ (v, b)σ(v(αz) + b)]
                 deg(ς∗ )
                                                                  πk (v, bα−1 log−2 d)
                  X                                              ′                                     
                                                                                          2k
               =          sk Ev∼Unif{±1},b∼[−α log2 d,α log2 d]                        log dσ(v(αz) + b)
                  k=0
                                                                         α log2 d
                    deg(ς∗ )                                                                deg(ς∗ )
                     X                                                                       X
                               sk log2k dEv∼Unif{±1},b∼[−1,1] πk′ (v, b)σ(vz log−2 d + b) =          sk z k = ς∗ (z),
                                                                                        
               =
                     k=0                                                                                          k=0


if |z log−2 d| ≤ 1. Note that supv,b |π ′ (v, b)| = O(α−1 log2 deg(σ∗ )−2 d) holds.
Furthermore, let us define events E− (v, b) and E+ (v, b) as

                                                     E− (v, b) = (v = −1 ∧ b ∈ [P1 ± α log2 d]),
                                                     E+ (v, b) = (v = 1 ∧ b ∈ [−P1 ± α log2 d]),

and then define
                                                 1
                           π(v, b) =                   (I(E− (v, b))π ′ (−1, b − P1 ) + I(E+ (v, b))π ′ (1, b + P1 )).   (D.1)
                                             2α log2 d
Now it holds that

               Ev∼Unif{±1},b∼[−1,1] [π(v, b)σ(v · g(x) + b)]
               1
              = Eb∼[P1 −α log2 d,P1 +α log2 d] π ′ (−1, b − P1 )σ(−P1 − α(⟨β, x⟩)l − n(x) + b)
                                                                                             
               2
                 1
               + Eb∼[−P1 −α log2 d,−P1 +α log2 d] π ′ (1, b + P1 )σ(P1 + α(⟨β, x⟩)l + n(x) + b)
                                                                                               
                 2
              (*)                                                                              l
              =Ev∼Unif{±1},b∼[−α log2 d,α log2 d] [π ′ (v, b)σ(v · α ⟨β, x⟩ + b)] + od (1) = σ∗ (⟨β, x⟩) + od (1)

                               l
holds (note that | ⟨β, x⟩ | ≤ log2 d with high probability from the tail bound for the standard Gaussian).
Here, we used the Lipschitz continuity of the ReLU function and the condition |n(x)| = od (α log−2 deg(σ∗ )+2 d) to derive
(*).

Lemma 24 (Construction of Discrete Output Layer). Under the condition of Lemma 23, there exists a∗ ∈ Rm such that

                                          m
                                          X
                                                a∗j σ(vj · g(x) + bj ) − σ∗ (⟨β, x⟩) = Õ(rl m−1/2 ) + od (1)            (D.2)
                                          j=1


with high probability over x ∼ N (0, Id ). Moreover, ∥a∥2 = Õ(r2l m−3/2 + r3l/2 m−1 ) holds with high probability.

Proof. Let aj = m−1 π(vj , bj ) where π is constructed in Lemma 23. As g(x) = O(1) and supv,b π(v, b) = Õ(rl ), from
Hoeffding’s inequality we have

                                   m
                                   X
                       m−1               π(vj , bj )σ(vj · g(x) + bj ) − Ev,b [π(v, b)σ(v · g(x) + b)] = Õ(rl m−1/2 )
                                   j=1


with high probability and then we obtain (D.2).

                                                                                    26
                                Nonlinear transformers can perform inference-time feature learning
                                              Pm
Let us upper bound ∥a∥2 = m−1 · m−1                                2
                                                    j=1 π(vj , bj ) . Again from Hoeffding’s inequality, we obtain

                                              m
                                              X
                                        m−1         π(vj , bj )2 − Ev,b [π(v, b)2 ] = Õ(r2l m−1/2 )
                                              j=1


and then it ramains to upper-bound Ev,b [π(v, b)2 ]. Naively supv,b π(v, b)2 = Õ(r2l ) holds, but from the definition (D.1),
π(v, b) is nonzero with probability Õ(r−l/2 ), meaning Ev,b [π(v, b)2 ] = Õ(r3l/2 ). Overall, ∥a∥2 = Õ(r2l m−3/2 +
r3l/2 m−1 ) is satisfied with high probability.

Proof of the Optimization Part of Theorem 1. Now we are ready to show the optimization part (part 1) in Theorem 1.

Proof of Part 1, Theorem 1. We note that the condition in Lemma 23 is satisfied from Proposition 8, and the condition in
Proposition 8 is ensured by Proposition 22. Let a′ be the output parameter constructed in Lemma 24: from the equivalence
between ℓ2 -regularized and norm-constrained optimization algorithms, there exists λ2 such that
              TX
                                                                    !2
               1 +T2                                                                1 +T2
                                                                                   TX
         1                                          ∗   ∗   ∗   ∗             1                                                              2
                         t          t    t    t
                        y − fTF (X , y , x , Γ , v , b , a )             ≤                   y t − fTF (X t , y t , xt , Γ∗ , v ∗ , b∗ , a∗ )
         T2                                                                   T2
              t=T1 +1                                                              t=T1 +1
                                                                                    1 +T2
                                                                                   TX
                                                                              1                                                              2
                                                                         ≤                   y t − fTF (X t , y t , xt , Γ∗ , v ∗ , b∗ , a′ )
                                                                              T2
                                                                                   t=T1 +1
                                                                                             2
                                                                         ≤ (τ + od (1)) (∵ Lemma 24, m = Ω̃(r2ge(σ∗ ) ))

and it holds that ∥a∗ ∥ ≤ ∥a′ ∥ = Õ(rge(σ∗ ) m−3/4 + r3ge(σ∗ )/4 m−1/2 ). Note that as we assumed m = Ω̃(r2ge(σ∗ ) ), the
second term r3ge(σ∗ )/4 m−1/2 is dominant.

E     Inference-Time Estimation Error Analysis
We are ready to analyze the ICL loss at the inference time defined by
                            ∗   ∗ ∗     ∗                                                  ∗   ∗ ∗     ∗
                   RICL
                    Ntest (Γ , v , b , a ) = EDx ,Df∗ ,Dζ [|fTF (X1:Ntest , y1:Ntest , x, Γ , v , b , a ) − y|].

In particular, our primary interest is in deriving the inference-time sample complexity, i.e., the number of in-context examples
Ntest in the test prompt needed to ensure that the ICL loss is od (1).

E.1   ICL Error at Ntest = Npt
We first treat the special case where Ntest = Npt holds: in this case, as we have an optimization guarantee at context length
Npt , it is sufficient to bound generalization gap via a standard Ramemacher complexity analysis.
Recall that g is defined as the attention output, i.e.,
                                                                             yi /ρ x⊤
                                                                    PN
                                                                     i=1 yi e     e i Γxi /ρ
                                              g(X, y, x; Γ) =       PN y /ρ x⊤ Γx /ρ .
                                                                      i=1 e      e i i
                                                                             i



In this section, we fix Γ, v and b. We define FA to describe the set of transformers where the norm of the output layer of the
MLP is constrained:                                                                            
                                                 Xm                                            
                            FA = (X, y, x) 7→         aj σ(vj · g(X, y, x; Γ) + bj ) ∥a∥ ≤ A .
                                                                                               
                                                         j=1

Moreover, let                                                             "                            #
                                                                               T
                                                                            1X t
                               RadT (FA ) = E{X t },{yt },{xt },{ϵt } sup         ϵ f (X t , y t , xt )
                                                                      f ∈FA T t=1

be its Rademacher complexity, where ϵt ∼ Unif({±1}). Here, we fix the context length to be N = O(polyd), i.e, suppose
X ∈ Rd×N and y ∈ RN . Then, we obtain the upper bound of RadT (FA ) as follows.

                                                                     27
                                Nonlinear transformers can perform inference-time feature learning

Lemma 25. When ∥b∥ ≤ B and vj = ±1, then it holds that
                                                             √ 
                                                        A(B + m)
                                    RadT (FA ) = Õ        √      .
                                                             T
Proof. From the definition of FA , we have
                                                                                                                 
                                                                 T      m
                                                              1 X      X
                                                                    ϵt     aj σ vj · g(X t , y t , xt ; Γ) + bj 
                                                                                                                
             RadT (FA ) = E{X t },{yt },{xt },{ϵt }  sup
                                                     a:∥a∥≤A T t=1     j=1
                                                                                                                     !
                                                              m             T
                                                             X          1  X
                                                                               ϵt σ vj · g(X t , y t , xt ; Γ) + bj .
                                                                                                                    
                        = E{X t },{yt },{xt },{ϵt }  sup        aj ·
                                                     a:∥a∥≤A j=1        T t=1

From Cauchy–Schwarz inequality and Jensen’s inequality, we have
                                                          v                                                                        
                                                           u
                                                             m                      T
                                                                                                                               !2
                                                                                   1X
                                                           uX
        RadT (FA ) ≤ E{X t },{yt },{xt },{ϵt }  sup ∥a∥ · t                              ϵt σ(vj · g(X t , y t , xt ; Γ) + bj )
                                                          u                                                                        
                                                                                  T t=1
                                                                                                                                    
                                                     a:∥a∥≤A              j=1
                           v
                           u
                                                      m             T
                                                                                                               !2
                                                                1X t
                           u                          X
                        ≤ AtE{X t },{yt },{xt },{ϵt }                 ϵ σ(vj · g(X t , y t , xt ; Γ) + bj )
                           u
                                                                                                                    .
                                                         j=1
                                                                T t=1

                                                                                                     ′
Next, we obtain the upper bound of the component in the square root. Since ϵt and ϵt are independent if t ̸= t′ , we have
                              
                                 m         T
                                                                                     !2 
                               X       1  X
                                              ϵt σ vj · g(X t , y t , xt ; Γ) + bj
                                                                                   
    E{X t },{yt },{xt },{ϵt }                                                           
                                j=1
                                       T  t=1
                                                                                                                                   
                                            m X  T X T
                                        1  X                  ′
                                                                                                            ′     ′    ′
                                                                                                                                  
                                                         ϵt ϵt σ vj · g(X t , y t , xt ; Γ) + bj σ vj · g(X t , y t , xt ; Γ) + bj 
                                                                                                
       = E{X t },{yt },{xt },{ϵt }  2
                                       T j=1 t=1 ′
                                                   t =1
                                                                                    
                                       m X  T
                                   1  X                                            2
                                               σ vj · g(X t , y t , xt ; Γ) + bj .
                                                                                 
       = E{X t },{yt },{xt }  2
                                  T j=1 t=1

Now, σ is a ReLU activation function, which means that σ(z)2 ≤ z 2 for z ∈ R. Therefore, we have
                                                                                                 
                                                  m X T
                                                1 X                                             2
                                                         σ vj · g(X t , y t , xt ; Γ) + bj 
                                                                                              
                         E{X t },{yt },{xt }  2
                                               T j=1 t=1
                                                                                                           
                                                          m X  T
                                   1                     X                                                2
                                                                    vj · g(X t , y t , xt ; Γ) + bj 
                                                                                                        
                               ≤ 2 E{X t },{yt },{xt } 
                                  T                      j=1 t=1
                                                                                                            
                                                          m X  T
                                   2                     X
                                                                    vj2 · g(X t , y t , xt ; Γ)2 + b2j 
                                                                                                          
                               ≤ 2 E{X t },{yt },{xt } 
                                  T                      j=1 t=1
                                                    T
                                                                                                       !
                                   2        2
                                                   X                              t    t    t      2
                                                                                                      
                               ≤ 2 B T +m               E{X t },{yt },{xt } g(X , y , x ; Γ)               .
                                  T                t=1


Finally, we bound the term E[g(X t , y t , xt ; Γ)2 ]. For i = 1, . . . , N , let
                                                                                 ⊤
                                                                        eyi /ρ exi Γx/ρ
                                               pi (X, y, x) = PN                      ⊤          .
                                                                              yi′ /ρ exi′ Γx/ρ
                                                                    i′ =1 e

                                                                    28
                                Nonlinear transformers can perform inference-time feature learning
                                     PN                                  PN
Then, we have g(X, y, x; Γ) =           i=1 pi (X, y, x)yi and                i=1 pi (X, y, x) = 1. Hence, from Jensen’s inequality, we have

                                                                              N
                                                                                                             !2
                                                                              X
                                                  t      t     t     2
                                            g(X , y , x ; Γ) =                                t    t
                                                                                     pi (X , y , x )yitt

                                                                              i=1
                                                                             N
                                                                             X
                                                                         ≤         pi (X t , y t , xt )(yit )2 .
                                                                             i=1

Now, we define random variables Zit , Ẑit (i = 1, . . . N ) as

                   Zit = pi (X t , y t , xt )(yit )2 ,       Ẑit = pi (X t , y t , xt )(yit )2 · I((yit )2 ≤ (log d)deg(σ∗ )+1 ).

Thus, using Hölder’s inequality, we have

           E{X t },{yt },{xt } [Zit − Ẑit ]
                                     h                                                         i
             ≤ E{X t },{yt },{xt } pi (X t , y t , xt )(yit )2 I((yit )2 ≥ (log d)deg(σ∗ )+1 )
                                                         1/4                             1/2 h t 2                      i1/4
             ≤ E{X t },{yt },{xt } pi (X t , y t , xt )4      E{X t },{yt },{xt } (yit )4     P (yi ) ≥ (log d)deg(σ∗ )+1
                                                                                

                                             1/2 h t 2                           i1/4
             ≤ E{X t },{yt },{xt } (yit )4       P (yi ) ≥ (log d)deg(σ∗ )+1
                                     
                                                                                        .

Using Lemma 15 and the definition of high probability events, we can set the quantity above to be O(N −2 ) (note that we
assume N = poly(d)). Consequently, we have
                                                    N
                                   t   t   t    2
                                                   X
                                                      E[Zit ]
                               
            E{X t },{yt },{xt } g(X , y , x ; Γ) ≤
                                                                   i=1
                                                                             N
                                                                             X
                                                             ≤ O(1) +              E[Ẑit ]
                                                                             i=1
                                                                                              n                                          o
                                                             ≤ O(1) + E              max        (yit )2 · I((yit )2 ≤ (log d)deg(σ∗ )+1 )
                                                                                   i=1,...,N
                                                                              deg(σ∗ )+1
                                                             ≤ O((log d)                      ).                                               (E.1)

In conclusion, we obtain
                                                      r                                      √ 
                                                             2  2                     A(B + m)
                             RadT (FA ) ≤ A ·                   B T + mT · Õ(1) = Õ      √     .
                                                             T2                              T



Then, we arrive at the following lemma:
Lemma 26. Suppose running Algorithm 1 under the conditions specified in Theorem 1. Then, with probability at least
                                                                                                ∗   ∗ ∗     ∗
0.995 over the training data and the random initialization of Algorithm 1, it holds that RICL
                                                                                          Npt (Γ , v , b , a ) = od (1).

                                                         PT1 +T2
Proof. Now we know from Part 1 of Theorem 1 that T12 t=T       1 +1
                                                                    |y t − fTF (X t , y t , xt , Γ∗ , v ∗ , b∗ , a∗ )| = od (1) with
                                                                                                               √
high probability. Moreover, we have parameter norm bounds ∥a∗ ∥ = Õ(r3ge(σ∗ )/4 m−1/2 ) and ∥b∥ ≤ m. Plugging these
values into A and B in Lemma 25 yields
                                                               3ge(σ∗ )/4 
                                                               r
                                            RadT2 (FA ) = Õ      √          .
                                                                     T2
                                                                                                                          3ge(σ )/4 
                                                                                                                          r √ ∗
Using standard symmetrization technique (cf: Appendix D.3 in (Oko et al., 2024b)) yields RICLNpt  (θ)   =   o d (1)+  Õ       T               2

with probability at least 0.995. Noting that T2 = Ω̃(r3ge(σ∗ )/2 ), we arrive at the assertion.

                                                                             29
                                   Nonlinear transformers can perform inference-time feature learning

E.2      ICL Error at General Ntest
Finally, we extend the generalization result to any inference-time context length Ntest , which concludes the proof of
Theorem 1.
Lemma 27. For N ≤ polyd,

                                    EX,y,x [fTF (X1:N , y1:N , x; Γ∗ , v ∗ , b∗ , a∗ )2 ] ≤ Õ(r3ge(σ∗ )/2 )

holds.

Proof. Note that
                                                                         m
                                                                         X
                          fTF (X1:N , y1:N , x; Γ∗ , v ∗ , b∗ , a∗ ) =         a∗j σ(vj∗ g(X1:N , y1:N , x; Γ∗ ) + b∗j )
                                                                         j=1


where E[g(X1:N , y1:N , x; Γ∗ )2 ] = Õ(1) from (E.1). Then,

                               E[fTF (X1:N , y1:N , x; Γ∗ , v ∗ , b∗ , a∗ )2 ]
                                                                                    
                                           m
                                           X
                              ≤E ∥a∗ ∥2 ·    σ(vj∗ g(X1:N , y1:N , x; Γ∗ ) + b∗j )2 
                                               j=1
                                                                                             
                                              m
                                              X
                              ≤E ∥a∗ ∥2 ·           (2g(X1:N , y1:N , x; Γ∗ )2 + 2(b∗j )2 ) ≤ Õ(r3ge(σ∗ )/2 )
                                               j=1

holds.

Finally, we prove the Part 2 of Theorem 1.

Proof of Part 2, Theorem 1. Note that
                              ∗   ∗ ∗     ∗             ∗   ∗ ∗     ∗
                      |RICL                     ICL
                        Npt (Γ , v , b , a ) − RNtest (Γ , v , b , a )|

                    ≤E[|fTF (X1:Npt , y1:Npt , x; Γ∗ , v ∗ , b∗ , a∗ ) − fTF (X1:Ntest , y1:Ntest , x; Γ∗ , v ∗ , b∗ , a∗ )|]

holds. From Proposition 11, if Npt , Ntest = Ω̃(r3ge(σ∗ )/2 ), then

                       |g(X1:Ntest , y1:Ntest , x; Γ∗ ) − g(X1:Npt , y1:Npt , x; Γ∗ )| ≤ od (r−3ge(σ∗ )/4 log−C d)

holds with high probability (here, C can be made sufficiently large by taking the constant Cκ to be sufficiently large), where
the upper bound quantity at right hand side does not depend on the data. Note that

                     |fTF (X1:Npt , y1:Npt , x; Γ∗ , v ∗ , b∗ , a∗ ) − fTF (X1:Ntest , y1:Ntest , x; Γ∗ , v ∗ , b∗ , a∗ )|
                      Xm
                   ≤     |a∗j | σ(vj∗ g(X1:Npt , y1:Npt , x; Γ∗ ) + b∗j ) − σ(vj∗ g(X1:Ntest , y1:Ntest , x; Γ∗ ) + b∗j )
                      j=1
                              √
                   ≤∥a∗ ∥ ·       m · od (r−3ge(σ∗ )/4 log−C d) (∵ Cauchy-Schwarz).

Using ∥a∗ ∥ = Õ(r3ge(σ∗ )/4 m−1/2 ) in Part 1 of Theorem 1, now we obtain

                 |fTF (X1:Npt , y1:Npt , x; Γ∗ , v ∗ , b∗ , a∗ ) − fTF (X1:Ntest , y1:Ntest , x; Γ∗ , v ∗ , b∗ , a∗ )| ≤ od (1)

with high probability. It remains to convert this bound into the expectation. Note that the od (1) quantity at right-hand side
does not depend on the data: we write this quantity as qd . We can state that P[|fTF (X1:Npt , y1:Npt , x; Γ∗ , v ∗ , b∗ , a∗ ) −
fTF (X1:Ntest , y1:Ntest , x; Γ∗ , v ∗ , b∗ , a∗ )| ≤ qd ] ≤ 1 − d−4 from the definition of the high probability event. We write this
event as E. Consequently,

         E[|fTF (X1:Npt , y1:Npt , x; Γ∗ , v ∗ , b∗ , a∗ ) − fTF (X1:Ntest , y1:Ntest , x; Γ∗ , v ∗ , b∗ , a∗ )|]

                                                                       30
                                 Nonlinear transformers can perform inference-time feature learning

      ≤qd + E[|fTF (X1:Npt , y1:Npt , x; Γ∗ , v ∗ , b∗ , a∗ ) − fTF (X1:Ntest , y1:Ntest , x; Γ∗ , v ∗ , b∗ , a∗ )|(1 − I(E))]
      ≤qd + E[|fTF (X1:Npt , y1:Npt , x; Γ∗ , v ∗ , b∗ , a∗ ) − fTF (X1:Ntest , y1:Ntest , x; Γ∗ , v ∗ , b∗ , a∗ )|2 ]1/2 · (d−4 )1/2
      ≤qd + E[2fTF (X1:Npt , y1:Npt , x; Γ∗ , v ∗ , b∗ , a∗ )2 + 2fTF (X1:Ntest , y1:Ntest , x; Γ∗ , v ∗ , b∗ , a∗ )2 ]1/2 · (d−4 )1/2
      ≤qd + Õ(r3ge(σ∗ )/4 · d−2 )
                                                                   ∗   ∗ ∗     ∗             ∗   ∗ ∗     ∗
From Lemma 27. Then, from ge(σ∗ ) ≤ 2 and r ≤ d, we obtain |RICL                     ICL
                                                             Npt (Γ , v , b , a ) − RNtest (Γ , v , b , a )| = od (1)
and arrive at the conclusion from Lemma 26.

F     Auxiliary Lemmas
F.1  High Probability Events on Gaussian and Spherical Variables
                                                      p
Lemma 28 ((Wainwright, 2019), Example 2.11). Let z ∼ x21 + · · · + x2r where x ∼ N (0, Ir ). Then, for any 0 < t < 1,

                                       P[|z 2 − r| ≥ rt] ≤ 2 exp −rt2 /8
                                                                         

                              √
holds. Consequently, z 2 ≤ O(r log d) holds with high probability, and if r = d, d/2 ≤ z 2 ≤ 3d/2 holds with high
probability.

                             √ Ir ), y ∼ N (0, Ir ) independent of x, and a r × r matrix G dependent of neither x nor
Lemma 29. Let r ≤ d, x ∼ N (0,
y. Then, | ⟨x, Gy⟩ | = O(∥G∥2 r log d) holds with high probability.

Proof. x can be decomposed as x = zβ, where β ∼ Unif(Sr−1 ) and √  z = ∥x∥ independent of β. Thus, ⟨x, Gy⟩ =
 zG⊤ β, y holds. From Lemma 28 we have ∥zG⊤ β∥2 = O(∥G∥22 r log d) with high probability, and if we fix x
                                 2        √       √
satisfying this, then zG⊤ β, y = O(∥G∥22 r log d · log d) with high probability again from Lemma 28 (in the case
r = 1). This yields the assertion.
                                   r−1
Corollary 30. Let r ≤ d, β ∼ Unif(S
                                 √     ), y ∼ N (0, Ir ) independent of β, and a r × r matrix G dependent of neither x
nor y. Then, | ⟨β, Gy⟩ | = O(∥G∥2 log d) holds with high probability.
Lemma 31. Let x1 , . . . , xN ∼ N (0, Id ) and let z1 , . . . , zN be i.i.d. random variables satisfying |zi | ≤ C (zi might depend
on xi ) with high probability. Then,
                                                     N
                                                     X                                  p
                                              N −1         zi xi − E[z1 x1 ] ≤ Õ(C      d/N )
                                                     i=1

holds with high probability.

Proof. Define zi′ = I(|zi | ≤ C)zi . Note that zi′ xi is a sub-Gaussian vector, i.e., ⟨zi′ xi , u⟩ is C-sub Gaussian for any
u ∈ Unif(Sd−1 ). Then, a standard concentration bound for sub-Gaussian vectors yields
                                                     N
                                                     X                                  p
                                              N −1         zi′ xi − E[z1′ x1 ] ≤ Õ(C    d/N )
                                                     i=1

                                   PN                 PN
with high probability. As N −1 i=1 zi xi = N −1 i=1 zi′ xi with high probability, it remains to show that ∥E[z1′ x1 ] −
E[z1 x1 ]∥ is sufficiently small. This can be seen by

                                       ∥E[z1′ x1 ] − E[z1 x1 ]| = ∥E[I(|z1 | ≥ C)x1 ]∥
                                                                 = E[I(|z1 | ≥ C)2 ]1/2 [∥x1 ∥2 ]1/2
                                                                 ≤ O(d−C∗ ).

where C∗ can be taken to be sufficiently large from the definition of the high-probability event. This completes the proof.

Applying Lemma 31 to each row yields the following:

                                                                     31
                               Nonlinear transformers can perform inference-time feature learning

Corollary 32. Let x1 , . . . , xN ∼ N (0, Id ) and let v1 , . . . , vN be i.i.d. random vectors satisfying ∥vi ∥ ≤ C (vi might
depend on xi ) with high probability. Then,
                                            N
                                            X                                        √
                                                   vi xi − E[v1 x1 ]         ≤ Õ(Cd/ N )
                                             i=1                         F

holds with high probability.

F.2Hermite Polynomials
Lemma 33. For g(z) = i≥0 ci!i Hei (z),
                    P
                                                    X c2
                                                          i
                                                               = Ez∼N (0,1) [g(z)2 ]
                                                          i!
                                                    i≥0

holds.
Lemma 34 ((Damian et al., 2023), Property 1). For α, β ∈ Sd−1 ,
                                                                                              i
                                 Ex∼N (0,Id ) [Hei (⟨x, α⟩)Hej (⟨x, β⟩)] = i! · I(i = j) ⟨α, β⟩

holds.

G     Experimental Details
For the experiment in Section 6, we used a 6-layer GPT-2 model (Radford et al., 2019) following the configuration used
in (Garg et al., 2022; Oko et al., 2024b). Precisely, the model take the length-(N + 1) prompt (X1:N +1 , y1:N +1 , x) as
input. Then, we first make the embedding as
                                            h                                 i
                                                                          pad
                                   E = W in x1 , y1pad , . . . , xN +1 , yN +1 ∈ R
                                                                                   d×(2N +2)
                                                                                                                    (G.1)

where yipad = [yi , 0, . . . , 0]⊤ and W in ∈ RD×d is a trainable read-in parameter. A 6-layers GPT-2 backbone with 4
attention heads, whose configuration is same as that in Garg et al. (2022) then convert this embedding into E ′ ∈ RD×(2N +2)
where D = 256, and we obtain
                                               [z1 , . . . , z2N +2 ] = (wout )⊤ E ′                                   (G.2)
where wout ∈ RD is also trainable. Here, we use z2i−1 as the prediction of yi based on x1 , y1 , . . . , xi−1 , yi−1 and xi .
Causal attention mask ensure that there is no information leakage. We pretrain the model using the Adam (Kingma & Ba,
2015) optimizer with learning rate 0.0001 on the mean-squared loss calculated over all the positions. We utilize curriculum
learning setting which is also adopted in (Garg et al., 2022) to reduce the pretraining cost. we start from d = 2 and increased
the input dimensionality of by two until the target dimensionality.
The test loss is averaged over 256 independent runs, where each run contains 8,192 independent batches.




                                                                    32
