[Paper Review] Transformers as Algorithms: Generalization and Stability in In-context Learning
The paper formalizes in-context learning (ICL) as an algorithm learning problem in which a transformer implicitly constructs a hypothesis function during inference, and provides generalization/stability bounds for multitask and transfer learning under i.i.d. and dynamical-system prompts.
In-context learning (ICL) is a type of prompting where a transformer model operates on a sequence of (input, output) examples and performs inference on-the-fly. In this work, we formalize in-context learning as an algorithm learning problem where a transformer model implicitly constructs a hypothesis function at inference-time. We first explore the statistical aspects of this abstraction through the lens of multitask learning: We obtain generalization bounds for ICL when the input prompt is (1) a sequence of i.i.d. (input, label) pairs or (2) a trajectory arising from a dynamical system. The crux of our analysis is relating the excess risk to the stability of the algorithm implemented by the transformer. We characterize when transformer/attention architecture provably obeys the stability condition and also provide empirical verification. For generalization on unseen tasks, we identify an inductive bias phenomenon in which the transfer learning risk is governed by the task complexity and the number of MTL tasks in a highly predictable manner. Finally, we provide numerical evaluations that (1) demonstrate transformers can indeed implement near-optimal algorithms on classical regression problems with i.i.d. and dynamic data, (2) provide insights on stability, and (3) verify our theoretical predictions.
Motivation & Objective
- Motivate and formalize in-context learning (ICL) as an algorithm learning problem where a transformer constructs a hypothesis function at inference time.
- Derive generalization bounds for ICL in multitask learning (MTL) under i.i.d. and dynamical-prompt settings.
- Characterize stability properties of transformer architectures that underpin these generalization guarantees.
- Investigate transfer learning (unseen tasks) and inductive biases governing cross-task generalization.
- Provide numerical evaluations that validate near-optimal algorithm implementation and stability insights.
Proposed method
- Model ICL as an implicit optimization on the in-context sequence that yields a prediction function f^{Alg}_{S^{(m)}}.
- Prove generalization bounds via algorithmic stability, yielding an MTL rate of 1/sqrt(nT) for i.i.d. and dynamic data.
- Establish stability conditions for self-attention in transformers and relate stability to excess risk through Lipschitz and perturbation analyses.
- Extend the framework to dynamical-system prompts with exponential (C_rho, rho)-stability and adapt stability-based arguments accordingly.
- Use covering numbers and Dudley/empirical process ideas to convert stability into finite-sample excess risk bounds.
- Provide empirical verifications showing ICL can implement near-optimal algorithms on classical regression tasks and validating transfer/inductive-bias insights.

Experimental results
Research questions
- RQ1Under what conditions does in-context learning generalize across tasks in a multitask learning setup?
- RQ2How does transformer stability influence generalization bounds for ICL with i.i.d. prompts and with dynamical-system prompts?
- RQ3What is the transfer learning behavior of ICL on unseen tasks and how do task complexity and the number of source tasks govern it?
- RQ4Can ICL be interpreted as implementing near-optimal algorithms (e.g., ridge regression) on regression problems, and how does prompt length affect stability?
- RQ5How does the alignment between source-task structure and target-task distance affect transfer risk in linear and dynamical settings?
Key findings
- ICL generalization achieves a 1/sqrt(nT) rate in multitask settings for both i.i.d. and dynamic prompts.
- Self-attention stability can be bounded; under certain norm constraints, transformer-based ICL obeys the stability condition that yields generalization guarantees.
- Empirically, ICL predictions become more stable with longer prompts, and training with noisy data promotes stability.
- There is an inductive bias in transfer learning: the transfer risk is governed by task complexity and the number of MT tasks, with little dependence on model size.
- For linear regression-like tasks, transfer risk and MTL risk curves align, with transfer risk scaling roughly as d^2/T in experiments.
- Across dynamical systems, ICL can outperform autoregressive LS estimators given sufficient memory and stable dynamics.
![Figure 3: The benefit of learning across the full task sequence: Right side: Standard ERM where each task trains with all $n=40$ prompts. Left side: ERM focuses on different parts of the trajectory by fitting $n/4=10$ prompts per task over $i\in[1,10]$ to $[31,40]$ (highlighted as the orange ranges)](https://ar5iv.labs.arxiv.org/html/2301.07067/assets/x6.png)
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.