cs.LGFeb 19, 2026

Bayesian Optimality of In-Context Learning with Selective State Spaces

Authors: Di Zhang, Jiaqi Xing

Organizations: School of AI and Advanced Computing Xi’an Jiaotong-Liverpool University Suzhou, Jiangsu, China

Abstract

We propose Bayesian optimal sequential prediction as a new principle for understanding in-context learning (ICL). Unlike interpretations framing Transformers as performing implicit gradient descent, we formalize ICL as meta-learning over latent sequence tasks. For tasks governed by Linear Gaussian State Space Models (LG-SSMs), we prove a meta-trained selective SSM asymptotically implements the Bayes-optimal predictor, converging to the posterior predictive mean. We further establish a statistical separation from gradient descent, constructing tasks with temporally correlated noise where the optimal Bayesian predictor strictly outperforms any empirical risk minimization (ERM) estimator. Since Transformers can be seen as performing implicit ERM, this demonstrates selective SSMs achieve lower asymptotic risk due to superior statistical efficiency. Experiments on synthetic LG-SSM tasks and a character-level Markov benchmark confirm selective SSMs converge faster to Bayes-optimal risk, show superior sample efficiency with longer contexts in structured-noise settings, and track latent states more robustly than linear Transformers. This reframes ICL from "implicit optimization" to "optimal inference," explaining the efficiency of selective SSMs and offering a principled basis for architecture design.

Figures & tables

Explore similar work

CardsList
  1. A Comparative Analysis of Attention versus State-Space Models for In-Context Learning

    Sep 26, 2026Enes Arda, Semih Cayci, Atilla EryilmazState Space ModelsIn-Context Learning

  2. Implicit Statistical Inference in Transformers: Approximating Likelihood-Ratio Tests In-Context

    Mar 11, 2026Faris Chaudhry, Siddhant GadkariLikelihood Ratio TestingIn-Context Learning