Transformers are Minimax Optimal Nonparametric In-Context Learners

In-context learning (ICL) of large language models has proven to be a surprisingly effective method of learning a new task from only a few demonstrative examples. In this paper, we study the efficacy of ICL from the viewpoint of statistical learning theory. We develop approximation and generalization error bounds for a transformer composed of a deep neural network and one linear attention layer, pretrained on nonparametric regression tasks sampled from general function spaces including the Besov space and piecewise $γ$-smooth class. We show that sufficiently trained transformers can achieve -- and even improve upon -- the minimax optimal estimation risk in context by encoding the most relevant basis representations during pretraining. Our analysis extends to high-dimensional or sequential data and distinguishes the \emph{pretraining} and \emph{in-context} generalization gaps. Furthermore, we establish information-theoretic lower bounds for meta-learners w.r.t. both the number of tasks and in-context examples. These findings shed light on the roles of task diversity and representation learning for ICL.

Paper

Similar papers

Peer review

Reviewer eg5H7/10 · confidence 4/52024-07-09

Summary

This paper analyzed in-context learning of a transformer consisting of a DNN and a linear attention layer pretrained on nonparametric regression tasks. The authors derived a general bound on the generalization error consisting of the approximation error, in-context generalization error and pertaining generalization error. They also showed that the icl prediction given by the pretrained TF is minimax optimal when the nonparametric regression functions are from the Besov space or piecewise $\gamma$-smooth class.

Strengths

The paper is well-written and the theoretical results are solid. The authors made reasonable assumptions on the regression tasks and the TF function class that do not significantly simplify the problem. From a technical perspective, this work leverages the approximation ability of DNNs and the ICL ability of single-layer linear attention to derive the near-optimal generalization error bounds. A few generalizations are also considered, e.g., anisotropic Besov space and piecewise $\gamma$-smooth class.

Weaknesses

The paper considered a model different from the standard TF models in practice, in the sense that a trainable DNN-based feature map is applied to the tokens before the attention layer. The proof in this works heavily rely on this feature map, as it is used to approximate the basis functions of the Besov space. Lack of simulation results. The work showed that the empirical risk minimizer is minimax-optimal but didn't analyze the training dynamics. So it would be good to have empirical evidence showing that pretraining indeed finds an empirical risk minimizer.

Questions

1. The functions in the Besov space are well approximated by linear combinations of finite number of basis functions in the space. Suppose now the feature map $\phi$ can well-approximate the basic functions (assumption 3) and is fixed to be $\phi^*$, and only the linear weight in the attention layer is trainable. I wonder how much differences there are between this simplified setting and previous works on ICL for linear regression. 2. I wonder if it is possible to theoretically analyze the training dynamics under the setting where the feature map is given and fixed and only the linear attention is trainable.

Rating

7

Confidence

4

Soundness

3

Presentation

4

Contribution

3

Limitations

As the author already mentioned, this work only analyzed the generalization error of the ERM but not the training dynamics. The transformer model in this work is limited to a single layer of self-attention and does not include the softmax activation and the MLP layer.

Authorsrebuttal2024-08-11

Thank you again for your time and effort in reviewing our paper! As the discussion period is ending soon, we are following up to see if our response was satisfactory in addressing the reviewer's questions. If not, we would be happy to discuss any remaining concerns.

Reviewer eg5H2024-08-13

Thanks for the response. I will maintain my positive score.

Reviewer YwVZ5/10 · confidence 4/52024-07-11

Summary

This paper explores the ICL capabilities of transformers from a statistical learning theory perspective. It focuses on transformers with a deep neural network and a linear attention layer, pretrained on nonparametric regression tasks from function spaces like the Besov space and piecewise gamma-smooth class. The authors demonstrate that sufficiently trained transformers can achieve or even surpass the minimax optimal estimation risk by encoding relevant basis representations during pretraining. The paper also establish result that explains the pretraining and in-context generalization gaps, which is essential for understanding ICL.

Strengths

1. The topic of this work is both interesting and important, addressing key aspects of ICL in transformers. 2. The results developed, especially Theorem 4.5, are very encouraging and could help the community better understand LLMs and their ICL capacity. 3. The analysis provided is rigorous and sound, offering new tools and methodologies for theoretical analysis in the ICL literature.

Weaknesses

