arXiv:2611.00921cs.LGOct 2026

Manuscript Offprint

arXiv:2611.00921

Solvable dynamics model of in-context learning

Ruoran Bai, Haiping Huang

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Pretrained Transformer architectures display a surprising in-context learning ability without additional training. How learning process guides the network to achieve this intriguing capability remains unsolved. In this study, we focus on a single layer single head linear attention model, where an empirical risk minimization is defined for learning. Given a finite amount of training examples, we determine the exact solution of network parameter dynamics, which is linked to the training error and generalization error, characterizing how memorization and generalization emerge from learning and how these transitions are related to curvatures of the empirical risk landscape. Furthermore, we calculate a data-dependent free energy, from which the training and generalization errors in the long time limit of learning dynamics can be well predicted. Our work adds insights toward understanding the mechanism of in-context learning especially from a learning dynamics perspective.

∗^{*}Electronic address: huanghp7@mail.sysu.edu.cn

I. INTRODUCTION

Inspired by the study of attention mechanism in the brain [1–3], an engineering generalization of the biological attention to the self-attention dominant in the current transformer computation starts a revolution in natural language processing first and recently the artificial general intelligence including superhuman capabilities in coding, mathematical reasoning, and documents comprehension [4, 5]. The self-attention captures long-range dependencies between different parts of the input (e.g., image or text), trained with a simple cost of next-token prediction [6], establishing a computer science foundation of large language model (LLM) [7].

As one of the astonishing abilities, the transformer is able to do in-context inference [8], i.e., the pre-trained transformer is able to accomplish previously-unseen complicated tasks by reasoning on a short prompt especially without a need for updating the model parameters. This remarkable property recently captures intense research interests from theoretical machine learning and statistical physics communities [9–17]. The theoretical efforts focused on a single-layer linear attention [9, 13–16], which revealed that a sufficient pre-training task diversity triggers the emergence of in-context inference. This phase transition was first empirically confirmed in the in-context learning of a regression task [12], later analytically studied in the asymptotic high-dimensional limit [14], and formulated recently in a disordered spin glass framework where the network parameters act as spins while training data act as quenched coupling between spins. Recent theoretical works start to focus on the learning dynamics of transformer in linear regression tasks, especially on the population loss (given infinite training prompts) [16, 18] and on the neural scaling law in training time, depth and context length [19]. An recent work derives non-asymptotic closed-form characterization of the learning dynamics for vector-valued regression [20].

Based on our previous work of statistical physics analysis of in-context learning (ICL), we continue to explore the learning dynamics of an empirical risk minimization in this work. We first describe the model setting which allows a closed-form solution of the network parameter dynamics, from which we can predict the behavior of individual concrete learning trajectory and related test performance on unseen linear regression examples. We also derive data-dependent statistical mechanics formalism to explain the stationary limit of the learning dynamics, supported by numerical experiments of single instance learning. Furthermore, we simplify our analytic results in specific setting, e.g., setting a particular set of network parameters zero, thereby isolating the key factor in the form of a data-dependent eigenvalue spectrum.