Pretrained transformer efficiently learns low-dimensional target functions in-context

Kazusato Oko, Yujin Song, Taiji Suzuki, Denny Wu · DOI

Pretrained transformer efficiently learns low-dimensional target functions in-context

Abstract

This paper provides the first end-to-end theoretical guarantee showing that pretrained transformers can learn nonlinear functions in-context with a sample complexity that depends only on the task's intrinsic dimensionality ($r$), rather than the high-dimensional ambient space ($d$). By "learning the prior" during pretraining, transformers effectively bypass the curse of dimensionality that plagues standard estimators like kernel regression during inference.

Introduction

In-context learning (ICL) allows transformers to solve new tasks using only a few examples in a prompt, without any parameter updates. While empirical success is undeniable, theoretical explanations have largely focused on linear models, often suggesting that transformers simply implement a single step of gradient descent (GD) on the prompt. However, if a transformer were merely performing standard GD on a linear prompt, it should not be more statistically efficient than a basic linear regression solver. This fails to explain why transformers are so effective at capturing specific structures or "priors" from their training data.

The authors address this gap by studying a more realistic scenario: nonlinear function classes where data is high-dimensional ($d$), but the underlying task depends on a much smaller $r$-dimensional subspace. They investigate whether a pretrained transformer can adapt to this low-dimensional structure to make ICL more efficient than baseline algorithms.

Methodology

The study focuses on a transformer architecture equipped with a nonlinear Multi-Layer Perceptron (MLP) layer and a simplified linear attention mechanism.

Target Function Class

The researchers analyze Gaussian Single-Index Models: $f_*(\boldsymbol{x}) = \sigma_*(\langle\boldsymbol{x}, \boldsymbol{eta}\rangle)$, where $\boldsymbol{eta}$ resides in a fixed $r$-dimensional subspace ($r \ll d$) and $\sigma_*$ is a nonlinear "link" function.

Two-Stage Pretraining

A layer-wise training procedure is analyzed:

  1. Stage I (Feature Learning): Gradient descent optimizes the MLP embedding layer to identify the relevant $r$-dimensional subspace from the $d$-dimensional noise.
  2. Stage II (Algorithm Learning): The attention matrix is optimized via Empirical Risk Minimization (ERM) to learn the regression algorithm on the extracted features.

Results

The primary theoretical result (Theorem 1) proves that with sufficient pretraining tasks ($T \gtrsim d^{\Theta(Q)}$), the transformer achieves low prediction risk with a test prompt length $N^*$ that depends only on $r$ (specifically $N^* \gtrsim r^{\Theta(P)}$). This demonstrates a clear separation: pretraining complexity scales with the ambient dimension $d$, but inference (ICL) complexity scales only with the intrinsic dimension $r$.

The pretrained transformer (purple) significantly outperforms Kernel Ridge Regression (orange) and two-layer NNs (pink). Notably, the transformer's performance is nearly identical for $d=16$ and $d=32$, confirming its ambient-dimension-free nature.

Empirical validation using a GPT-2 model confirms these findings. As shown in the figure above, the ICL risk curves for the pretrained transformer overlap across different ambient dimensions when the intrinsic dimension is held constant. In contrast, baseline methods like Kernel Ridge Regression (KRR) and two-layer Neural Networks trained from scratch suffer significantly as the gap between $r$ and $d$ increases.

Discussion and Limitations

The "ambient vs. intrinsic" separation highlights how transformers use pretraining to "learn the subspace," enabling efficient low-dimensional regression during the forward pass. The nonlinear MLP layer acts as the engine for feature extraction.

However, several limitations remain:

  • Simplified Architecture: The analysis uses linear attention and layer-wise training, whereas real-world models use SoftMax attention and end-to-end training.
  • Feature Learning in ICL: It remains an open question whether transformers can perform feature learning (identifying new subspaces) during the ICL phase itself.
  • Link Function Complexity: Pretraining complexity depends on the "information exponent" of the link function, which may be high for complex nonlinearities.

Future research could explore if different training objectives can lower pretraining requirements or if transformers can adapt to entirely new subspaces during inference.

Summary updated

BibTeX
@inproceedings{oko2024pretrained,
  author = {Kazusato Oko and Yujin Song and Taiji Suzuki and Denny Wu},
  title = {{Pretrained transformer efficiently learns low-dimensional target functions in-context}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=uHcG5Y6fdB},
}
Figure