TL;DR
While in-context learning (ICL) is usually associated with GPT-style autoregressive models, this paper provides a unified theoretical framework proving that masked language models (like BERT) share the same statistical guarantees. Through Wasserstein-based excess-risk analysis and synthetic experiments, the authors demonstrate that ICL is a fundamental property of both pretraining paradigms, rather than a unique feature of causal architectures.
What Problem Does This Paper Address?
In-context learning (ICL)—the ability of a large language model to adapt to a new task at inference time simply by conditioning on a few input-output examples—has become a defining feature of modern AI. However, almost all theoretical explanations of why and how ICL works focus exclusively on causal, left-to-right autoregressive language models (like GPT).
Masked language models (like BERT), which predict missing tokens using bidirectional context, are a cornerstone of representation learning but remain poorly understood regarding ICL. This paper addresses this gap by answering a fundamental question: How do autoregressive and masked objectives differently affect the excess risk and scaling behavior of ICL?
Methods
The authors bridge the gap by developing a unified statistical learning framework that abstracts how a prompt is represented. Instead of treating the prompt as an ordered sequence of tokens, they encode the context examples as an empirical measure (a data distribution) and model the prediction as a function of this measure and the query: $f(\rho, x)$.
This abstraction allows them to cast both objectives into a single predictor class, differing only in how the context measure is constructed:
- Masked Objective: Modeled using a leave-one-out empirical measure, where the target label is excluded from the bidirectional context.
- Autoregressive Objective: Modeled using a prefix empirical measure, where only preceding examples are visible to the predictor.
Using Wasserstein distance metrics, they perform an excess-risk analysis to track how pretraining on $T$ tasks with $N$ samples per task translates to $k$-shot inference performance. They also extend this framework to out-of-distribution (OOD) settings by introducing a "lifted" Wasserstein distance to quantify task-distribution shifts.
Datasets
The authors validate their theoretical framework using controlled synthetic function-learning tasks, evaluating models on their ability to learn mathematical operations in-context:
- Dense Linear Regression: The canonical baseline for evaluating ICL against standard statistical methods like Ordinary Least Squares (OLS).
- Noisy Linear Regression: Used to test model robustness against data noise and observe double-descent phenomena.
- Random Depth-4 Decision Trees: A non-linear task testing the model's ability to handle axis-aligned splits.
- Two-layer ReLU Networks: A complex neural function class that serves as a rigorous non-linear test.
Key Insights and Ideas
- ICL is Paradigm-Agnostic: Theoretically, masked and autoregressive objectives yield the same-order upper bounds for excess risk. This suggests that ICL capability is an intrinsic property of attention-based architectures trained on multi-task data, not a quirk of causal masking.
- Quantifying Task Shift: If the pretraining task distribution ($\mathbb{P}$) differs from the evaluation task distribution ($\mathbb{Q}$), the performance degradation is linearly controlled by the lifted Wasserstein distance between $\mathbb{P}$ and $\mathbb{Q}$.
- Beating the Curse of Dimensionality: Standard statistical bounds suffer heavily as data dimensionality increases. However, the authors prove that if the underlying task data concentrates on a low-dimensional manifold or forms distinct clusters, the within-task error rate sharpens significantly, depending only on the intrinsic dimension rather than the ambient space.
- Optimal Data Allocation: Under a fixed pretraining data budget ($B = T \times N$), the framework derives an order-optimal allocation strategy to perfectly balance task diversity ($T$) against the number of examples per task ($N$).
Key Results
The authors introduce the Masked Pair Encoder (MPE), a bidirectional Transformer encoder trained with a masked label-prediction objective, and pit it against a GPT-2-style causal Transformer.
- Comparable Performance: Across all four synthetic function-learning tasks, the MPE achieved performance virtually indistinguishable from the causal baseline.
- Algorithmic Alignment: In linear regression, both models closely tracked the performance of OLS once the number of in-context examples exceeded the input dimension ($n > d_{in}$).
- Robustness to Noise: In noisy settings, the MPE followed the least-squares trend smoothly without experiencing the extreme "interpolation spike" typical of OLS near the threshold, proving it learns a robust estimator rather than simply memorizing prompts.
Limitations and Future Work
- Idealized Objectives: The framework analyzes simplified mathematical abstractions of masking and autoregression (e.g., masking specific target labels) rather than the token-level masking strategies used in real-world BERT or GPT pretraining.
- A Priori Structure Assumptions: The mitigation of the curse of dimensionality relies on explicit assumptions about low-dimensional data structures, leaving open the question of how neural networks adaptively discover these structures during training.
- Synthetic Scope: The empirical verification is entirely restricted to synthetic mathematical functions. Extending this evaluation to large-scale natural language benchmarks is an essential next step.
Summary updated