1. The writing and presentation of the paper need improvement. For instance, in Section 4, the flow feels disjointed, with several results appearing to be stitched together without a clear, organized connection. 2. Although the ICL capabilities of transformers are powerful and of great interest, the simplified transformer model presented in this paper is not very realistic. While it is common to use simplified models for analyzing LLMs, the paper would greatly benefit from numerical experiments demonstrating the claimed theoretical findings.

Questions

While reading this paper, I feel it provides new insights into understanding ICLs. However, I cannot find concrete evidence of how this theoretical framework can offer supportive insights for practitioners using ICL. The simplified model without numerical experiments cannot indicate how real LLMs behave. Could the authors provide more detailed explanations on how this work connects to the mechanisms of ICL and LLMs in practice?

Rating

5

Confidence

4

Soundness

3

Presentation

2

Contribution

3

Limitations

NA

Reviewer 1n5m5/10 · confidence 3/52024-07-17

Summary

This work shows that ICL can perform non-parametric regression at an optimal rate. Section 3 gives an upper bound on ICL error in terms of a metric entropy of the representation class. Section 4 instantiates the bound for DNN representations and shows it to be optimal. Section 4.3 explores ways to reduce the dependence on dimension. Section 5 gives lower bounds for any ICL (not just transformers). There is a sufficiently expressive representation class $\mathcal{F}$ (here we take DNNs) from which we can draw a $\phi^*$ such that linear attention on top of this solves regression well. In that sense, this paper generalizes the idea from linear attention for linear regression that the attention inverts the data-covariance.

Strengths

The paper contains a general analysis of ICL error for regression problems. The comparison to non-parametric rates is interesting and possibly the right way to extend the so far mostly linear analysis in the literature to problems beyond linear regression.

Weaknesses

This is general analysis of a very specific simplification of the transformer. The setting is that there are trainable layers before the attention layer, and then exactly one linear attention layer. Is there any hope to extend this analysis to more attention layers/ non-linear attention/ constant $N$? When $N$ is constant, the error is constant, which seems vacuous considering everything is bounded. Is that an artifact of analysis? Is it possible to have a setting where we removed the DNN and force the features themselves to satisfy Assumption 3? Would that reduce to the linear regression setting of prior work? If so, it seems very important to justify how we can find a $\phi^*$ satisfying Assumption 3 for DNNs.

Questions

A matter of notation: in assumption 1, why aren’t the basis functions the first N functions, rather than the functions from $\underline{N}$ to $\overline{N}$? Also, are the functions past $\overline{N}$ not spanned by the basis? Remark 2.1 offers some explanation. I think it would be helpful to write the main paper in the setting where $\psi$'s span the space and leave the generalization for the appendix. What role does the sparsity $S$ play, why is it set to be $O(1)$? Isn't is unrealistic that $N$ should scale in $n$ for a real transformer (one of the key selling points about transformers are how the parameters dont scale in the context length)? Do the authors think this is due to the analysis or is it fundamental for attention? It would be helpful to instantiate a target function class in the main paper, specify what $\alpha$ is, etc.

Rating

5

Confidence

3

Soundness

3

Presentation

2

Contribution

3

Limitations

Yes

Authorsrebuttal2024-08-06

(continued from rebuttal) * **Isn't is unrealistic that $N$ should scale in $n$ for a real transformer?** In practice we agree that the architecture should not depend on $n$, especially if prompts of any length are allowed. However since we assume **all** prompts (during both pretraining and ICL) are of fixed length $n$, it is reasonable to choose a more powerful architecture for larger $n$. Strictly speaking, $N$ does not need to scale in $n$ since our bounds hold for all $N,n,T$. But the bound itself is natural: as we mentioned, approximation error must decrease in $N$ due to the infinite dimensionality of the target class, and generalization error should of course decrease in $n,T$. For example if $N$ is considered fixed, the bound is interpreted as an excess risk of $O(1/n+1/T)$. However we want to obtain the *overall* sample complexity rate in $n$, which necessitates $N$ to scale in $n$. The rate itself is less important than the fact that it is the *best rate attainable by any estimator*, and the optimality result should be viewed more as guaranteeing tightness of the derived bounds (further justified by Section 5) than a prescription of how $N,T$ should scale. We also mention that this approach is standard in minimax analyses. For example, rate-optimal scaling for ordinary supervised regression with DNNs (Suzuki, 2019) also requires the width to scale as $n^{\frac{1}{2s+1}}$ even though the smoothness of the target is unknown. * **Rebuttal End** Finally, we have also obtained **improved lower bounds** which reinforce the message of our paper, and newly conducted **numerical experiments** justifying our assumptions and results. Please see Item 2 and Item 3 of the global response for details. We also humbly ask the reviewer to consider raising their score if some of their concerns were addressed.

