In-Context Learning as Nonparametric Conditional Probability Estimation: Risk Bounds and Optimality

Chenrui Liu, Falong Tan, Chuanlong Xie, Yicheng Zeng, Lixing ZhuarXiv 2025 · DOI

Introduction

In-Context Learning (ICL) has emerged as a defining capability of modern Large Language Models (LLMs), allowing them to solve novel tasks using only a few examples provided in a prompt. Despite its empirical ubiquity, theoretical explanations for ICL have often lagged behind. Existing theories frequently rely on simplified assumptions, such as linear regression tasks, binary classification, or "infinite context" limits where the prompt length grows indefinitely.

This paper addresses these gaps by providing a rigorous statistical foundation for ICL, framing it as a problem of nonparametric conditional probability estimation. By shifting the focus from context-scaling (the number of examples in a prompt) to task-scaling (the number of tasks encountered during pretraining), the authors establish minimax optimal convergence rates for both Transformers and Multilayer Perceptrons (MLPs).

Formalizing In-Context Learning

The authors formalize ICL as the process of estimating the conditional class probabilities of a query input given a prompt consisting of $N$ labeled examples. Unlike previous works that focus on the internal mechanics of attention, this framework treats the model as a statistical estimator operating over a distribution of tasks.

Risk Metric and Oracle Inequality

To measure performance, the study employs the expected truncated Kullback-Leibler (KL) divergence. Truncation is a critical technical necessity; it prevents the risk from becoming infinite if a model assigns a near-zero probability to a class that actually occurs.

A central contribution of the paper is a new oracle inequality that decomposes the ICL risk into three distinct components:

  1. Approximation Error: The inherent ability of the chosen architecture (Transformer or MLP) to represent the target distribution.
  2. Optimization Error: The gap between the model found during training and the global minimum.
  3. Generalization Error: The model's ability to perform on unseen tasks.

To provide sharper bounds on generalization, the authors introduce a method based on uniform empirical entropy. This data-dependent measure offers more precise complexity control than traditional $L^\infty$-metric entropy, which considers the model's complexity over the entire possible input space.

Task-Scaling and Minimax Optimality

In the "few-shot" regime—where the context length $N$ is fixed and relatively small—the primary driver of performance is the number of pretraining tasks $T$. The paper proves that the ICL estimator achieves the minimax optimal rate of $T^{-2\beta/(2\beta+d)}$ (up to logarithmic factors).

In this rate:

  • $\beta$ represents the Hölder smoothness of the task distributions (characterizing the complexity of the underlying function).
  • $d$ represents the dimension of the input.

This result demonstrates that as the diversity and quantity of pretraining tasks increase, the model's ICL performance improves according to a predictable power law, reaching the theoretical limits of what any statistical estimator can achieve.

Architecture Agnosticism: Transformers vs. MLPs

One of the paper's most significant findings is that the "magic" of ICL is not exclusive to the Transformer architecture. While self-attention is often credited for ICL's success, the authors demonstrate that deep ReLU MLPs can also achieve minimax optimal rates under similar conditions.

Both architectures are shown to be universal approximators for Hölder-smooth conditional probability distributions. This suggests that the ICL phenomenon is driven more by the training objective and the diversity of the task distribution than by a specific "secret sauce" within the attention mechanism. However, the authors note that in practice, Transformers may still possess inductive biases that make them more efficient at navigating low-dimensional structures within high-dimensional data.

Limitations and Future Directions

While the paper provides a robust theoretical framework, several challenges remain:

  • The Optimization Gap: The theory assumes the existence of a model that minimizes empirical risk. It does not solve the non-convex optimization problem inherent in training deep neural networks.
  • The Curse of Dimensionality: The established convergence rates are still subject to the "curse of dimensionality," where the required number of tasks $T$ grows exponentially with the input dimension $d$.
  • The Manifold Hypothesis: Real-world data often resides on low-dimensional manifolds. Future research could explore whether ICL convergence rates improve when the underlying data structure is simpler than the ambient dimension $d$ suggests.

Conclusion

By reframing In-Context Learning as a classical statistical estimation problem, this work demystifies the success of few-shot learning in LLMs. It establishes that ICL is a principled approach to nonparametric estimation, where performance is fundamentally governed by the scale and smoothness of the pretraining task distribution, regardless of whether the underlying architecture is a Transformer or a sufficiently deep MLP.

Summary updated

BibTeX
@misc{liu2025context,
  author = {Chenrui Liu and Falong Tan and Chuanlong Xie and Yicheng Zeng and Lixing Zhu},
  title = {{In-Context Learning as Nonparametric Conditional Probability Estimation: Risk Bounds and Optimality}},
  year = {2025},
  eprint = {2508.08673},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2508.08673},
}
Figure