Papers
Topics
Authors
Recent
Search
2000 character limit reached

A Theoretical Interpretation of In-Context Learning via Probabilistic Modeling

Published 27 Jun 2026 in cs.IT and cs.LG | (2606.28926v1)

Abstract: In-context learning (ICL) is an emerging paradigm that employs the semantic information inherent in LLMs for generating answers to user queries. While the remarkable performance of ICL has been widely known, a general modeling and a rigorous theoretical analysis of this paradigm are still lacking. This work presents a probabilistic model for ICL and derives the performance of ICL for both general parametric distributions and exponential families. Based on the derived results, the work explains the impact of multiple factors such as the number of demonstrations, the sensitivity of the probabilistic model to the variation of its parameters, as well as the similarity between the demonstrations and the query on the performance of ICL.

Summary

  • The paper introduces a probabilistic framework for ICL by modeling input-output pairs via MLE and quantifying risk using expected KL divergence.
  • The paper demonstrates that the asymptotic risk decays as 1/n, with Fisher information guiding optimal demonstration selection.
  • The paper establishes both asymptotic and non-asymptotic bounds, offering actionable insights for prompt engineering in large language models.

Theoretical Insights into In-Context Learning via Probabilistic Modeling

Introduction

The paper "A Theoretical Interpretation of In-Context Learning via Probabilistic Modeling" (2606.28926) addresses the lack of rigorous theoretical understanding of in-context learning (ICL) in LLMs. ICL enables LLMs to perform few-shot generalization strictly through context prompts, without modifying model parameters. This work introduces a principled probabilistic modeling framework for ICL and employs it to characterize the fundamental performance limits and sensitivities of ICL, focusing on derivations for both general parametric conditional distributions and exponential family cases. The main metric of interest is the expected excessive risk (EER), instantiated as the expected KL divergence between the ground-truth and the inferred conditional distribution under the in-context solution.

Figure 1

Figure 1: Schematic diagram of the in-context learning (ICL) framework and its underlying probabilistic modeling pipeline.

Probabilistic Framework for ICL

The modeling starts by treating both input texts and their corresponding outputs as random variables, denoted (X,Y)(X, Y). Each demonstration pair (xi,yi)(x_i, y_i) is a realization, and the set of nn demonstrations is followed by a query xQx_Q, for which the LLM predicts an output yQy_Q by conditioning on the demonstrations.

The central assumption is that, conditional on the input, the outputs are independent and follow a parametric model PY∣X(α)P_{Y|X}^{(\alpha)}, where α\alpha parameterizes the conditional distribution. The ICL mechanism is abstracted as inferring α\alpha via maximum likelihood estimation (MLE) over the demonstrations. The predicted answer to a query is sampled from PY∣X(α^)(yQ∣xQ)P_{Y|X}^{(\hat{\alpha})}(y_Q|x_Q), where α^\hat{\alpha} is the MLE based on the in-context data.

The discrepancy between the true conditional and the inferred conditional is measured by the KL divergence (xi,yi)(x_i, y_i)0 at (xi,yi)(x_i, y_i)1. The EER is the expected value of this KL divergence, reflecting the average risk incurred by inference error attributable to in-context generalization.

Asymptotic and Non-Asymptotic Analysis of EER

The authors prove several strong results regarding the decay of EER with increasing demonstration count (xi,yi)(x_i, y_i)2, both for general parametric families and for exponential families.

Asymptotic Regime

For general parametric models under standard regularity assumptions, the asymptotic EER decays as (xi,yi)(x_i, y_i)3 with an explicit prefactor (xi,yi)(x_i, y_i)4 (the EER coefficient):

(xi,yi)(x_i, y_i)5

The form of (xi,yi)(x_i, y_i)6 is given as a trace involving the Fisher information at query and demonstrations, as well as the covariance of the score functions (see main text for precise formulation).

Specifically, for exponential families, this coefficient reduces to:

(xi,yi)(x_i, y_i)7

where (xi,yi)(x_i, y_i)8 is the Fisher information matrix at input (xi,yi)(x_i, y_i)9. The result encodes the effect of the informativeness (Fisher information) of both query and demonstrations, and allows for immediate comparison of the impact of demonstration selection strategies.

Properties and Implications

  • The EER decays exactly with the number of demonstrations, and the decay rate is modulated by the relative information content in the query and demonstration points.
  • When the Fisher information at the query is greater (in PSD ordering), the risk is larger; risk is minimized when the aggregate demonstration information matches the query's.
  • Lower bounds are established via determinant constraints, pinpointing the optimal configuration of informativeness for demonstration selection.

Non-Asymptotic Bounds

A sharp non-asymptotic upper bound is obtained for the exponential family case, specifying the convergence profile towards the asymptotic regime. The bound is of the form:

nn0

where explicit constants are derived in terms of higher-order derivatives of the log-likelihood and Fisher information properties.

Practical and Theoretical Implications

This formalization demonstrates that ICL in LLMs can be effectively understood as likelihood-based probabilistic inference conditioned on demonstrations. The framework gives explicit guidance for prompt engineering: optimal demonstration selection is tightly linked to matching Fisher information structure between the demonstration set and the query.

The theoretical results clarify that:

  • Increasing the number of demonstrations leads to strictly diminishing risk, quantifiable in terms of information geometry.
  • Demonstration informativeness (Fisher information content) and its match to the query's information profile are decisive for minimizing EER.
  • The exponential family case implies that common NLP modeling assumptions (e.g., conditional softmax distributions) are directly encompassed by the main results.

This advances the analysis of ICL by moving beyond meta-learning or algorithmic simulation views [xie2021explanation, dai2023can, li2023transformers, zhou2023algorithms] to a fully probabilistic, risk-sensitive characterization.

Design Guidance and Future Directions

The findings prescribe that prompt construction should prioritize demonstrations such that the Fisher information profile of the demonstration set matches, as closely as possible, that of the query—a mathematically principled criterion for demonstration selection and ordering. The formalism is agnostic to the specifics of the LLM's architecture, making it applicable to a broad class of pre-trained models, provided the necessary conditional distribution assumptions approximate reality.

Future research could extend this framework to more complex dependency structures among demonstrations (e.g., non-i.i.d. cases), analyze implications for multitask and continual learning setups, and empirically validate the predicted risk decay rates across LLM platforms and tasks. Connections can also be explored between the information-theoretic analysis here and observed empirical sensitivities in prompt engineering [raventos2023pretraining, chan2022data, wang2023large].

Conclusion

This work provides a principled probabilistic foundation for understanding and analyzing in-context learning in LLMs through quantifiable risk guarantees. The results unify and rigorously explain diverse empirical phenomena in ICL, set clear guidelines for optimal demonstration design, and establish a theoretical basis for future studies on the generalization and limitations of ICL in modern neural architectures.

Paper to Video (Beta)

No one has generated a video about this paper yet.

Whiteboard

No one has generated a whiteboard explanation for this paper yet.

Open Problems

We haven't generated a list of open problems mentioned in this paper yet.