Authorsrebuttal2024-08-11

Thank you again for your time and effort in reviewing our paper! As the discussion period is ending soon, we are following up to see if our response addressed the reviewer's questions. If so, we hope that they would be willing to increase their score. If not, we would be happy to discuss any remaining concerns.

Reviewer KRWK6/10 · confidence 3/52024-07-29

Summary

This paper studies in-context nonparametric learning using transformers. In the setting used in the main result of the paper, the transformer is trained on a dataset consisting of multiple sequences/tasks. For each task, the target function $F_\beta$ is drawn from the span of a certain countable set of functions - in the setting used for the main result of the paper, the target function is drawn from a Besov space spanned by a B-spline wavelet basis. The task then consists of multiple in-context pairs $(x_k, y_k)$, where $y_k$ is $F_\beta(x_k) + \xi$, where $\xi$ is random noise. Certain technical assumptions are made on the basis functions $\psi_j$ and the coefficients $\beta_j$: the $\psi_j$ are assumed to have a property that is similar to linear independence/orthonormality, while the $\beta_j$ are assumed to decay at a certain rate. The model in this paper's setting consists of a feature map $\phi$ applied to all of the $x_k$, followed by a linear attention layer applied to the $\phi(x_k)$ and the $y_k$. The feature map $\phi$ is assumed to be expressive enough to approximate the $\psi_j$. In the main result of this paper, $\phi$ is chosen from the class of deep neural networks (DNNs) with a logarithmic number of layers (logarithmic in the size of the feature map), and $O(1)$ width and $O(1)$ entries per layer. The class of feature maps $\phi$ is denoted as $\mathcal{F}_N$, and the overall model class is denoted as $\mathcal{T}_N$. The main result of the paper, Theorem 4.5, is that with a sufficient number of tasks during pretraining, in-context learning with transformers will achieve the optimal minimax risk. This is shown as follows. Theorem 3.1 first gives a bound on the expected test loss in terms of the covering number of the model class $\mathcal{T}_N$, and the minimum test loss achievable by some member of $\mathcal{T}_N$. Next, the paper gives a particular construction for a set of parameters which achieves low test loss. The weight matrix for the linear attention layer is chosen similarly to the optimal weight matrix given in Zhang, et al. (2023) and nonlinear feature map outputs a subset of the basis functions. Additional results are also given. This paper shows how the curse of dimensionality can be avoided when the target function is drawn from an anisotropic Besov space. Also, under certain assumptions, even if the target function is drawn from a Besov space with smoothness $\tau < \alpha$, it is possible to achieve the same minimax rate as in the case where the target function is drawn from a Besov space with smoothness $\alpha$. Finally, the paper gives similar results in the setting where the tokens are themselves sequences of unbounded length, and gives minimax lower bounds that match the upper bounds.

Strengths

- This work seems to be the first to study in-context learning using transformers in Besov spaces (prior work studied settings such as regression with DNNs). - The paper is very well-written.

Weaknesses

I think the main weakness is that the techniques used to show Theorem 4.5 are somewhat standard. - Theorem 3.1, which shows that the empirical risk minimizer achieves good test loss, seems to be using relatively standard arguments from previous work, based on covering numbers. - The construction used to show that low approximation error can be achieved also seems somewhat straightforward. The weight matrix for the attention layer is chosen similarly to Zhang, et al. (2023), and the feature map outputs a subset of the basis vectors.

Questions

- In Lemma 4.4, how important is the assumption that the width/sparsity of the deep neural network is $O(1)$? Would the guarantee obtained in Theorem 4.5 change if the deep neural network is allowed to have more nonzero entries? - Could the setting in this paper be considered similar to the linear regression setting studied by previous works such as Zhang, et al. (2023), with the difference being that the linear regression weight vector is replaced by the vector $\beta$ of coefficients for the basis functions?

Rating

6

Confidence

3

Soundness

4

Presentation

4

Contribution

2

Limitations

Yes.

Reviewer YwVZ2024-08-09

Thanks for the reply. My questions are partly addressed and I'll maintain my rating.

Authorsrebuttal2024-08-09

Thank you for taking the time to read our rebuttal! As your criticisms were generally on the lack of numerical experiments, if there are any other types of experiments which you believe will further benefit our paper, please inform us and we will strive to implement them to gain more insight into our analyses.

Authorsrebuttal2024-08-11

Thank you again for your time and effort in reviewing our paper! As the discussion period is ending soon, we are following up to see if our response addressed the reviewer's questions. If so, we hope that they would be willing to increase their score. If not, we would be happy to discuss any remaining concerns.

Reviewer KRWK2024-08-13

Thank you for the detailed reply. I am not familiar with the literature on wavelet systems, but since the covariance matrix may not be invertible, this suggests that the analysis in this work is more than a direct extension of Zhang, et al. The lower bound in the coarser basis setting is also an interesting takeaway. I will increase my score to 6. Could you please clarify the following: - For your main setting, you mention in the global response that your upper bound is jointly optimal in $n, T$. In what sense is it optimal in $T$? - How do you select $N$ in Theorem 4.5 and Corollary 4.9? Would it be possible to optimize the bound in Corollary 4.9 further by selecting a different $N$?

Authorsrebuttal2024-08-13

We are very grateful to the reviewer for re-evaluating our contributions and raising their score! Here are some further clarifications: * Wavelet systems form a hierarchy ordered by resolution, and wavelets with lower resolution can always be written as a combination of those with higher resolution (forming the basis of *multiresolution analysis* theory). Hence the covariance matrix is indeed never invertible, necessitating our new 'aggregation' techniques. * ICL can be viewed as a meta-learner which takes as input not just $n$ samples from the current task but also $(n+1)T$ samples from related tasks. Now also consider $T$ as a variable. It could be the case that a well-designed meta-estimator (possibly not constrained to be fixed at inference time) can achieve a rate faster than $n^{-\frac{2\alpha}{2\alpha+d}}$ by taking all these samples as input, as the ordinary minimax rate only applies to estimators which only learn from $n$ ground-truth samples. Our lower bound shows that this is impossible: *any* estimator that takes the $n$ ground-truth \& $(n+1)T$ related samples as input is still lower bounded by $n^{-\frac{2\alpha}{2\alpha+d}}$. Since our upper bound matches this when $T$ is sufficiently large, we conclude that ICL is **optimal in both** $n,T$. Conversely, the new lower bound $n^{-\frac{2\alpha}{2\alpha+d}} + (nT)^{-\frac{2\tau}{2\tau+d}}$ in the coarser basis setting allows us to conclude that ICL (or any other meta-learner) is **suboptimal in both** $n,T$ when $T<n^{\frac{(\alpha-\tau)d}{\tau(2\alpha+d)}}$, supplementing our upper bound in Corollary 4.9. * The selection of $N$ is standard rate analysis, except that we also have to consider the effect of $T$ through the pretraining gap. Let's look at Theorem 4.5. First assume $T\gtrsim nN$ so that the 3rd term can be ignored compared to the 2nd term. Then we want to choose $N$ such that $N^{-2\alpha/d}+\frac{N\log N}{n}$ is minimized, which can be found by balancing $N^{-2\alpha/d}\asymp\frac{N}{n}$ and thus $N\asymp n^\frac{d}{2\alpha+d}$ (ignoring log terms). However if $T<nN$ then the 3rd term dominates and $N^{-2\alpha/d}+\frac{N^2\log N}{T}$ is minimized when $N\asymp T^\frac{d}{2\alpha+2d}$, so the overall risk is now bounded suboptimally as $T^{-\frac{\alpha}{\alpha+d}}$. * Corollary 4.9 is similarly tuned and the bound cannot be optimized further as we also proved it is optimal in both $n,T$ when $T$ is large. Again there is some suboptimal scaling when $T$ is small, but -- as we indicate in our global response -- for this regime it is better to look at the information-theoretic lower bound which gives a rigorous proof of suboptimality.

Program Chairsdecision2024-09-25

Decision

Accept (poster)

© 2026 NYSGPT2525 LLC