betaFeedback

WorksComputer Science

In-Context Learning Before Specialisation: Theory of Learning in a Solvable Topic Model

Abstract

Sequence models can generalise in fundamentally distinct ways: extrapolating structures seen in training, or using their prompt to adapt to novel tasks. The prevailing strategy determines how the model behaves beyond its training distribution, controlling potential capabilities and risks. Recent work has characterised many different strategies theoretically, and empirically described the transition between them as the quality and quantity of pretraining data vary. However, there is no learning theory for this competition, hence no fundamental understanding of why one solution might be favoured over another. Here we provide such a theory in a solvable topic model—documents drawn from a finite mixture of latent topics, mirroring the heterogeneity of modern pretraining data. The dataset comes with two distinct solutions: a specialised predictor, that stores the finite topic mixture, and an in-context one, optimal for topics never seen during training. Our theory predicts their emergence at distinct sample complexities: the in-context predictor is available early, while the specialised one emerges only after the training tokens outnumber the parameters of the data-generating process. Trained transformers reproduce both scales and the separating crossover in remarkable agreement with the theory, with no fitted parameters.

Introduction

Large language models generalise in ways that were not anticipated in training. In particular, novel behaviours can be elicited simply via prompting, including few-shot learning of supervised tasks [9] or adopting different roles depending on a set of instructions [34]. This In-Context Learning (ICL) mechanism is not captured by the classical learning-theoretic paradigm, where a model is evaluated on fresh samples from same the distribution it was trained on. Nevertheless, ICL is a critical source of both generality and risk [4] in modern AI systems, calling for a theory of what trained models do beyond their training distribution.

An early theoretical attempt framed ICL as implicit Bayesian inference of the latent concept behind the prompt [38]. This framework has found extensive support: trained transformers behave as Bayes-optimal estimators for many families of tasks [17], and how such estimators are represented and acquired during training is understood in simple settings [26, 15, 24, 40, 7]. However, other settings admit distinct classes of predictors, and models transition between them as the training conditions vary [1]. Raventos et al. [29] identified task diversity as the key control parameter: When trained at low diversity, the transformer can only memorise the training tasks, acquiring general ICL abilities only above a certain task-diversity threshold.

The role of task diversity has been explored in synthetic data, revealing that the competition between the two behaviours extends along training time [35, 31, 25, 28, 18], culminating in a hierarchical Bayesian framework that fits the model behaviour to a weighted mixture of the memorising and generalising predictors [11, 37]. This framework is phenomenological: still missing is a microscopic theory that predicts the favoured solution from data properties alone, and how much data it takes for one solution to give way to the other.

Our Contribution Here we provide this theory in a synthetic dataset containing the minimal required ingredients: a task diversity parameter DD, a vocabulary of size KK, a document length TT and a corpus of NN training documents. Task diversity enters as a mixture of DD latent topics from which documents are generated (Figure 1, left). In this setting, we provide:

In-context learning and specialisation in a random topic model

Figure 1. In-context learning and specialisation in a random topic model. Left: A random topic model consists of DD topics, i.e. unigram probabilities pz∈ΔK−1p_z \in\Delta^{K-1} over a vocabulary of size KK. Training sequences are obtained by sampling a topic zz uniformly, then TT tokens i.i.d. from pzp_z. Right: Learning curve of a one-layer transformer trained for next-token prediction on a random topic model with (K,D,T)=(32,512,128)(K,D,T)=(32,512,128). Initially, both In-Distribution (ID, on the DD training topics, blue) and Out-Of-Distribution (OOD, on a new topic p⋆p_\star, orange) descend with NN towards the entropy of the Bayes-optimal predictor (orange dotted): the add-one estimator rt(a∣X≤t)=(#{i≤t∣Xi=a}+1)/(t+K)r_t(a \mid X_{\leq t})=(\#\{i\leq t\mid X_i=a\}+1)/(t+K). Later, the predictor specialises to the training topics: the ID loss converges to the ID Bayes-optimal floor (blue dotted), while the OOD loss rises as in overfitting. Code: https://github.com/fr acagnetta/random-topic-model.

  • A solvable model of strategy competition. We characterise analytically two distinct Bayes-optimal predictors: a specialised one, relying on knowledge of the DD topics in the data-generating process, and an in-context one, equivalent to the add-one estimator from statistics under our data model (§ 2).

  • A first-principles learning-curve theory for specialisation. We derive the specialisation learning curve in a Bayesian learning setting: the excess loss over the asymptotic floor is DK/(2NT)DK/(2NT) at leading order—a function of the number of training tokens per parameter of the data-generating process (§ 3).

  • A statistical mechanism for the in-context phase. The in-context predictor is linear in the token counts, and a learner that estimates this map from data acquires it at a sample complexity set by its K2K^2 parameters and by the information that a context carries about the next token: both independent of DD. Hence, comparison with the specialisation scale gives a task-diversity threshold above which (see Figure 1) the in-context solution emerges first, it remains stable in a window that widens with task diversity, then it gives way to the specialised solution (Sec. 4).

  • Parameter-free agreement with trained transformers. Across vocabularies, task diversities, sequence lengths and corpus sizes, transformer in-distribution losses collapse as functions of NT/DKNT/DK, converging to the specialised solution at the predicted rate. Non-trivial ICL performance develops at the predicted, DD-independent sample complexity, then vanishes again with specialisation (§ 5).

  • Separation from classical spectral methods. Reconstructing the topics from low-order moments [21, 3] requires resolving a Marchenko–Pastur bulk of eigenvalues, which takes N∼D2KN \sim D^2K samples: a worse scaling with task diversity than the Bayes-optimal NT∼DKNT \sim DK followed by trained transformers (§ 5.1).

Related work

Mixtures of tasks as ICL testbeds. Finite task mixtures underlie most theoretical studies of ICL: linear regression ([17, 1, 29, 24, 40, 8, 23]), classification ([31, 25]), and mixtures of Markov ([15, 28, 7, 18]) and hidden Markov ([32, 30]) models. The “Balls & Urns” setting of Wurgaft et al. [37] is precisely the random topic model studied here, and their memorising and generalising predictors are our specialised and in-context ones. Our work complements their phenomenological Bayesian framework: where they assume a scaling law and a low-Kolmogorov-complexity bias, we derive the sample complexities of the two predictors from first principles. Thus, our approach does not require estimating Kolmogorov complexities and fitting parameters, but rather prescribes a simple picture where the functional simplicity of the ICL solution promotes its emergence as long as it leads to a noticeable loss gain with fewer data.

Representations, Belief-state geometry and task vectors. Due to next-token pretraining, transformers linearly represent the belief state over latent structure ([33]). In particular, mixtures of independent components, or non-ergodic sources, give rise to a telescopic geometry, which sparsifies along the context ([30]). The random topic model is the simplest non-ergodic source, and our results predict the sample dependence of the resulting belief geometry. Beyond controlled data structures, ICL has been linked to task vectors encoding the inferred task ([20]), whose geometry distinguishes dual modes of task inference corresponding to our two predictors ([39]). Overall, these approaches describe how a trained network implements the chosen strategies; ours predicts when the data favours each.

Learning theories of ICL. Most analytical studies of learning focus on the infinite-data and infinite-diversity limit. Lu et al. [24] is closest to us: they solve linear attention trained on Gaussian regression in a proportional asymptotic limit, obtaining sharp learning curves and a genuine transition with increasing task diversity. However, since their linear model cannot fit the specialised predictors exactly, they did not observe the crossover from in-context to specialised predictor as the number of data increases. Furthermore, our setup can be extended to mixtures of Markov chains ([18]) and generic hidden Markov models ([32]).

Data model and optimal predictors

This section introduces our synthetic model of mixture data and the two reference predictors representing the specialised and in-context solutions. The solutions are distinguished by their next-token-prediction loss profiles. As shown in Figure 2, trained transformers behave like the specialised predictor at low data diversity, while converging to the in-context one at high diversity. The rest of the paper explains why, and on which scale of the corpus size NN each solution is selected.

Next-token loss profiles of the two Bayes-optimal predictors and trained transformers

Figure 2. Next-token loss profiles of the two Bayes-optimal predictors and of trained transformers, for K=64K=64 and T=128T=128. Left: ID loss Lt[q]\mathcal{L}_t[\mathbf{q}] of the specialised predictor for DD from 32 to 8192 (colour), averaged over realisations of the topic matrix, and OOD loss Lt⋆[r]\mathcal{L}^{\star}_t[\mathbf{r}] of the in-context predictor (black dashed), which does not depend on DD. Dotted line: log⁡K\log K. Markers: context length at which each specialised profile has covered half of its descent, growing as log⁡D\log D (grey guide; § 2.1). Middle and right: the same two references at D=32D=32 and D=8192D=8192, with the ID (blue) and OOD (orange) loss profiles of a one-layer transformer trained on NN documents at that DD, mean ±\pm s.e. over four runs with independent topic matrix, corpus and initialisation, at the checkpoint of minimal validation loss. At D=32D=32 the transformer matches the specialised predictor in distribution and stays above log⁡K\log K out of distribution; at D=8192D=8192 both profiles follow the in-context predictor.

Random Topic Model A dataset is specified by a vocabulary size KK, a number of topics DD and a document length TT. Each topic is a probability distribution over the vocabulary, pz∈ΔK−1\boldsymbol{p}_z \in\Delta^{K-1} with entries pz(a)p_z(a) for a=1,…,Ka = 1,\ldots,K, drawn independently and uniformly from the simplex, pz∼Dir⁡K(1)\boldsymbol{p}_z \sim\operatorname{Dir}_K(1) for z=1,…,Dz = 1,\ldots,D, and then held fixed. We collect the topics as the columns of the topic matrix P=[p1,…,pD]∈RK×DP = [\boldsymbol{p}_1,\ldots,\boldsymbol{p}_D] \in\mathbb{R}^{K \times D}. A document is generated by drawing a topic index ZZ uniformly from {1,…,D}\{1,\ldots,D\}. It then tokens X1,…,XT∈{1,…,K}X_1,\ldots,X_T \in\{1,\ldots,K\} independently from pZp_Z (Figure 1, left). Given the topic, the likelihood of a context X≤t=(X1,…,Xt)X_{\le t} = (X_1,\ldots,X_t) depends only on its histogram, the count vector

C(X≤t)∈NK,Ca(X≤t):=#{s≤t:Xs=a}.(1)C(X_{\le t}) \in\mathbb{N}^{K}, \qquad C_a(X_{\le t}) := \#\{s \le t : X_s = a\}. \tag*{(1)}

The training corpus consists of NN documents, all generated with the same topic matrix PP.

Data versus topic distribution. Two kinds of averages appear throughout. E[⋅]\mathbb{E}[\cdot] denotes the expectation over documents at fixed topic matrix PP, i.e. over the topic index ZZ and the tokens: this is the average that defines the loss of any predictor, including a trained transformer. x‾\overline{\phantom{x}} denotes the further average over the draw of the topics. Unless stated otherwise, the curves in the figures are averaged over independent realisations of the topic matrix PP.

Next-token prediction, In- and Out-Of-Distribution. We consider two test distributions. In-distribution (ID) documents are generated as the training ones, from one of the DD topics of PP. Out-of-distribution (OOD) documents are generated from a fresh topic p⋆∼Dir⁡K(1)\mathbf{p}_{\star} \sim\operatorname{Dir}_{K}(1), drawn from the same prior as the training topics but independently, and hence almost surely different from all of them. A next-token predictor ff maps each context X≤tX_{\leq t} to a distribution ft(X≤t)∈ΔK−1f_t(X_{\leq t}) \in\Delta^{K-1} over Xt+1X_{t+1}. We measure ID performance by the next-token loss at context length tt, or tt-gram entropy

Lt[f]:=E[−log⁡ft(Xt+1∣X≤t)],t=0,…,T−1,(2)\mathcal{L}_t[f] := \mathbb{E}\left[-\log f_t(X_{t+1} \mid X_{\leq t})\right], \qquad t = 0,\ldots,T-1, \tag*{(2)}

where the expectation is over fresh documents generated from the DD training topics. The same expectation over a fresh topic p⋆\mathbf{p}_{\star} defines the OOD loss Lt⋆[f]\mathcal{L}^{\star}_t[f]. The usual autoregressive loss LAR\mathcal{L}_{\mathrm{AR}} is the average of Lt\mathcal{L}_t over positions.

The specialised predictor

A learner that knows the topic matrix PP still does not observe the topic ZZ of a given document, and must infer it from the context. The Bayes-optimal next-token distribution is the posterior mixture of the topics,

qt(X≤t):=∑z=1Dγt(z) pz,γt(z):=P(Z=z∣X≤t)=∏a=1Kpz(a)Ca∑y=1D∏a=1Kpy(a)Ca,(3)q_t(X_{\leq t}) := \sum_{z=1}^{D} \gamma_t(z)\,\mathbf{p}_z,\qquad\gamma_t(z) := \mathbb{P}(Z=z \mid X_{\leq t}) = \frac{\prod_{a=1}^{K}p_z(a)^{C_a}}{\sum_{y=1}^{D}\prod_{a=1}^{K}p_y(a)^{C_a}}, \tag*{(3)}

where the posterior over the topic γt(z)\gamma_t(z) depends on the context only through the counts. qtq_t is the true conditional distribution of Xt+1X_{t+1} given the context, hence it minimises Lt\mathcal{L}_t over all predictors (App. B). We call it specialised, as it is built from the DD topics realised in training.

The cross-entropy loss splits into an entropy plus a Kullback–Leibler divergence,

Lt[q]=1D∑z=1DH(pz)+E[DKL(pZ∥qt)],(4)\mathcal{L}_t[\mathbf{q}] = \frac{1}{D}\sum_{z=1}^{D} H(\mathbf{p}_z) + \mathbb{E}\left[D_{\mathrm{KL}}(\mathbf{p}_Z \mathbin{\|} \mathbf{q}_t)\right], \tag*{(4)}

both averaged over the unknown topic. The first term is the loss of an oracle that observes the topic, and no predictor can go below it: it is the entropy rate of the data-generating process. For sufficiently large DD, the entropy rate converges to the average over draws of the topic matrix H(p)H(\mathbf{p}), which is log⁡K−1+γE+O(1/K)\log K - 1 + \gamma_{\mathrm{E}} + O(1/K) for large KK (App. A), with γE≃0.57721\gamma_{\mathrm{E}} \simeq0.57721 Euler’s constant. The second term is the excess loss due to the uncertainty on the topic and, by Eq. (3), it is controlled by the posterior mass on the wrong topics y≠zy \ne z. As shown in App. B, the mass on a wrong topic yy decays exponentially in tt, at a rate given by the divergence DKL(pz∥py)D_{\mathrm{KL}}(\mathbf{p}_z \mathbin{\|} \mathbf{p}_y). For random topics this divergence is of order one (App. A), so that discriminating the true topic from the other D−1D-1 requires a context of length t∼log⁡Dt \sim\log D (App. B). This scale is visible in the left panel of Figure 2.

The in-context predictor

Consider now an OOD document, generated from a new topic p⋆\mathbf{p}_{\star} that does not belong to the topic matrix PP. A learner that knows the prior Dir⁡K(1)\operatorname{Dir}_{K}(1) but not p⋆\mathbf{p}_{\star} must infer from the context the topic itself, rather than its index within the topic dictionary. By Dirichlet categorical conjugacy, the posterior over p⋆\mathbf{p}_{\star} given X≤tX_{\leq t} is Dir⁡K(C1+1,…,CK+1)\operatorname{Dir}_{K}(C_1+1,\ldots,C_K+1), and the Bayes-optimal next-token distribution is its mean, the add-one smoothing of the histogram (App. C)

rt(a∣X≤t):=P(Xt+1=a∣X≤t)=Ca(X≤t)+1t+K.(5)r_t(a \mid X_{\leq t}) := \mathbb{P}(X_{t+1}=a \mid X_{\leq t}) = \frac{C_a(X_{\leq t})+1}{t+K}. \tag*{(5)}

We call it in-context as it does not depend on the topic matrix PP, and thus applies unchanged to documents from seen or unseen topics.

The OOD loss of rtr_t decomposes as in Eq. (4), with the unseen topic in place of pZ\mathbf{p}_Z,

Lt⋆[r]=H(p)‾+E[DKL(p⋆∥rt)]=H(p)‾+K−12t+O(log⁡tt2),(6)\mathcal{L}^{\star}_t[\mathbf{r}] = \overline{H(\mathbf{p})} + \mathbb{E}\left[D_{\mathrm{KL}}(\mathbf{p}_{\star} \mathbin{\|} \mathbf{r}_t)\right] = \overline{H(\mathbf{p})} + \frac{K-1}{2t} + O\left(\frac{\log t}{t^2}\right), \tag*{(6)}

where the expansion holds at fixed KK for t≫Kt \gg K (App. C). Simply put, the histogram needs to include at least order KK tokens to depart from a trivial prediction 1/K1/K. Note that, since p⋆\mathbf{p}_{\star} is drawn from the same prior as the topics of PP, the entropy floor is the same for the two predictors, while the approach is significantly different (see Figure 2, left). Identifying one of DD known topics requires log⁡D\log D nats of evidence, which the context delivers at a constant rate per token, hence the exponential convergence of § 2.1. Estimating a new topic is instead a (K−1)(K-1)-dimensional problem, and the excess in Eq. (6) is the classical half of the number of parameters per observation behaviour.

Learning-curve theory of specialisation

The training corpus contains only the DD topics in the matrix PP. Hence, a sufficiently expressive, well-optimised machine learning model must converge to the specialised solution Eq. (3) in the infinite-data and training time limit. But how many training documents does it take to specialise?

Bayesian learning We answer this question with a Bayesian learner that uses the training corpus optimally: It knows the model class, including DD and KK, but not the realised topic matrix PP, and observes a collection CN\mathcal{C}_N of NN length-TT training documents, together with the test context. The training corpus informs a posterior π(dP∣CN)\pi(dP\mid\mathcal{C}_N) over the topic matrix PP, proportional, by Bayes’ rule, to prior μ(dP)\mu(dP) times the joint probability of the corpus under PP, P{CN}\mathbb{P}\{\mathcal{C}_N\}. The Bayes-optimal learner is the posterior mean of the PP-dependent specialised predictor from Eq. (3),

q^t(X≤t)∝∫qt(X≤t;P) π(dP∣CN,X≤t),(7)\hat{\mathbf{q}}_t(X_{\leq t}) \propto\int\mathbf{q}_t(X_{\leq t};P)\,\pi(dP\mid\mathcal{C}_N,X_{\leq t}), \tag*{(7)}

where the posterior also includes the test context X≤tX_{\leq t} (see App. § 12 for details). Note that, after averaging over the draw of the topics, no predictor built from the same data has a lower loss than q^\hat{\mathbf{q}}. Its loss is the statistical limit of specialisation from NN training documents, hence a natural reference against which a transformer trained on the same corpus can be measured.

Learning curve and mutual information. The learning curve of specialisation is the excess loss of the Bayes-optimal learner over the specialised predictor, averaged over topic matrices,

εt(N):=Lt[q^]−Lt[q],(8)\varepsilon_t(N) := \mathcal{L}_t[\hat{\mathbf{q}}]-\mathcal{L}_t[\mathbf{q}], \tag*{(8)}

Averaging over the topics gives it an information-theoretic meaning: εt(N)\varepsilon_t(N) is the conditional mutual information between PP and the next token, given corpus and context (App. § 12),

εt(N)=I(P;Xt+1∣X≤t,CN)⇒∑t=0T−1εt(N)=I(P;CN+1)−I(P;CN),(9)\varepsilon_t(N)=I(P;X_{t+1}\mid X_{\leq t},\mathcal{C}_N)\Rightarrow\sum_{t=0}^{T-1}\varepsilon_t(N)=I(P;\mathcal{C}_{N+1})-I(P;\mathcal{C}_N), \tag*{(9)}

where CN+1C_{N+1} adds the test document to the corpus. The excess loss of the learner on the test document equals the information that this document adds about the topic matrix. Thus, the learning curve quantifies how fast the corpus reveals PP.

The DK/NTDK/NT law. The topic matrix has D(K−1)D(K-1) free parameters, and a corpus of NN documents reveals them at the rate of parametric statistics: under identifiability and regularity, I(P;CN)=(D(K−1)/2)log⁡N+O(1)I(P; C_N) = (D(K-1)/2)\log N + O(1) ([13, 14]). The increment gives the leading term of the learning curve at fixed DD and KK (App. § 12),

1T∑t=0T−1ϵt(N)=D(K−1)2NT+o(N−1).(10)\frac{1}{T}\sum_{t=0}^{T-1}\epsilon_t(N)=\frac{D(K-1)}{2NT}+o(N^{-1}). \tag*{(10)}

Specialisation thus requires NT≫DKNT \gg DK, and the learning curve is a function of the number of training tokens per parameter, x:=NT/(DK)x := NT/(DK), decaying as x−1x^{-1}. As shown in § 5, trained transformers specialise on the same sample-complexity scale, and with the same decay. Two remarks. First, identifiability, i.e. that the law of a document determines PP up to a relabelling of the topics, requires a sufficiently long document and a generic topic matrix. For D≤KD \le K, T≥3T \ge3 suffices: the columns of PP are linearly independent almost surely under the topics draw, and the third-order moment of the tokens has a unique decomposition with the topics as factors ([22, 3]). For larger DD the same holds for the lifted topics pz⊗m\mathbf{p}_z^{\otimes m}, which are generic in the same sense, i.e. linearly independent, as long as D≤(K+m−1m)D \le\binom{K+m-1}{m}, the dimension of the space of symmetric tensors, at the price of longer documents, T≥2m+1T \ge2m+1 (App. § 12). For instance, pairs of tokens cover K<D≤K(K+1)/2K < D \le K(K+1)/2 with T≥5T \ge5. Secondly, the learning curve is an average over topic matrices, whereas an experiment runs on individual realisations. Comparing the two assumes that the excess loss of a given realisation is close to its average, i.e. typicality of the random topic matrix. An empirical check of this typicality is the spread across independent realisations in § 5.

The same law at fixed, large position. (10) concerns the loss averaged over positions; at a fixed position tt the same law follows from a simple picture. Beyond the resolution scale log⁡D\log D of § 2.1, the learner can identify the topic of the test document, and likewise the topics of the training documents if T≫log⁡DT \gg\log D. It is then left with estimating the token distribution of the test topic from the training documents of that topic, about N/DN/D of them, i.e. from m≈NT/Dm \approx NT/D tokens: this is the problem solved by the in-context predictor of § 2.2, with mm in place of tt, whose excess (K−1)/(2m)(K-1)/(2m) becomes D(K−1)/(2NT)D(K-1)/(2NT). The tt-gram loss at large tt therefore obeys the same law as the average, and App. § 12 makes this rigorous at fixed PP, under conditions on tt, TT and NN; Figure 10 compares it with the TT-gram learning curves of trained transformers.

Three-panel plots of scaled T-gram loss versus number of training sequences and rescaled training tokens

Figure 10. Transformers match the Bayes-optimal specialisation learning curve at the longest context too. TT-gram counterpart of Figure 3, for the same twelve (K,D)(K,D) at T=128T=128. Left: Scaled ID TT-gram loss (LT(N)−LT(∞))/(log⁡K−LT(∞))(\mathcal{L}_T(N)-\mathcal{L}_T(\infty))/(\log K-\mathcal{L}_T(\infty)) versus number of training sequences, where LT(∞)\mathcal{L}_T(\infty) is the mean entropy 1D∑zH(pz)\frac{1}{D}\sum_z H(p_z) of the topics of each run, the large-context floor of the specialised predictor. Middle: Rescaling the xx-axis as the number of tokens per parameter of the data-generating process collapses all the curves onto a single functional form, more tightly than for the autoregressive loss. Right: The decay towards 00 (black dashed) follows the x−1x^{-1} rate of the Bayes-optimal learning curve.

When does ICL emerge?

Simplicity of the in-context predictor. If any learner eventually converges to the specialised predictor, when does ICL emerge? Both predictors of § 2 are functions of the counts, but of very different complexity. The in-context predictor is linear up to normalisation,

rt(X≤t)∝C(X≤t)+1,(11)r_t(X_{\le t}) \propto C(X_{\le t})+1, \tag*{(11)}

whereas the specialised predictor is exponential in the counts (Eq. (3)). Then, simplicity bias suggests that the in-context predictor is easier to learn. rtr_t represents a point in the family of K2K^2 linear maps from counts to next-token probability, whereas random topic models PP lie in D(K−1)D(K-1) dimensions. The estimation error follows from the same argument as § 3, in the form appropriate to a fitted parametric family rather than a Bayesian posterior (App. § 13). Simply put, a learner estimating the K2K^2 parameters of the linear map from a corpus of NTNT tokens pays an excess K2/(2NT)K^2/(2NT) over the optimal in-context solution, again proportional to the number of parameters per training token.

Estimation penalty versus loss gain. This excess must be compared with the gain of the add-one rule over the uniform predictor, equal to the mean mutual information between the next token and its context (App. § 13),

G(K,T):=log⁡K−1T∑t<TLt⋆[r]=1T∑t=0T−1I(Xt+1;X≤t).(12)G(K,T) := \log K-\frac{1}{T}\sum_{t<T}\mathcal{L}_t^\star[r]=\frac{1}{T}\sum_{t=0}^{T-1}I(X_{t+1};X_{\le t}). \tag*{(12)}

The new solution can only appear once the error due to finite data K2/(2NT)K^2/(2NT) is smaller than the gain, i.e. for

N≳Nicl:=K22T G(K,T),(13)N \gtrsim N_{\mathrm{icl}} := \frac{K^2}{2T\,G(K,T)}, \tag*{(13)}

independently of the task diversity DD.

Task-diversity threshold. By Eq. (10), the specialised solution emerges at Nspec=DK/TN_{\mathrm{spec}}=DK/T. Hence, if

D≫K2G(K,T),(14)D \gg\frac{K}{2G(K,T)}, \tag*{(14)}

then the in-context solution emerges before the specialised one, and persists in the window (Nicl,Nspec)(N_{\mathrm{icl}},N_{\mathrm{spec}}). The resulting picture is that of Figure 1, right. In the (Nicl,Nspec)(N_{\mathrm{icl}},N_{\mathrm{spec}}) window the learner applies the same rule to seen and unseen topics alike, thus OOD and ID loss decay together towards the OOD optimum Lt⋆[r]\mathcal{L}^{\star}_{t}[\mathbf{r}]. At NspecN_{\mathrm{spec}}, the learner resolves the dictionary: the ID loss descends to the entropy rate, and the OOD loss rises towards Lt⋆[q]\mathcal{L}^{\star}_{t}[\mathbf{q}]—OOD loss of the specialised predictor.

Transformer experiments

This section collects empirical learning curves of one-block transformers trained with Adam on data generated from random topic models of varying KK and DD. Experiments with varying TT are reported in App. H. Since we are testing the scaling of performance with the number of training tokens, we conducted extensive hyperparameter search, looking for the best configuration of model size, learning rate, batch size and training time at fixed depth and optimiser. Further details of architectures and training algorithms are reported in App. G.

Figure 3 shows that transformers learn random topic models at the same rate as the Bayesian learner of Sec. 3.

Three-panel learning curves for transformer experiments

Figure 3. Transformers match the Bayes-optimal specialisation learning curve. Left: Scaled ID autoregressive loss (LAR(N)−LAR(∞))/(log⁡K−LAR(∞))(\mathcal{L}_{\mathrm{AR}}(N)-\mathcal{L}_{\mathrm{AR}}(\infty))/(\log K-\mathcal{L}_{\mathrm{AR}}(\infty)) versus number of training sequences for one-block transformers trained on random topic model data with varying (K,D)(K,D), T=128T=128. The scaled loss is 1 at the uniform predictor 1/K1/K, 0 at the specialised predictor. Middle: Rescaling the xx-axis as the number of tokens per parameter of the data-generating process collapses all the curves onto a single functional form. Right: The decay towards 0 (black dashed) shows remarkable agreement with the x−1x^{-1} rate of the Bayes-optimal learning curve.

Even above the task-diversity threshold Eq. (14), specialisation kicks in as soon as the number of tokens NTNT surpasses the number of parameters DKDK. This is clearly shown by Figure 4: the large-NN decay of the ID loss scales with (NT/(DK))(NT/(DK)), while the early-NN decay develops a DD-independent behaviour. Correspondingly, the OOD losses at early stopping (dashed lines) show an initial descent, followed by a steep ascent around N∼(DK)/TN\sim(DK)/T. This result shows that the transience of ICL is inevitable, unless the learning model is regularised.

Scaled ID and OOD autoregressive losses for varying model dimensions and rescaled training-set size

Figure 4. In-context learning gives way to specialisation at the parametric scale NT∼DKNT \sim DK. Left: Scaled ID (solid) and OOD (dashed) autoregressive losses, both subtracting the ID loss floor for comparison. Right: Rescaling the xx-axis as the number of tokens per parameter of the data-generating process collapses both the descent of ID losses and the ascent of OOD losses.

Figure 5 shows OOD learning curves in the high-diversity regime: the initial DD-independent descent scales like K2/G(K,T)K^2/G(K,T) as predicted in Eq. (13). Since specialisation occurs at NT∼DKNT\sim DK, the in-context solution remains stable for a window of training set sizes linear in DD. Figure 11 of App. § 17 shows the same scaling behaviour for the initial decay of ID learning curves.

Empirical OOD learning curves for varying topic-model and transformer parameters

Figure 5. Empirical OOD learning curves decay at the predicted sample scale. Left: Scaled OOD autoregressive loss (LAR⋆(N)−LAR⋆(∞))/(log⁡K−LAR⋆(∞))(L_{\mathrm{AR}}^{\star}(N)-L_{\mathrm{AR}}^{\star}(\infty))/(\log K-L_{\mathrm{AR}}^{\star}(\infty)) versus number of training tokens NTNT for one-block transformers trained on random topic model data with varying (K,D)(K,D) at T=128T=128 (solid), and with K=64K=64, D=1024D=1024 at T=64T=64 (dotted) and T=256T=256 (dashed). These losses are not recorded at early stopping (training step with the lowest ID validation loss), but at the training step with the lowest OOD validation loss. Hence, the OOD losses shown in this figure do not rise at N∼DK/TN \sim DK/T as in Figure 4. Right: The early-NN departure from the trivial loss log⁡K\log K does not depend on DD and collapse after dividing the number of training sequences by K2/G(K,T)K^2/G(K,T), in perfect agreement with the theory of Eq. (13).

Two-panel plots of ID autoregressive loss versus training tokens and rescaled sample count

Figure 11. The ID loss descends to the in-context level at the predicted sample scale. Left: ID autoregressive loss at early stopping, scaled as (LAR(N)−LAR⋆[r])/(log⁡K−LAR⋆[r])(\mathcal{L}_{\mathrm{AR}}(N)-\mathcal{L}^{\star}_{\mathrm{AR}}[r])/(\log K-\mathcal{L}^{\star}_{\mathrm{AR}}[r]), where LAR⋆[r]=log⁡K−G(K,T)\mathcal{L}^{\star}_{\mathrm{AR}}[r]=\log K-G(K,T) is the autoregressive loss of the in-context predictor, the same on ID and OOD documents (App. § 11). This scaled loss is 1 at the uniform prediction, 0 at the in-context solution, and negative at specialisation. Versus number of training tokens NTNT, for the (K,D)(K,D) and TT of Figure 5, with the same line styles. Right: When plotted against NTG(K,T)/K2=N/(2Nicl)NTG(K,T)/K^2=N/(2N_{\mathrm{icl}}) (Eq. (13)) the descents to the in-context level coincide for all KK, DD and TT, with no adjustable constant. The subsequent departure below zero is specialisation.

Comparison with spectral baselines

Latent-variable models like the random topic model are classically learnt by spectral methods based on the moments of the tokens ([21, 5, 3]). The first step is recovery of the DD-dimensional subspace spanned by the topics from a low-order moment: the pair moment M2=1D∑zpzpzTM_2 = \frac{1}{D}\sum_z p_zp_z^{\mathsf{T}}, of rank DD, when D≤KD \le K, and the moment of 2m2m tokens when D≤(K+m−1m)D \le\binom{K+m-1}{m}, the number of independent products of mm topic entries. The topics themselves then follow from the moment with one more token, which is the identifiability step of § 3 (App. § 14). The subspace is resolved once the empirical moment, estimated from NN independent 2m2m-tuples, is close to the population moment. The corresponding sample size is a lower bound for the method to work.

The error on the empirical moment is of order (KmN)−1/2(K^{m}N)^{-1/2} by the matrix Bernstein inequality (App. § 14, verified numerically in Figure 8). The scales of the population moments, instead, follow from random matrix theory, in the limit D,K→∞D, K \to\infty. With D/K=α<1D/K = \alpha< 1 and m=1m = 1, the bulk of M2M_2’s spectrum converges to a Marchenko–Pastur distribution with eigenvalues of order 1/(DK)1/(DK) (Figure 6). Comparison with the noise gives N≳D2KN \gtrsim D^2K. With D/(K(K+1)/2)=β<1D/(K(K + 1)/2) = \beta< 1 and m=2m = 2, the relevant bulk of M4M_4 is of order 1/(DK2)1/(DK^2) (Figure 7). Comparison with the noise gives N≳D2K2N \gtrsim D^2K^2. This analysis is carried out in a different limit from the rest of the paper, and it counts independent tuples rather than documents of TT tokens, so we only compare the dependence on task diversity: quadratic in DD for the spectral baseline, against the linear NT∼DKNT \sim DK of the Bayes-optimal learner, which the trained transformers follow. Furthermore, in the spectral baseline, the order of KK grows with the order of the required moment.

Population spectrum of $M_2$

Figure 6. Population spectrum of M2M_2 for D≤KD \le K. Left: ranked eigenvalues λrDK\lambda_r DK against the scaled rank r/Dr/D at α=D/K=1/2\alpha= D/K = 1/2, for K∈{256,512,1024,2048}K \in\{256, 512, 1024, 2048\} and one topic realisation per (K,D)(K,D); dashed: the ranked Marchenko–Pastur law; the spike is the outlier at λ1DK≈D\lambda_1 DK \approx D. Right: density of the bulk eigenvalues, spike removed, on the λDK\lambda DK scale, against the Marchenko–Pastur density (dashed).

Population spectrum of $M_4$

Figure 7. Population spectrum of M4M_4 for K<D≤K(K+1)/2K < D \le K(K+1)/2. Left: ranked eigenvalues of M4M_4 for one realisation at K=192K = 192, D=K(K+1)/4=9264D = K(K+1)/4 = 9264: the spike at K−2K^{-2} (dotted), the K−1K-1 eigenvalues of the linear block and, beyond r=Kr = K (dotted), the D−KD-K eigenvalues of the quadratic block, against the Marchenko–Pastur predictions of the two blocks (dashed). Right: Frobenius norm of each block against KK, for D=K(K+1)/4D = K(K+1)/4, with the parameter-free predictions (dashed).

Convergence of the empirical pair moment for $D \le K$

Figure 8. Convergence of the empirical pair moment for D≤KD \le K. Left: operator-norm error ∥M^2−M2∥op\lVert\widehat{M}_2-M_2\rVert_{\mathrm{op}}, geometric mean over eight replicas, against NKNK for eleven (K,D)(K,D) configurations, α=D/K∈{1/4,1/2,3/4}\alpha=D/K\in\{1/4,1/2,3/4\} times K∈{128,256,512}K\in\{128,256,512\} plus K=256K=256 with D∈{16,32,64,128,192}D\in\{16,32,64,128,192\}; colour encodes KK, line style α\alpha; all curves collapse on the dotted 1.5/NK1.5/\sqrt{NK}; circles mark where each curve crosses its own population λD\lambda_D, beyond which the lower bulk edge is resolved. Right: overlap 1D−1∥U2:DTU^2:D∥F2\frac{1}{D-1}\lVert U_{2:D}^{\mathsf T}\widehat{U}_{2:D}\rVert_F^2 between the bulk eigenvector subspaces of M2M_2 and M^2\widehat{M}_2, mean ±\pm one standard deviation over replicas, against N/(D2K)N/(D^2K); each curve rises from the random-subspace value (D−1)/(K−1)(D-1)/(K-1) towards one around N/(D2K)=O(1)N/(D^2K)=O(1) (dashed line at one). One topic realisation per (K,D)(K,D), uniform topic prior.

Conclusions

We have studied a solvable model of a mixture of DD topics, where two strategies compete: in-distribution specialisation to the finite mixture, or out-of-distribution generalisation to topics never seen in training. Specialisation requires more training tokens than there are parameters in the data-generating process—a statistical limit that no learner can beat. The in-context solution is available at a DD-independent scale, hence it comes first whenever the number of topics is large enough. Trained transformers follow both scales. It follows that the transience of ICL ([35]) is inevitable as the corpus grows, unless a constraint on parameters or training budget keeps the learner in the in-context window.

The specialised solution was called memorising in previous studies of the same competition ([29, 25, 11, 37]). Indeed, its placement after the in-context phase mirrors the training dynamics of diffusion models, where generalisation is acquired before the memorisation of the training set ([16]). We find the label misleading: the specialised predictor stores the DD topics of the population, not the NN documents of the corpus—memorisation happens in feature space. This is a form of in-distribution generalisation, distinct from the adaptation to new topics of the in-context predictor, and we name it after the specialisation of teacher-student networks, where the hidden units of the student align with those of the teacher ([19, 6]).

Several directions are open. The first is the training dynamics of transformers on the random topic model, which would connect our sample complexities with the phenomenological description of Wurgaft et al. [37]. More importantly, the dynamics determine which representations are learned in each phase and the corresponding geometry of the residual stream ([33, 30]). Clarifying the distinction between representations in the two phases could help understand the emergence and role of task vectors ([20]), including scenarios where multiple solutions coexist ([39]). The second is the competition between task diversity and other structures of the data. The tools developed here can address this problem in general non-ergodic hidden Markov models ([32]), of which the random topic model is the simplest instance. Such mixtures are natural models of large heterogeneous corpora. Solvable models like the one proposed here could help understand how heterogeneity contributes to data statistics and scaling laws ([10]), and how improvements on the individual components of a mixture interact.

AI Use Statement

In this work, we used generative AI tools for: assistance in the writing of proofs; implementation of numerical methods. We have not used generative AI tools for: Generating synthetic data sets, helping develop theoretical models or conceptual frameworks, formulating mathematical claims, providing critical ingredients for proving mathematical claims, proposing or refining hypotheses, designing feedback on research methodology or experiments, interpreting results, and assisting with translation, cleaning and reformatting dataset, supporting qualitative and thematic data analysis are not applicable to this work. Additionally, we used generative AI tools for: modifying scientific figures, drafting parts of a research paper, identifying relevant literature. We have reviewed all AI-assisted work. We checked LLM-generated proofs; LLM-generated numerical implementations were verified and tested for correctness by 2 authors; We checked LLM-generated descriptions of additional related works. We take responsibility for the final content of this work, including text, claims or artifacts produced with the aid of generative AI.

Reproducibility Statement

The theoretical results are stated with their assumptions and proved in the appendices. Appendices § 9–§ 11 prove the statements of § 2: the averages over the topic prior, the optimality and loss decomposition of the two predictors, and the exact finite-tt loss of the in-context predictor, Eq. (28), from which the in-context reference, the gain G(K,T)G(K,T) and the sample scale NiclN_{\mathrm{icl}} used to rescale the axes of the figures are computed. App. § 12 states the identifiability and regularity assumptions behind the DK/NTDK/NT law, Eq. (10), gives sufficient conditions on (D,K,T)(D,K,T) under which they hold almost surely, proves the law and gives its fixed-position version. App. § 13 lists the conditions under which the estimation excess of a fitted family equals its parameter count, behind Eq. (13), and App. § 14 states the joint limit in which the spectral scales hold. Arguments that we do not prove are identified as such where they appear: the concentration of pairwise divergences behind the log DD constant, the signal-to-noise criterion and the block approximation of the spectral baseline, and the applicability of the estimation argument to a trained transformer.

The experiments are fully specified in App. § 16: the data-generating process, with the topic prior, the sizes of the validation and OOD sets and the number of fresh OOD topics; the architecture, initialisation and parameter count; the optimiser, learning-rate schedule and batching; the evaluation protocol, the definition of early stopping and the two readings of the OOD loss; and the hyperparameter grid with the selection rule. Every point of a learning curve is the mean over four runs with independent topic matrix, corpus and initialisation, with standard errors as error bars, and every run stores its full configuration, including the seeds of the draws, so that any point can be regenerated exactly. The theoretical references in the figures are evaluated from closed-form expressions or by Monte Carlo estimates over topic realisations, as stated in the captions. The code for data generation, training, evaluation and the theoretical curves is available at https://github.com/fracagnetta/random-topic-model.

Statistics over random topic models

This appendix collects the averages over the topic prior used in the main text. Let p,p′∼Dir⁡K(1)\mathbf{p},\mathbf{p}' \sim\operatorname{Dir}_{K}(1) be independent, i.e. uniform on the simplex ΔK−1\Delta^{K-1}, and let ψ=Γ′/Γ\psi=\Gamma'/\Gamma denote the digamma function. Each entry is marginally pa∼Beta⁡(1,K−1)p_a \sim\operatorname{Beta}(1,K-1), with moments

par‾=Γ(K)Γ(r+1)Γ(K+r),log⁡pa‾=ψ(1)−ψ(K),palog⁡pa‾=1K[ψ(2)−ψ(K+1)],(15)\overline{p_a^r}=\frac{\Gamma(K)\Gamma(r+1)}{\Gamma(K+r)}, \qquad\overline{\log p_a}=\psi(1)-\psi(K), \qquad\overline{p_a\log p_a}=\frac{1}{K}\left[\psi(2)-\psi(K+1)\right], \tag*{(15)}

where the last two follow by differentiating the first with respect to rr at r=0r=0 and r=1r=1.

Entropy of a topic. By symmetry of the entries,

H(p)‾=−Kpalog⁡pa‾=ψ(K+1)−ψ(2)=log⁡K−1+γE+12K+O(K−2),(16)\overline{H(\mathbf{p})}=-K\overline{p_a\log p_a}=\psi(K+1)-\psi(2)=\log K-1+\gamma_{\mathrm{E}}+\frac{1}{2K}+O(K^{-2}), \tag*{(16)}

using ψ(2)=1−γE\psi(2)=1-\gamma_{\mathrm{E}} and ψ(K+1)=log⁡K+1/(2K)+O(K−2)\psi(K+1)=\log K+1/(2K)+O(K^{-2}). A random topic thus has entropy 1−γE−1/(2K)≈0.421-\gamma_{\mathrm{E}}-1/(2K)\approx0.42 nats below the uniform value log⁡K\log K, at leading orders: this gap is the height of the descent of every profile in Figure 2.

Divergence between two topics. Expanding the divergence and using the independence of p\mathbf{p} and p′\mathbf{p}',

DKL(p∥p′)‾=Kpalog⁡pa‾−Kpalog⁡pa′‾=[ψ(2)−ψ(K+1)]−[ψ(1)−ψ(K)]=1−1K,(17)\overline{D_{\mathrm{KL}}(\mathbf{p}\Vert\mathbf{p}')}=K\overline{p_a\log p_a}-K\overline{p_a\log p'_a}=[\psi(2)-\psi(K+1)]-[\psi(1)-\psi(K)]=1-\frac{1}{K}, \tag*{(17)}

by the recurrence ψ(x+1)=ψ(x)+1/x\psi(x+1)=\psi(x)+1/x. Two random topics are thus separated by an order-one divergence for every vocabulary size, which sets the rate of topic resolution in App. B.

Bhattacharyya coefficient. The non-asymptotic resolution bound of App. B involves ρ(p,p′):=∑apapa′\rho(\mathbf{p},\mathbf{p}'):=\sum_a\sqrt{p_ap'_a}, whose average follows from Eq. (15) at r=1/2r=1/2,

ρ(p,p′)‾=K(pa‾)2=πK4[Γ(K)Γ(K+12)]2=π4(1+14K+O(K−2)).(18)\overline{\rho(\mathbf{p},\mathbf{p}')}=K\left(\overline{\sqrt{p_a}}\right)^2=\frac{\pi K}{4}\left[\frac{\Gamma(K)}{\Gamma\left(K+\frac{1}{2}\right)}\right]^2=\frac{\pi}{4}\left(1+\frac{1}{4K}+O(K^{-2})\right). \tag*{(18)}

The specialised predictor

This appendix proves the statements of § 2.1: the optimality of qtq_t, the loss decomposition Eq. (4), and the resolution of the topic on the context scale log⁡D\log D. Throughout, the topic matrix PP is fixed, with distinct columns, and all expectations are over documents at fixed PP.

Optimality. Conditional on the context, Xt+1X_{t+1} is distributed as qt(X≤t)q_t(X_{\leq t}): by construction qt(a∣X≤t)=∑zP(Z=z∣X≤t)P(Xt+1=a∣Z=z)q_t(a\mid X_{\leq t})=\sum_z\mathbb{P}(Z=z\mid X_{\leq t})\mathbb{P}(X_{t+1}=a\mid Z=z), using that Xt+1X_{t+1} is independent of the context given ZZ. For any predictor ff, therefore,

E[−log⁡ft(Xt+1∣X≤t)∣X≤t]=H(qt)+DKL(qt∥ft)≥H(qt),(19)\mathbb{E}\left[-\log f_t(X_{t+1}\mid X_{\leq t})\mid X_{\leq t}\right]=H(q_t)+D_{\mathrm{KL}}(q_t\Vert f_t)\geq H(q_t), \tag*{(19)}

with equality if and only if ft=qtf_t=q_t. Averaging over contexts, Lt[f]≥Lt[q]\mathcal{L}_t[f]\geq\mathcal{L}_t[q].

Loss decomposition. Conditioning instead on the topic and the context, Xt+1∼pZX_{t+1}\sim p_Z, and the same identity gives E[−log⁡qt(Xt+1∣X≤t)∣Z,X≤t]=H(pZ)+DKL(pZ∥qt)\mathbb{E}[-\log q_t(X_{t+1}\mid X_{\leq t})\mid Z,X_{\leq t}]=H(p_Z)+D_{\mathrm{KL}}(p_Z\Vert q_t); averaging over the topic, uniform on {1,…,D}\{1,\ldots,D\}, and over the context yields Eq. (4). The floor is the loss of the oracle ft=pZf_t=p_Z, which is not a function of the context and hence not a predictor in the sense of Eq. (2); by the optimality of qtq_t, every predictor pays at least the excess E[DKL(pZ∥qt)]\mathbb{E}[D_{\mathrm{KL}}(p_Z\Vert q_t)] above it.

Excess loss and wrong-topic mass. Write the posterior in terms of the likelihood ratios of the wrong topics against the true one,

Ry(t):=γt(y)γt(Z)=∏s=1tpy(Xs)pZ(Xs),γt(Z)=(1+∑y≠ZRy(t))−1.(20)R_y^{(t)}:=\frac{\gamma_t(y)}{\gamma_t(Z)}=\prod_{s=1}^{t}\frac{p_y(X_s)}{p_Z(X_s)}, \qquad\gamma_t(Z)=\left(1+\sum_{y\ne Z}R_y^{(t)}\right)^{-1}. \tag*{(20)}

Isolating the true topic in Eq. (3), qt=γt(Z) pZ+∑y≠Zγt(y) py≥γt(Z) pZq_t = \gamma_t(Z)\,p_Z + \sum_{y\ne Z}\gamma_t(y)\,p_y \ge\gamma_t(Z)\,p_Z entrywise, hence

DKL(pZ∥qt)≤∑a=1KpZ(a)log⁡pZ(a)γt(Z) pZ(a)=−log⁡γt(Z)=log⁡(1+∑y≠ZRy(t)).(21)D_{\mathrm{KL}}(p_Z\Vert q_t) \le\sum_{a=1}^{K} p_Z(a)\log\frac{p_Z(a)}{\gamma_t(Z)\,p_Z(a)}=-\log\gamma_t(Z)=\log\left(1+\sum_{y\ne Z}R_y^{(t)}\right). \tag*{(21)}

Conditional on ZZ, the tokens are i.i.d. from pZp_Z, so by the strong law of large numbers

1tlog⁡Ry(t)=1t∑s=1tlog⁡py(Xs)pZ(Xs)→t→∞a.s.−DKL(pZ∥py)<0,(22)\frac{1}{t}\log R_y^{(t)}=\frac{1}{t}\sum_{s=1}^{t}\log\frac{p_y(X_s)}{p_Z(X_s)}\xrightarrow[t\to\infty]{\mathrm{a.s.}}-D_{\mathrm{KL}}(p_Z\Vert p_y)<0, \tag*{(22)}

i.e. each wrong topic is suppressed exponentially in tt, at a rate equal to its divergence from the true topic. This is the mechanism described in the main text; it is asymptotic in tt at fixed PP.

Resolution on the scale log⁡D\log D. A bound valid at every tt follows from a fractional moment of the likelihood ratios. Using log⁡(1+∑yRy)≤∑ylog⁡(1+Ry)≤∑yRy\log(1+\sum_y R_y)\le\sum_y\log(1+R_y)\le\sum_y\sqrt{R_y} in Eq. (21), then the independence of the tokens given ZZ,

E[DKL(pZ∥qt)]≤E[−log⁡γt(Z)]≤1D∑z=1D∑y≠zE[Ry(t)∣Z=z]=1D∑z=1D∑y≠zρzyt≤(D−1)ρ⋆t.(23)\begin{aligned} \mathbb{E}\left[D_{\mathrm{KL}}(p_Z\Vert q_t)\right]\le\mathbb{E}\left[-\log\gamma_t(Z)\right]\le\frac{1}{D}\sum_{z=1}^{D}\sum_{y\ne z}\mathbb{E}\left[\sqrt{R_y^{(t)}}\mid Z=z\right] \\ &=\frac{1}{D}\sum_{z=1}^{D}\sum_{y\ne z}\rho_{zy}^{t}\le(D-1)\rho_\star^{t}. \tag*{(23)} \end{aligned}

where ρzy:=∑apz(a) py(a)\rho_{zy}:=\sum_a\sqrt{p_z(a)\,p_y(a)} is the Bhattacharyya coefficient of topics zz and yy, and ρ⋆:=max⁡z≠yρzy<1\rho_\star:=\max_{z\ne y}\rho_{zy}<1 by the Cauchy–Schwarz inequality and the distinctness of the topics. Hence the excess loss of the specialised predictor is below any ϵ>0\epsilon>0 as soon as

t≥log⁡[(D−1)/ϵ]log⁡(1/ρ⋆),(24)t\ge\frac{\log\left[(D-1)/\epsilon\right]}{\log(1/\rho_\star)}, \tag*{(24)}

which is the log⁡D\log D scale of § 2.1, with a rate set by the closest pair of topics. The guaranteed rate log⁡(1/ρzy)\log(1/\rho_{zy}) is at most half of the almost-sure rate in Eq. (22), since log⁡ρzy≥−12DKL(pz∥py)\log\rho_{zy}\ge-\frac{1}{2}D_{\mathrm{KL}}(p_z\Vert p_y) by Jensen’s inequality, and ρ⋆\rho_\star grows with DD as the closest pair among DD random topics gets closer: Eq. (24) is a statement about the dependence on tt at fixed PP, not a sharp constant. For the constant, the typical pair is the relevant one: two random topics have D‾KL(p∥p′)=1−1/K\overline{D}_{\mathrm{KL}}(p\Vert p')=1-1/K and ρ‾(p,p′)≃π/4\overline{\rho}(p,p')\simeq\pi/4 (App. § 9), and if the D−1D-1 divergences from the true topic concentrate near their mean, the odds of a wrong topic in Eq. (21) are approximately (D−1)e−(1−1/K)t(D-1)e^{-(1-1/K)t}, so that the floor is reached for t≈log⁡(D−1)t\approx\log(D-1). This last estimate is heuristic, as it assumes a concentration of the pairwise divergences that we do not prove; it is consistent with the half-descent points in Figure 2, which grow linearly in log⁡D\log D.

The in-context predictor

This appendix proves the statements of § 2.2: the form and optimality of rtr_t, the loss decomposition Eq. (6), and the exact finite-tt risk behind its expansion. Throughout, the document is OOD: p⋆∼Dir⁡K(1)p_\star\sim\operatorname{Dir}_K(1) and, given p⋆p_\star, the tokens are i.i.d. from p⋆p_\star.

Posterior and add-one rule. The prior density is constant on the simplex and the likelihood of a context is ∏ap⋆(a)Ca\prod_a p_\star(a)^{C_a}, so the posterior density is proportional to ∏ap⋆(a)Ca\prod_a p_\star(a)^{C_a}: this is Dir⁡K(C1+1,…,CK+1)\operatorname{Dir}_K(C_1+1,\ldots,C_K+1), whose density is proportional to ∏apaαa−1\prod_a p_a^{\alpha_a-1} with αa=Ca+1\alpha_a=C_a+1. Given p⋆p_\star and the context, Xt+1∼p⋆X_{t+1}\sim p_\star, and the mean of Dir⁡K(α)\operatorname{Dir}_K(\alpha) is αa/∑bαb\alpha_a/\sum_b\alpha_b, so the posterior predictive distribution is

rt(a∣X≤t)=E[p⋆(a)∣X≤t]=Ca+1t+K.(25)r_t(a\mid X_{\le t})=\mathbb{E}\left[p_\star(a)\mid X_{\le t}\right]=\frac{C_a+1}{t+K}. \tag*{(25)}

which is Eq. (5).

Optimality. As in Appendix § 10, rtr_t is the conditional distribution of Xt+1X_{t+1} given the context, so for any predictor ff

E[−log⁡ft(Xt+1∣X≤t)∣X≤t]=H(rt)+DKL(rt∥ft)≥H(rt),(26)\mathbb{E}\left[-\log f_t(X_{t+1}\mid X_{\leq t})\mid X_{\leq t}\right]=H(r_t)+D_{\mathrm{KL}}(r_t\|f_t)\geq H(r_t), \tag*{(26)}

with equality if and only if ft=rtf_t=r_t; averaging over contexts, Lt⋆[f]≥Lt⋆[r]\mathcal{L}^{\star}_t[f]\geq\mathcal{L}^{\star}_t[r]. Unlike qtq_t, the predictor rtr_t does not depend on the topic matrix: on a document generated from any topic pp, its loss is a function Rt(p):=E[−log⁡rt(Xt+1∣X≤t)∣p]R_t(p):=\mathbb{E}[-\log r_t(X_{t+1}\mid X_{\leq t})\mid p] of that topic alone. Its ID loss at fixed PP is Lt[r]=1D∑zRt(pz)\mathcal{L}_t[r]=\frac{1}{D}\sum_z R_t(p_z) and its OOD loss is Lt⋆[r]=Rt(p)\mathcal{L}^{\star}_t[r]=R_t(p), whence Lt[r]=Lt⋆[r]\mathcal{L}_t[r]=\mathcal{L}^{\star}_t[r].

Loss decomposition. Conditioning on p⋆p_{\star} and the context, Xt+1∼p⋆X_{t+1}\sim p_{\star}, so E[−log⁡rt(Xt+1∣X≤t)∣p⋆,X≤t]=H(p⋆)+DKL(p⋆∥rt)\mathbb{E}[-\log r_t(X_{t+1}\mid X_{\leq t})\mid p_{\star},X_{\leq t}]=H(p_{\star})+D_{\mathrm{KL}}(p_{\star}\|r_t); averaging over p⋆p_{\star} and the context gives the first equality in Eq. (6), with E[H(p⋆)]=H(p‾)\mathbb{E}[H(p_{\star})]=H(\overline{p}) because p⋆p_{\star} has the law of the training topics. Moreover, by Eq. (26) at f=rf=r, Lt⋆[r]=H(Xt+1∣X≤t)\mathcal{L}^{\star}_t[r]=H(X_{t+1}\mid X_{\leq t}) is a conditional entropy; since the tokens are exchangeable given p⋆p_{\star}, H(Xt+2∣X≤t)=H(Xt+1∣X≤t)H(X_{t+2}\mid X_{\leq t})=H(X_{t+1}\mid X_{\leq t}), and conditioning on one more token shows that Lt⋆[r]\mathcal{L}^{\star}_t[r] is non-increasing in tt.

Exact finite-tt risk. Integrating the likelihood against the uniform prior, the count vector of a context is uniform over the (t+K−1K−1)\binom{t+K-1}{K-1} weak compositions of tt into KK parts,

P(C(X≤t)=n)=t!∏ana!Γ(K)∏aΓ(na+1)Γ(t+K)=(t+K−1K−1)−1,∑ana=t.(27)\mathbb{P}\bigl(C(X_{\leq t})=\mathbf{n}\bigr)=\frac{t!}{\prod_a n_a!}\frac{\Gamma(K)\prod_a\Gamma(n_a+1)}{\Gamma(t+K)}=\binom{t+K-1}{K-1}^{-1},\qquad\sum_a n_a=t. \tag*{(27)}

Hence, by Eq. (25) and the symmetry of the entries, for K≥2K\geq2

Lt⋆[r]=log⁡(t+K)−E[∑art(a∣X≤t)log⁡(Ca+1)]=log⁡(t+K)−K(t+K)(t+K−1K−1)∑n=0t(n+1)log⁡(n+1)(t−n+K−2K−2),(28)\begin{aligned} \mathcal{L}^{\star}_t[r]=\log(t+K)-\mathbb{E}\left[\sum_a r_t(a\mid X_{\leq t})\log(C_a+1)\right] \\ &=\log(t+K)-\frac{K}{(t+K)\binom{t+K-1}{K-1}}\sum_{n=0}^{t}(n+1)\log(n+1)\binom{t-n+K-2}{K-2}, \tag*{(28)} \end{aligned}

where (t−n+K−2K−2)\binom{t-n+K-2}{K-2} counts the compositions with C1=nC_1=n. In particular Lt⋆[r]=log⁡K\mathcal{L}^{\star}_t[r]=\log K and Lt⋆[r]→H(p‾)\mathcal{L}^{\star}_t[r]\to H(\overline{p}) as t→∞t\to\infty. Expanding at large tt and fixed KK gives the second equality in Eq. (6),

Lt⋆[r]=ψ(K+1)−ψ(2)+K−12t+OK(log⁡tt2),(29)\mathcal{L}^{\star}_t[r]=\psi(K+1)-\psi(2)+\frac{K-1}{2t}+O_K\left(\frac{\log t}{t^2}\right), \tag*{(29)}

where the logarithm in the remainder comes from the mass that the uniform prior puts near the boundary of the simplex. The leading correction is one half of the number of parameters of a topic, K−1K-1, per observation, and the expansion requires t≫Kt\gg K: at K=64K=64 and t=128t=128, Eq. (28) gives an excess of 0.15 nats over the floor, against 0.25 for the leading term alone; the former is the gap between the dashed line and the floor at the end of the profiles in Figure 2.

The Bayesian learner

This appendix proves the statements of § 3: the form and optimality of the Bayesian learner, the information identity, the DK/NTDK/NT law and its fixed-position version.

Posterior and predictor. Let CN=(X1:T(n))n=1NC_N=(X_{1:T}^{(n)})_{n=1}^{N} be the corpus, with count vectors C(n)C^{(n)}, and write ℓC(p):=∏ap(a)Ca\ell_C(p):=\prod_a p(a)^{C_a} for the likelihood of a count vector under a topic. Given a candidate topic matrix P~\widetilde{P}, integrating out the latent topic of each document gives the likelihood of corpus and context,

L(P~):=∏n=1N[1D∑z=1DℓC(n)(p~z)]×1D∑z=1DℓC(X≤t)(p~z),(30)L(\widetilde{P}):=\prod_{n=1}^{N}\left[\frac{1}{D}\sum_{z=1}^{D}\ell_{C^{(n)}}(\widetilde{p}_z)\right]\times\frac{1}{D}\sum_{z=1}^{D}\ell_{C(X_{\leq t})}(\widetilde{p}_z), \tag*{(30)}

up to multinomial factors that do not depend on P~\widetilde{P}. The posterior of PP is π(dP~)∝L(P~)μ(dP~)\pi(\mathrm{d}\widetilde{P})\propto L(\widetilde{P})\mu(\mathrm{d}\widetilde{P}), with μ\mu the product of DD uniform priors on the simplex, and Eq. (7) reads q^t=∫qt,P~(X≤t) π(dP~)\widehat{q}_t=\int q_{t,\widetilde{P}}(X_{\leq t})\,\pi(\mathrm{d}\widetilde{P}), where qt,P~q_{t,\widetilde{P}} is the specialised predictor of Eq. (3) computed with P~\widetilde{P}. By construction q^t\widehat{q}_t is the conditional law of Xt+1X_{t+1} given (CN,X≤t)(C_N,X_{\leq t}) under the joint law of topics, corpus and test document, so, as in Appendix § 10, every predictor ff built from corpus and context satisfies Lt[f]≥Lt[q^]\mathcal{L}_t[f]\geq\mathcal{L}_t[\widehat{q}], with equality if and only if ft=q^tf_t=\widehat{q}_t.

Excess and mutual information. At fixed PP, conditioning on the context, Xt+1∼qtX_{t+1}\sim q_t and the corpus is independent of the test document, so Lt[q^]−Lt[q]=E[DKL(qt∥q^t)]≥0\mathcal{L}_t[\hat{q}]-\mathcal{L}_t[q]=\mathbb{E}[D_{\mathrm{KL}}(q_t\Vert\hat{q}_t)]\ge0. Averaged over PP, the two losses are the conditional entropies H(Xt+1∣X≤t,CN)H(X_{t+1}\mid X_{\leq t},C_N) and H(Xt+1∣X≤t,CN,P)H(X_{t+1}\mid X_{\leq t},C_N,P), whence

εt(N)=I(P;Xt+1∣X≤t,CN).(31)\varepsilon_t(N)=I(P;X_{t+1}\mid X_{\leq t},C_N). \tag*{(31)}

The second entropy does not change if one more document X1:T(N+1)X_{1:T}^{(N+1)} is added to the corpus, since given PP the corpus is irrelevant, so εt(N)−εt(N+1)=I(Xt+1;X1:T(N+1)∣X≤t,CN)≥0\varepsilon_t(N)-\varepsilon_t(N+1)=I(X_{t+1};X_{1:T}^{(N+1)}\mid X_{\leq t},C_N)\ge0: the learning curve is non-increasing in NN. Summing Eq. (31) over positions with the chain rule, and using that the test document has the law of X1:T(N+1)X_{1:T}^{(N+1)} and is independent of the corpus given PP,

∑t=0T−1εt(N)=I(P;X1:T(N+1)∣CN)=I(P;CN+1)−I(P;CN),(32)\sum_{t=0}^{T-1}\varepsilon_t(N)=I(P;X_{1:T}^{(N+1)}\mid C_N)=I(P;C_{N+1})-I(P;C_N), \tag*{(32)}

which is Eq. (9), the document-level form of the cumulative predictive risk identity of [13].

The DK/NT law. Up to a relabelling of the topics, the law QP:=1D∑zpz⊗TQ_P:=\frac{1}{D}\sum_z p_z^{\otimes T} of a document has d=D(K−1)d=D(K-1) parameters. Assume that P↦QPP\mapsto Q_P is identifiable up to relabelling and regular: twice continuously differentiable in local coordinates, with positive definite Fisher information, and with a prior density that is positive and continuous. Then, for fixed DD, KK, TT and N→∞N\to\infty, Theorem 1 of [14] gives

I(P;CN)=d2log⁡N+c+o(1),(33)I(P;C_N)=\frac{d}{2}\log N+c+o(1), \tag*{(33)}

with a constant cc that depends on prior and document model but not on NN. The increment in Eq. (32) does not follow by direct subtraction, since an o(1)o(1) term need not have o(N−1)o(N^{-1}) increments, but it does follow from monotonicity. Let aN:=∑tεt(N)a_N:=\sum_t\varepsilon_t(N), non-increasing in NN, and for λ>1\lambda>1 let m=⌊λN⌋m=\lfloor\lambda N\rfloor and l=⌊N/λ⌋l=\lfloor N/\lambda\rfloor. Summing ana_n over N≤n<mN\le n<m and over l≤n<Nl\le n<N and using monotonicity,

I(P;Cm)−I(P;CN)m−N≤aN≤I(P;CN)−I(P;Cl)N−l,(34)\frac{I(P;C_m)-I(P;C_N)}{m-N}\le a_N\le\frac{I(P;C_N)-I(P;C_l)}{N-l}, \tag*{(34)}

where both numerators equal d2log⁡λ+o(1)\frac{d}{2}\log\lambda+o(1) by Eq. (33). Letting N→∞N\to\infty and then λ↓1\lambda\downarrow1 squeezes NaNNa_N between d2log⁡λλ−1\frac{d}{2}\frac{\log\lambda}{\lambda-1} and d2λlog⁡λλ−1\frac{d}{2}\frac{\lambda\log\lambda}{\lambda-1}, both of which tend to d/2d/2; dividing by TT gives Eq. (10).

Identifiability. For T≥3T\ge3 the third-order moment of the tokens, M3=1D∑zpz⊗3M_3=\frac{1}{D}\sum_z p_z^{\otimes3}, is a marginal of QPQ_P, and by Kruskal’s theorem [22, 2] its decomposition into DD rank-one terms is unique up to permutation when 3rank⁡K(P)≥2D+23\operatorname{rank}_K(P)\ge2D+2, where the Kruskal rank rank⁡K(P)\operatorname{rank}_K(P) is the largest kk such that any kk columns of PP are linearly independent. For topics drawn from the simplex, rank⁡K(P)=min⁡{K,D}\operatorname{rank}_K(P)=\min\{K,D\} almost surely, so the condition holds for D≤KD\le K (and up to D≤3K/2−1D\le3K/2-1), and the topics can be recovered constructively: the second moment M2=1D∑zpzpzTM_2=\frac{1}{D}\sum_z p_zp_z^{\mathsf T} has rank DD and whitens M3M_3 into an orthogonally decomposable tensor whose factors are the topics [3]. For larger DD, lift the topics to pz⊗mp_z^{\otimes m}, which lie in the space of symmetric tensors, of dimension sm=(K+m−1m)s_m=\binom{K+m-1}{m}, and span it as pzp_z ranges over the simplex, since a homogeneous polynomial vanishing on the simplex vanishes identically; some sm×sms_m\times s_m minor of [v1,…,vD][v_1,\ldots,v_D] is then a nonzero polynomial in the topic entries, so the lifted topics are linearly independent almost surely whenever D≤smD\le s_m. In that case the 2m2m-token moment 1D∑zvzvzT\frac{1}{D}\sum_z v_zv_z^{\mathsf T} has rank DD, the rank of the Hankel matrix of the token process, and together with the (2m+1)(2m+1)-token moment it determines the law of documents of every length, hence PP up to relabelling [5] (App. F). Moreover, for T≥2m+1T\ge2m+1 the Fisher information of a document is nonsingular: a perturbation δP\delta P that leaves the law of a document unchanged to first order leaves the (2m+1)(2m+1)-token marginal 1D∑zvz⊗vz⊗pz\frac{1}{D}\sum_z v_z\otimes v_z\otimes p_z unchanged, and contracting its variation with az⊗az⊗Id⁡a_z\otimes a_z\otimes\operatorname{Id}, where the functionals aza_z satisfy az(vz′)=δzz′a_z(v_{z'})=\delta_{zz'}, gives δpz+2az(δvz)pz=0\delta p_z+2a_z(\delta v_z)p_z=0 for each zz and then δpz=0\delta p_z=0. Hence D≤(K+m−1m)D\le\binom{K+m-1}{m} and T≥2m+1T\ge2m+1 suffice almost surely: D≤KD\le K with T≥3T\ge3, D≤K(K+1)/2D\le K(K+1)/2 with T≥5T\ge5, and so on; these conditions are sufficient, not necessary, and they are the only place where the genericity of the topic matrix is used. Regularity additionally excludes the sets, of prior measure zero, where two topics coincide or a topic lies on the boundary of the simplex.

Fixed position: the resolved learner. Reveal to the learner the topic labels of the training documents and of the test document. Conditional on the labels, by the conjugacy of App. C, the Bayesian predictor is the add-one rule on the pooled counts of the test topic,

q^tres(a∣X≤t)=MZ,a+Ca+1NZT+t+K,(35)\hat{q}^{\mathrm{res}}_t(a \mid X_{\leq t}) = \frac{M_{Z,a} + C_a + 1}{N_ZT + t + K}, \tag*{(35)}

where NZN_Z is the number of training documents of topic ZZ and MZ,aM_{Z,a} their total count of token aa: the in-context predictor of Eq. (5) applied to m=NZT+tm = N_ZT + t tokens. Averaged over topics, its excess over the entropy rate 1D∑ZH(pZ)\frac{1}{D}\sum_Z H(p_Z) is therefore E[gK(NZT+t)]\mathbb{E}[g_K(N_ZT + t)], with gK(m):=Lm∗[r]−H‾(p)g_K(m) := \mathcal{L}^*_m[r] - \overline{H}(p) the excess of the in-context predictor in Eq. (6) and NZ∼Bin⁡(N,1/D)N_Z \sim\operatorname{Bin}(N,1/D). If N/D→∞N/D \to\infty then NZ/(N/D)→1N_Z/(N/D) \to1 in probability, and if moreover tD/(NT)→0tD/(NT) \to0 and log⁡T=o(N/D)\log T = o(N/D), so that the event that the test topic is absent from the corpus is negligible on the 1/(NT)1/(NT) scale, Eq. (6) gives

Etres(N):=E[gK(NZT+t)]=D(K−1)2NT(1+o(1)).(36)\mathcal{E}^{\mathrm{res}}_t(N) := \mathbb{E}\left[g_K(N_ZT+t)\right] = \frac{D(K-1)}{2NT}(1+o(1)). \tag*{(36)}

The resolved learner is not the Bayesian learner, which must also infer the labels and the topic matrix. For a fixed PP with distinct topics, and assuming identifiability from a marginal of k≤Tk \leq T tokens, the two excesses differ by at most

C(P)(e−c(P)t+Ne−c(P)T)+exp⁡{−a(P)N+OP(log⁡[N(T+t)])},(37)C(P)\left(e^{-c(P)t}+Ne^{-c(P)T}\right)+\exp\left\{-a(P)N+O_P\left(\log[N(T+t)]\right)\right\}, \tag*{(37)}

with c(P)=log⁡(1/ρ∗)c(P)=\log(1/\rho_*) from Eq. (23) and a(P)>0a(P)>0. The first two terms are the costs of unresolved test and training labels, by the bound of App. B applied to the test context and to each of the NN training documents; the last is the posterior mass on topic matrices outside a fixed neighbourhood of PP, exponentially small in NN by a likelihood-ratio test on the identifying marginal, against the polynomial prior mass of the neighbourhood. Hence the Bayesian learner obeys Eq. (36) at fixed PP whenever tt and TT grow like Alog⁡NA\log N with AA large enough for Eq. (37) to be o(1/(NT))o(1/(NT)): the fixed-position form of the DK/NTDK/NT law. The statement is conditional on PP; averaging it over the prior would require uniform control over nearly coinciding topics, for which c(P)c(P) is arbitrarily small.

The in-context solution

This appendix supports Sec. 4: the estimation excess of a fitted parametric family, the count-linear family that contains the in-context predictor, and the gain G(K,T)G(K,T) with its interpretation and expansions.

Estimation excess of a fitted family. Let {fθ:θ∈Θ⊂Rd}\{f_\theta: \theta\in\Theta\subset\mathbb{R}^d\} be a family of distributions of a document Y=X1:TY=X_{1:T}, with all dd coordinates of θ\theta free, and let ℓ(θ;Y):=−log⁡fθ(Y)\ell(\theta;Y):=-\log f_\theta(Y) and R(θ):=E[ℓ(θ;Y)]\mathcal{R}(\theta):=\mathbb{E}[\ell(\theta;Y)] be its log loss and its population risk under the true law of YY. Let θ∗\theta_* be an interior minimiser of R\mathcal{R}, isolated up to finite symmetries, around which fθ(y)>0f_\theta(y)>0 is three times continuously differentiable, and define the risk curvature and the gradient covariance

H:=∇2R(θ∗)≻0,J:=E[∇ℓ(θ∗;Y)∇ℓ(θ∗;Y)T];(38)H := \nabla^2\mathcal{R}(\theta_*) \succ0,\qquad J := \mathbb{E}\left[\nabla\ell(\theta_*;Y)\nabla\ell(\theta_*;Y)^\mathsf{T}\right]; \tag*{(38)}

the gradient has zero mean because θ∗\theta_* is a minimiser. Let θ^N\hat{\theta}_N be a consistent fit on NN independent documents whose empirical gradient is oP(N−1/2)o_P(N^{-1/2}), as for an interior minimiser of the empirical risk R^N\hat{\mathcal{R}}_N, and let gN:=∇R^N(θ∗)g_N:=\nabla\hat{\mathcal{R}}_N(\theta_*), which has mean zero and covariance J/NJ/N by independence. Expanding the empirical gradient and the population risk around θ∗\theta_*,

θ^N−θ∗=−H−1gN+uN,R(θ^N)−R(θ∗)=12(θ^N−θ∗)TH(θ^N−θ∗)+vN,(39)\hat{\theta}_N-\theta_*=-H^{-1}g_N+u_N,\qquad\mathcal{R}(\hat{\theta}_N)-\mathcal{R}(\theta_*)=\frac{1}{2}(\hat{\theta}_N-\theta_*)^\mathsf{T}H(\hat{\theta}_N-\theta_*)+v_N, \tag*{(39)}

with uN=oP(N−1/2)u_N=o_P(N^{-1/2}) and vN=oP(N−1)v_N=o_P(N^{-1}). If the remainders are also small in expectation, E∥uN∥2=o(N−1)\mathbb{E}\lVert u_N\rVert^2=o(N^{-1}) and E∣vN∣=o(N−1)\mathbb{E}|v_N|=o(N^{-1}), then substituting and using E[gTAg]=tr⁡(ACov⁡g)\mathbb{E}[g^\mathsf{T}Ag]=\operatorname{tr}(A\operatorname{Cov}g) for centred gg,

E[R(θ^N)−R(θ∗)]=deff2N+o(N−1),deff:=tr⁡(JH−1).(40)\mathbb{E}\left[\mathcal{R}(\hat{\theta}_N)-\mathcal{R}(\theta_*)\right]=\frac{d_{\mathrm{eff}}}{2N}+o(N^{-1}),\qquad d_{\mathrm{eff}}:=\operatorname{tr}(JH^{-1}). \tag*{(40)}

If the family is well specified, i.e. the true law is fθ∗f_{\theta_*}, differentiating ∑yfθ(y)=1\sum_y f_\theta(y)=1 twice gives H=JH=J, the Fisher information of one document, and deff=dd_{\mathrm{eff}}=d and the model is nonsingular. The remainder bounds hold, for instance, for an empirical-risk minimiser over a compact set that contains θ⋆\theta_\star in its interior and on which probabilities are bounded below; they are not automatic for an unrestricted fit, nor for a transformer. Divided by TT, (40) is a per-token excess d/(2NT)d/(2NT). For the topic matrix itself, d=D(K−1)d = D(K-1), and the Fisher information is nonsingular almost surely for D≤KD \le K and T≥3T \ge3 (the Jacobian of the three-token marginal is injective when the topics are linearly independent), so a fitted dictionary recovers (10) by an argument on a fitted parameter rather than on the posterior; for the count map below, d≃K2d \simeq K^2.

The count-linear family. The predictors that are linear in the counts up to normalisation,

fA,b(a∣X≤t):=(AC(X≤t)+b)a1T(AC(X≤t)+b),A∈RK×K, b∈RK,(41)f_{A,\mathbf{b}}(a \mid X_{\le t}) := \frac{\left(A C(X_{\le t})+\mathbf{b}\right)_a}{\mathbf{1}^{\mathsf{T}}\left(A C(X_{\le t})+\mathbf{b}\right)}, \qquad A \in\mathbb{R}^{K \times K},\ \mathbf{b} \in\mathbb{R}^{K}, \tag*{(41)}

contain the in-context predictor at (A,b)=(I,1)(A,\mathbf{b}) = (I,\mathbf{1}). Counts are bounded by TT, so the family is positive and smooth on a neighbourhood of this point, and it has d=K2+K−1d = K^2 + K - 1 free parameters, the overall scale of (A,b)(A,\mathbf{b}) being immaterial. On OOD documents the family is well specified, since the law of an OOD document is the product of its add-one predictors (App. C), so θ⋆=(I,1)\theta_\star= (I,\mathbf{1}) and (40) gives the excess d/(2NT)≃K2/(2NT)d/(2NT) \simeq K^2/(2NT) of Sec. 4 for a learner that fits this family. On the training distribution the family is misspecified at finite DD, its optimum being a fit to qtq_t, a ratio of exponentials of the counts. The misspecification vanishes as D→∞D \to\infty: writing (3) as a ratio of averages over the dictionary,

qt(a∣X≤t)=1D∑zpz(a)∏bpz(b)Cb1D∑z∏bpz(b)Cb⟶D→∞a.s.p(a)∏bp(b)Cb∏bp(b)Cb=Ca+1t+K=rt(a∣X≤t),(42)q_t(a \mid X_{\le t}) = \frac{\frac{1}{D}\sum_z p_z(a)\prod_b p_z(b)^{C_b}}{\frac{1}{D}\sum_z \prod_b p_z(b)^{C_b}} \mathrel{\mathop{\longrightarrow}^{\mathrm{a.s.}}_{D\to\infty}} \frac{p(a)\prod_b p(b)^{C_b}}{\prod_b p(b)^{C_b}} = \frac{C_a+1}{t+K} = r_t(a \mid X_{\le t}), \tag*{(42)}

by the strong law of large numbers applied to numerator and denominator at fixed KK and count vector, and the Dirichlet moment ∏bp(b)nb=Γ(K)∏bΓ(nb+1)Γ(K+∑bnb)\prod_b p(b)^{n_b} = \frac{\Gamma(K)\prod_b \Gamma(n_b+1)}{\Gamma(K+\sum_b n_b)}, of which (15) is the one-entry case. The convergence is pointwise in the count vector, and the dictionary size needed for a given accuracy grows with tt, since the weights in (42) concentrate on a neighbourhood of the empirical frequencies that shrinks with tt. Note that the family cannot be reached through the specialised predictor of a small dictionary. qtq_t is a convex combination of the DD topics, so its Jacobian with respect to the counts has rank at most D−1D-1, whereas that of the add-one map is K−1K-1: a learner whose predictor tracks the in-distribution optimum can realise the count-linear rule only if D≥KD \ge K.

The gain of the in-context predictor. On an OOD document every token is marginally uniform, P(Xt+1=a)=p(a)=1/K\mathbb{P}(X_{t+1}=a)=p(a)=1/K, so H(Xt+1)=log⁡KH(X_{t+1})=\log K, and Lt⋆[r]=H(Xt+1∣X≤t)\mathcal{L}_t^\star[r]=H(X_{t+1}\mid X_{\le t}) by App. C; hence

log⁡K−Lt⋆[r]=I(Xt+1;X≤t),(43)\log K-\mathcal{L}_t^\star[r]=I(X_{t+1};X_{\le t}), \tag*{(43)}
TG(K,T)=Tlog⁡K−H(X1:T)=T[log⁡K−H(p)‾]−I(p⋆;X1:T),(44)T G(K,T)=T\log K-H(X_{1:T})=T\left[\log K-\overline{H(\mathbf{p})}\right]-I(\mathbf{p}_\star;X_{1:T}), \tag*{(44)}

by the chain rule, and H(X1:T)=H(X1:T∣p⋆)+I(p⋆;X1:T)H(X_{1:T})=H(X_{1:T}\mid\mathbf{p}_\star)+I(\mathbf{p}_\star;X_{1:T}) with H(X1:T∣p⋆)=TH(p)‾H(X_{1:T}\mid\mathbf{p}_\star)=T\overline{H(\mathbf{p})}. The gain per token is thus the entropy gap between the uniform distribution and a random topic, 1−γE−1/(2K)+O(K−2)1-\gamma_{\mathrm{E}}-1/(2K)+O(K^{-2}) by (16), minus the information about its own topic that the document leaves unrevealed. Its exact value follows from (28), and its two regimes are

G(K,T)=log⁡K−H(p)‾−K−12log⁡TT+OK(1T)(T≫K),G(K,T)=\log K-\overline{H(\mathbf{p})}-\frac{K-1}{2}\frac{\log T}{T}+O_K\left(\frac{1}{T}\right) \qquad(T \gg K),
G(K,T)=(2log⁡2−1)T−12K+O(T2K2)(K≫T).(45)G(K,T)=(2\log2-1)\frac{T-1}{2K}+O\left(\frac{T^2}{K^2}\right) \qquad(K \gg T). \tag*{(45)}

The first follows by summing (29) over opposite positions, which gives I(p⋆;X1:T)=K−12log⁡T+OK(1)I(\mathbf{p}_\star;X_{1:T})=\frac{K-1}{2}\log T+O_K(1): a long context reveals its topic up to the usual parametric cost. The second follows from (28) at t≪Kt\ll K: a given token appears once in the context with probability P(Ca=1)=(K−1)t/[(t+K−1)(t+K−2)]≃t/K\mathbb{P}(C_a=1)=(K-1)t/[(t+K-1)(t+K-2)]\simeq t/K and more than once with probability O(t2/K2)O(t^2/K^2), so that Lt⋆[r]=log⁡(t+K)−Kt+Klog⁡2 P(Ca=1)+O(t2/K2)=log⁡K−(2log⁡2−1)t/K+O(t2/K2)\mathcal{L}_t^\star[r]=\log(t+K)-\frac{K}{t+K}\log2\,\mathbb{P}(C_a=1)+O(t^2/K^2)=\log K-(2\log2-1)t/K+O(t^2/K^2); in a short context most tokens are new, and the gain comes from the few repeated ones.

The spectral baseline

This appendix supports § 5.1: the Hankel formulation of spectral learning, the spectra of the pair and four-token moments under the random topic model, the noise of their empirical estimates, and the resulting sample complexities. Its asymptotic statements are in the joint limit D,K→∞D, K \to\infty with D/KD/K, respectively D/K2D/K^{2}, fixed.

Hankel matrix and subspace

For the token process, the Hankel matrix has entries H(u,v):=P(X1:∣u∣+∣v∣=uv)H(u,v) := \mathbb{P}(X_{1:|u|+|v|}=uv), indexed by a prefix string uu and a suffix string vv; since tokens are i.i.d. given the topic, H(u,v)=1D∑zgz(u)gz(v)H(u,v)=\frac{1}{D}\sum_z g_z(u)g_z(v) with gz(u)=∏pz(us)g_z(u)=\prod p_z(u_s), so that rank⁡H≤D\operatorname{rank} H \le D (Balle et al., [5]). Spectral learning first recovers the column space of HH from a complete sub-block, i.e. one of rank DD, then the observation operators from the block with one more symbol; for the random topic model the hidden state is constant within a document, the transition matrix is the identity and the observation matrix is PP (Hsu et al., [21]). The block on prefixes and suffixes of mm tokens is M2m=1D∑z(pz⊗m)(pz⊗m)⊤M_{2m}=\frac{1}{D}\sum_z(\mathbf{p}_z^{\otimes m})(\mathbf{p}_z^{\otimes m})^\top, whose nonzero spectrum is that of the D×DD \times D Gram matrix 1D[(pi⊤pj)m]ij\frac{1}{D}[(\mathbf{p}_i^\top\mathbf{p}_j)^m]_{ij}. The lifted topics pz⊗m\mathbf{p}_z^{\otimes m} lie in the space of symmetric tensors, of dimension sm=(K+m−1m)s_m=\binom{K+m-1}{m}, and span it as pz\mathbf{p}_z ranges over the simplex, since a homogeneous polynomial vanishing on the simplex vanishes identically; some sm×sms_m \times s_m minor of the lifted topic matrix is therefore a nonzero polynomial in the topic entries, and rank⁡M2m=min⁡{D,sm}\operatorname{rank} M_{2m}=\min\{D,s_m\} almost surely for topics drawn from the simplex. The single-token block M2M_2 is thus complete for D≤KD \le K, the two-token block M4M_4 for D≤K(K+1)/2D \le K(K+1)/2, and so on; the topics follow from M3M_3, M5M_5, …\ldots, for D≤KD \le K through the whitening of M3M_3 by M2M_2 and the decomposition of the resulting orthogonal tensor (Anandkumar et al., [3]), as recalled in App. D.

Spectrum of M2M_2

By Eq. (15), papb‾=1/(K(K+1))\overline{p_a p_b}=1/(K(K+1)) for a≠ba\ne b and pa2‾=2/(K(K+1))\overline{p_a^2}=2/(K(K+1)), so the mean of M2M_2 over the topics is (I+11⊤)/(K(K+1))(I+11^\top)/(K(K+1)), with one eigenvalue 1/K1/K along 11 and 1/(K(K+1))1/(K(K+1)) on its complement. For a realisation, write pz=1/K+ξz\mathbf{p}_z=1/K+\xi_z with ξz\xi_z centred, orthogonal to 11, of covariance 1K(K+1)(I−11⊤/K)\frac{1}{K(K+1)}(I-11^\top/K) and independent across topics; the nonzero spectrum of M2=1DPP⊤M_2=\frac{1}{D}PP^\top is that of 1DP⊤P=1D[1K11⊤+Ξ⊤Ξ]\frac{1}{D}P^\top P=\frac{1}{D}\left[\frac{1}{K}11^\top+\Xi^\top\Xi\right] with Ξ=[ξ1,…,ξD]\Xi=[\xi_1,\ldots,\xi_D]. In the (K−1)(K-1)-dimensional complement of 11, the rescaled columns K(K+1) ξz\sqrt{K(K+1)}\,\xi_z are independent, isotropic and log-concave, being uniform on a convex set, so that as D,K→∞D,K\to\infty with D/(K−1)→α∈(0,1)D/(K-1)\to\alpha\in(0,1) the eigenvalues of K(K+1)K−1Ξ⊤Ξ\frac{K(K+1)}{K-1}\Xi^\top\Xi follow the Marchenko–Pastur law of ratio α\alpha, with extreme eigenvalues converging to the edges (1±α)2(1\pm\sqrt{\alpha})^2 (Pajor & Pastur, [27]; Chafaï & Tikhomirov [12]). The rank-one term removes at most one eigenvalue from this bulk, by interlacing, and produces the outlier D/KD/K; dividing by DD,

λ1(M2)=1K(1+oP(1)),λ2(M2),λD(M2)=K−1DK(K+1)(1±DK−1)2(1+oP(1)),(46)\lambda_1(M_2)=\frac{1}{K}\left(1+o_P(1)\right),\qquad\lambda_2(M_2),\lambda_D(M_2)=\frac{K-1}{DK(K+1)}\left(1\pm\sqrt{\frac{D}{K-1}}\right)^2\left(1+o_P(1)\right), \tag*{(46)}

and the remaining K−DK-D eigenvalues vanish: one spike at 1/K1/K and a bulk of D−1D-1 eigenvalues at scale 1/(DK)1/(DK), as in Figure 6.

Spectrum of M4M_4

For K<D≤K(K+1)/2K<D\le K(K+1)/2 the complete block is M4M_4, whose nonzero spectrum is that of 1D[(pi⊤pj)2]ij\frac{1}{D}[(\mathbf{p}_i^\top\mathbf{p}_j)^2]_{ij}. Writing p⊗2=u⊗2+(u⊗ξ+ξ⊗u)+ξ⊗2\mathbf{p}^{\otimes2}=\mathbf{u}^{\otimes2}+(\mathbf{u}\otimes\xi+\xi\otimes\mathbf{u})+\xi^{\otimes2} with u=1/K\mathbf{u}=1/K separates three scales. The mean feature has squared norm (K+3)/(K(K+1)2)≃K−2(K+3)/(K(K+1)^2)\simeq K^{-2} and gives one spike at K−2K^{-2}; the linear features span K−1K-1 directions with characteristic eigenvalue 2/(K2(K+1))2/(K^2(K+1)); the centred quadratic features span the remaining r2=K(K−1)/2r_2=K(K-1)/2 directions, with average covariance eigenvalue 2K−4(1+O(K−1))2K^{-4}(1+O(K^{-1})). Neglecting the coupling between the blocks, a Marchenko–Pastur approximation of each predicts K−1K-1 eigenvalues of order K−3K^{-3}, with edges 2K2(K+1)(1±(K−1)/D)2\frac{2}{K^2(K+1)}\left(1\pm\sqrt{(K-1)/D}\right)^2, and D−KD-K eigenvalues of order 1/(DK2)1/(DK^2), with edges 1+O(K−1)DK2(1±D/r2)2\frac{1+O(K^{-1})}{DK^2}\left(1\pm\sqrt{D/r_2}\right)^2 when D/r2→β∈(0,1)D/r_2\to\beta\in(0,1). This block picture is heuristic, since quadratic features are neither isotropic nor log-concave and the coupling is neglected; Figure 7 compares it with the spectrum of one realisation at D=K(K+1)/4D=K(K+1)/4, where both bulks follow the predicted curves and their Frobenius norms agree with the predictions within 7% for the linear block and 2% for the quadratic one, for KK from 64 to 192.

Noise and sample complexity

Let M^2\widehat{M}_2 be the empirical pair moment from NN independent pairs, so that M^2−M2=1N∑μYμ\widehat{M}_2 - M_2 = \frac{1}{N}\sum_\mu Y_\mu with Yμ=x1(μ)x2(μ)T−M2Y_\mu= x_1^{(\mu)}x_2^{(\mu)\mathsf{T}} - M_2 centred, ∥Yμ∥op≤1+1/K\lVert Y_\mu\rVert_{\mathrm{op}} \le1 + 1/K and E[YμYμT]⪯diag⁡(pˉ)\mathbb{E}[Y_\mu Y_\mu^{\mathsf{T}}] \preceq\operatorname{diag}(\bar{p}), with pˉ=∑zpz\bar{p} = \sum_z p_z the unigram marginal, of entries close to 1/K1/K. The matrix Bernstein inequality ([36]) then gives, with probability at least 1−δ1-\delta,

∥M^2−M2∥op≤2log⁡(2K/δ)KN+2log⁡(2K/δ)3N,(47)\lVert\widehat{M}_2 - M_2\rVert_{\mathrm{op}} \le\sqrt{\frac{2\log(2K/\delta)}{KN}} + \frac{2\log(2K/\delta)}{3N}, \tag*{(47)}

a noise level of order (NK)−1/2(NK)^{-1/2}; the measured error follows 1.5/NK1.5/\sqrt{NK} across eleven (K,D)(K,D) configurations (Figure 8, left). Treating the noise as a generic perturbation, an eigenvalue λ\lambda of M2M_2 is resolved once λ≳1.5/NK\lambda\gtrsim1.5/\sqrt{NK}: the spike at N∼KN \sim K, and the lower edge of the bulk, K−1DK(K+1)(1−α)2\frac{K-1}{DK(K+1)}(1-\sqrt{\alpha})^2, at N∗=2.25 D2K/(1−α)4N^* = 2.25\,D^2K/(1-\sqrt{\alpha})^4, i.e. at N∼D2KN \sim D^2K up to an α\alpha-dependent constant. This criterion is heuristic, but the scale is confirmed by the eigenvectors: the overlap between the bulk eigenvector subspaces of M^2\widehat{M}_2 and M2M_2 rises from its random value (D−1)/(K−1)(D-1)/(K-1) to one around N/(D2K)=O(1)N/(D^2K)=O(1) (Figure 8, right). For the four-token moment the same bound has a variance proxy of order K−2K^{-2} and gives a noise level of order (NK2)−1/2(NK^2)^{-1/2}, so the spike at K−2K^{-2} is resolved at N∼K2N \sim K^2, the linear block at N∼K4N \sim K^4 and the quadratic block, of scale 1/(DK2)1/(DK^2), at N∼D2K2N \sim D^2K^2; extrapolating, the bulk of M2mM_{2m} sits at 1/(DKm)1/(DK^m) against a noise of (NKm)−1/2(NK^m)^{-1/2}, and its resolution takes N∼D2KmN \sim D^2K^m.

Experimental details

This appendix specifies the transformer experiments of § 5. The code to reproduce them is available at https://github.com/fracagnetta/random-topic-model.

Data. Every run draws its own topic matrix PP, with DD topics from Dir⁡K(1)\operatorname{Dir}_K(1) and uniform topic weights, and from it NN training documents and 32 768 validation documents; a further 32 768 OOD documents are generated from 16 fresh topics, drawn independently of PP from the same prior. Each point of a learning curve averages four runs with independent topic matrices, test ID and OOD corpora and initialisation, and error bars are standard errors over the four. Documents carry T+1T+1 tokens: the model reads the first TT and is trained to predict tokens 2 to T+1T+1, so that its loss profile covers context lengths 1 to TT, the TT-gram loss is the loss at context length TT, and the autoregressive loss is the average of the profile over the TT positions.

Model. A one-block decoder-only transformer: token embeddings of dimension dembd_{\mathrm{emb}} with no positional embedding, so that the causal mask is the only source of order, as befits documents that are exchangeable given their topic; one causal self-attention head; a ReLU multilayer perceptron with one hidden layer of width 4demb4d_{\mathrm{emb}}; both sub-layers pre-normalised and residual; a final layer normalisation and an untied linear readout to the KK logits. Attention and perceptron carry no biases and there is no dropout. The model has 12demb2+2Kdemb+O(demb)12d_{\mathrm{emb}}^2+2Kd_{\mathrm{emb}}+O(d_{\mathrm{emb}}) parameters, from 5×1045\times10^4 at (K,demb)=(32,64)(K,d_{\mathrm{emb}})=(32,64) to 3×1063\times10^6 at (128,512)(128,512). Weights are initialised as standard normals and each linear map is scaled by the inverse square root of its input dimension, the readout by 1/demb1/d_{\mathrm{emb}}.

Training. The loss is the cross-entropy of the next token, averaged over the TT positions and the documents of a batch. Batches of bb documents are taken cyclically from the corpus and the parameters are updated with Adam, moment parameters (0.9,0.999)(0.9,0.999) and no weight decay, at a learning rate η\eta raised linearly from zero over the first 8 steps and constant thereafter, for a fixed number of passes over the corpus.

Evaluation and early stopping. The validation autoregressive loss is measured at log-spaced steps throughout training. The checkpoint of lowest validation loss defines early stopping, and its loss is the value that enters the ID learning curves (Figure 1, Figure 3, Figure 9). At a coarser log-spaced subset of the steps the full loss profiles on the validation and on the OOD documents are recorded as well. The TT-gram ID loss of a run (Figure 10) is the minimum over these recorded checkpoints of the loss at context length TT; the OOD losses are read either at the recorded checkpoint of lowest validation loss, “at early stopping” (Figure 1, Figure 4), or minimised over the recorded checkpoints, “best over training” (Figure 1, Figure 5), as stated in each caption.

Learning curves at different document lengths

Figure 9. Learning curves at different document lengths collapse on the number of tokens per parameter. Left: Scaled ID autoregressive loss (LAR(N)−LAR(∞))/(log⁡K−LAR(∞))(\mathcal{L}_{\mathrm{AR}}(N) - \mathcal{L}_{\mathrm{AR}}(\infty))/(\log K - \mathcal{L}_{\mathrm{AR}}(\infty)) versus number of training sequences for one-block transformers trained on random topic model data with K=128K = 128, D=16D = 16 and T=128,256,512T = 128, 256, 512 (colour). LAR(∞)\mathcal{L}_{\mathrm{AR}}(\infty) is the autoregressive loss of the specialised predictor at each TT, averaged over 32 realisations of the topic matrix. Right: Against NT/(DK)NT/(DK) the three curves coincide: at fixed NN, longer documents bring the loss closer to its floor in proportion to the number of tokens they contribute.

Hyperparameter selection. The embedding dimension, batch size, learning rate and training budget are selected separately for every (K,D,T,N)(K, D, T, N) on the validation loss at early stopping, so that each learning curve reports the best model of the family rather than a fixed architecture, and the model is not the bottleneck of the comparison with the Bayes-optimal learning curves. The grid is dembd_{\mathrm{emb}} from KK to 512 in powers of two, b∈{16,32,64,128}b \in\{16, 32, 64, 128\} and η∈{10−2,3×10−2,10−1}\eta\in\{10^{-2}, 3 \times10^{-2}, 10^{-1}\}; larger dictionaries require larger dembd_{\mathrm{emb}}, and the selected width grows with DD at fixed KK. The number of passes is extended until the early-stopping checkpoint falls well inside the budget, or until a doubling of the budget improves the validation loss by less than the spread over seeds. A candidate combination replaces the incumbent only when its early-stopping validation loss, over four fresh seeds, is lower beyond the standard errors, or tied with a clearly earlier early-stopping step. The combination selected on the ID validation loss serves for every quantity reported at that (K,D,T,N)(K, D, T, N), including the OOD losses, which play no role in the selection.

Additional figures

References

  1. [1]Ekin Akyürek, Dale Schuurmans, Jacob Andreas, Tengyu Ma, and Denny Zhou. What learning algorithm is in-context learning? investigations with linear models. In The Eleventh International Conference on Learning Representations, 2023. URL https://openreview.net/forum?id=Og0X4H8yN4I.arxiv.org/abs/2211.15661
  2. [2]Elizabeth S. Allman, Catherine Matias, and John A. Rhodes. Identifiability of parameters in latent structure models with many observed variables. The Annals of Statistics, 37(6A):3099–3132, 2009. URL http://www.jstor.org/stable/25662188.DOI
  3. [3]Animashree Anandkumar, Rong Ge, Daniel Hsu, Sham M. Kakade, and Matus Telgarsky. Tensor decompositions for learning latent variable models. J. Mach. Learn. Res., 15(1):2773–2832, 2014. doi: 10.5555/2627435.2697055. URL https://dl.acm.org/doi/10.5555/2627435.2697055.
  4. [4]Usman Anwar, Abulhair Saparov, Javier Rando, Daniel Paleka, Miles Turpin, Peter Hase, Ekdeep Singh Lubana, Erik Jenner, Stephen Casper, Oliver Sourbut, Benjamin L. Edelman, Zhaowei Zhang, Mario Günther, Anton Korinek, Jose Hernandez-Orallo, Lewis Hammond, Eric J Bigelow, Alexander Pan, Lauro Langosco, Tomas Korbak, Heidi Chenyu Zhang, Ruqia Zhong, Sean O hEigeartaigh, Gabriel Recchia, Giulio Corsi, Alan Chan, Markus Anderljung, Lilian Edwards, Aleksandar Petrov, Christian Schroeder de Witt, Sumeet Ramesh Motwani, Yoshua Bengio, Danqi Chen, Philip Torr, Samuel Albanie, Tegan Maharaj, Jakob Nicolaus Foerster, Florian Tramèr, He He, Atoosa Kasirzadeh, Yejin Choi, and David Krueger. Foundational challenges in assuring alignment and safety of large language models. Transactions on Machine Learning Research, 2024. ISSN 2835-8856. URL https://openreview.net/forum?id=oVTkOs8Pka. Survey Certification, Expert Certification.
  5. [5]Borja Balle, William L. Hamilton, and Joelle Pineau. Methods of moments for learning stochastic languages: unified presentation and empirical comparison. In Proceedings of the 31st International Conference on Machine Learning, volume 32, pp. 1386–1394. PMLR, 2014.
  6. [6]Jean Barbier, Francesco Camilli, Minh-Toan Nguyen, Mauro Pastore, and Rudy Skerk. Optimal generalisation and learning transition in extensive-width shallow neural networks near interpolation. arXiv preprint arXiv:2501.18530, 2025.DOI
  7. [7]Marco Bondaschi, Nived Rajaraman, Xiuying Wei, Razvan Pascanu, Caglar Gulcehre, Michael Gastpar, and Ashok Vardhan Makkvva. From markov to laplace: How mamba in-context learns markov chains. In The Fourteenth International Conference on Learning Representations, 2026. URL https://openreview.net/forum?id=kmK3WSC0CT.arxiv.org/abs/2502.10178
  8. [8]Blake Bordelon, Mary Letey, and Cengiz Pehlevan. Theory of scaling laws for in-context regression: Depth, width, context and time. In The Fourteenth International Conference on Learning Representations, 2026. URL https://openreview.net/forum?id=qA42mWsnbJ.arxiv.org/abs/2510.01098
  9. [9]Tom Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah, Jared D. Kaplan, Prafulla Dhariwal, Arvind Neelakantan, Pranav Shyam, Girish Sastry, Amanda Askell, Sandhini Agarwal, Ariel Herbert-Voss, Gretchen Krueger, Tom Henighan, Rewon Child, Aditya Ramesh, Daniel M. Ziegler, Jeffrey Wu, Clemens Winter, Chris Hesse, Mark Chen, Eric Sigler, Mateusz Litwin, Scott Gray, Benjamin Chess, Jack Clark, Christopher Berner, Sam McCandlish, Alec Radford, Ilya Sutskever, and Dario Amodei. Language models are few-shot learners. In Advances in Neural Information Processing Systems, volume 33, pp. 1877–1901, 2020. URL https://proceedings.neurips.cc/paper/2020/hash/1457c0d6bfcb4967418bfb8ac142f64a-Abstract.html.arxiv.org/abs/2005.14165
  10. [10]Francesco Cagnetta, Allan Raventos, Surya Ganguli, and Matthieu Wyart. Deriving neural scaling laws from the statistics of natural language. In Forty-third International Conference on Machine Learning, 2026. URL https://openreview.net/forum?id=VX1nIX0C5y.arxiv.org/abs/2602.07488
  11. [11]Liam Carroll, Jesse Hoqgland, Matthew Farrugia-Roberts, and Daniel Murfet. Dynamics of transient structure in in-context linear regression transformers. arXiv preprint arXiv:2501.17745, 2025.arxiv.org/abs/2501.17745
  12. [12]Djalil Chafaï and Konstantin Tikhomirov. On the convergence of the extremal eigenvalues of empirical covariance matrices with dependence. Probability Theory and Related Fields, 170:847–889, 2018. doi: 10.1007/s00440-017-0778-9. URL https://arxiv.org/abs/1509.02231.
  13. [13]Bertrand S. Clarke and Andrew R. Barron. Information-theoretic asymptotics of Bayes methods. IEEE Transactions on Information Theory, 36(3):453–471, 1990. doi: 10.1109/18.54897. URL https://bertrandsclarke.weebly.com/uploads/2/7/3/6/2736392/clarkebarron1990.pdf.DOI
  14. [14]Bertrand S. Clarke and Andrew R. Barron. Jeffreys’ prior is asymptotically least favorable under entropy risk. Journal of Statistical Planning and Inference, 41(1):37–60, 1994. doi: 10.1016/0378-3758(94)90153-8. URL https://doi.org/10.1016/0378-3758(94)90153-8.
  15. [15]Ezra Edelman, Nikolaos Tsilivis, Benjamin L. Edelman, eran malach, and Surbhi Goel. The evolution of statistical induction heads: In-context learning markov chains. In The Thirty-eighth Annual Conference on Neural Information Processing Systems, 2024. URL https://openreview.net/forum?id=qaRT6QTIqJ.arxiv.org/abs/2402.11004
  16. [16]Alessandro Favero, Antonio Sclocchi, and Matthieu Wyart. Bigger isn’t always memorizing: Early stopping overparameterized diffusion models. arXiv preprint arXiv:2505.16959, 2025.arxiv.org/abs/2505.16959
  17. [17]Shivam Garg, Dimitris Tsipras, Percy Liang, and Gregory Valiant. What can transformers learn in-context? a case study of simple function classes. In Advances in Neural Information Processing Systems, 2022. URL https://openreview.net/forum?id=f1NZJ2eOet.arxiv.org/abs/2208.01066
  18. [18]Cole Gibson, Wenping Cui, and Gautam Reddy. Distinct mechanisms underlying in-context learning in transformers. arXiv preprint arXiv:2604.12151, 2026.arxiv.org/abs/2604.12151
  19. [19]Sebastian Goldt, Madhu Advani, Andrew M. Saxe, Florent Krzakala, and Lenka Zdeborová. Dynamics of stochastic gradient descent for two-layer neural networks in the teacher-student setup. In Advances in Neural Information Processing Systems, volume 32, 2019.
  20. [20]Roee Hendel, Mor Geva, and Amir Globerson. In-context learning creates task vectors. In The 2023 Conference on Empirical Methods in Natural Language Processing, 2023. URL https://openreview.net/forum?id=QYvFULF19n.
  21. [21]Daniel Hsu, Sham M. Kakade, and Tong Zhang. A spectral algorithm for learning hidden Markov models. Journal of Computer and System Sciences, 78(5):1460–1480, 2012.arxiv.org/abs/0811.4413
  22. [22]Joseph B. Kruskal. Three-way arrays: rank and uniqueness of trilinear decompositions, with application to arithmetic complexity and statistics. Linear algebra and its applications, 18(2):95–138, 1977. doi: 10.1016/0024-3795(77)90069-6. URL https://linkinghub.elsevier.com/retrieve/pii/0024379577900696.DOI
  23. [23]Mary Letey, Jacob A Zavatone-Veth, Yue M. Lu, and Cengiz Pehlëvan. Pretrain–test task alignment governs generalization in in-context learning. In The Fourteenth International Conference on Learning Representations, 2026. URL https://openreview.net/forum?id=KZLeg0MQ2r.arxiv.org/abs/2509.26551
  24. [24]Yue M. Lu, Mary Letey, Jacob A. Zavatone-Veth, Anindita Maiti, and Cengiz Pehlëvan. Asymptotic theory of in-context learning by linear attention. Proceedings of the National Academy of Sciences, 122(28):e2502599122, 2025. doi: 10.1073/pnas.2502599122. URL https://www.pnas.org/doi/abs/10.1073/pnas.2502599122.DOI
  25. [25]Alex Nguyen and Gautam Reddy. Differential learning kinetics govern the transition from memorization to generalization during in-context learning. In The Thirteenth International Conference on Learning Representations, 2025. URL https://openreview.net/forum?id=INyiI7qUdjZ.arxiv.org/abs/2412.00104
  26. [26]Eshaan Nichani, Alex Damian, and Jason D. Lee. How transformers learn causal structure with gradient descent. In Forty-first International Conference on Machine Learning, 2024. URL https://openreview.net/forum?id=jNM4imlHZv.arxiv.org/abs/2402.14735
  27. [27]Alain Pajor and Leonid Pastur. On the limiting empirical measure of eigenvalues of the sum of rank one matrices with log-concave distribution. Studia Mathematica, 195(1):11–29, 2009. doi: 10.4064/sm195-1-2. URL https://arxiv.org/abs/0710.1346.
  28. [28]Core Francisco Park, Ekdeep Singh Lubana, and Hidenori Tanaka. Competition dynamics shape algorithmic phases of in-context learning. In The Thirteenth International Conference on Learning Representations, 2025. URL https://openreview.net/forum?id=XgH1wEHSX8.arxiv.org/abs/2412.01003
  29. [29]Allan Raventos, Mansheej Paul, Feng Chen, and Surya Ganguli. Pretraining task diversity and the emergence of non-bayesian in-context learning for regression. In Thirty-seventh Conference on Neural Information Processing Systems, 2023. URL https://openreview.net/forum?id=BtAz4a5xDg.arxiv.org/abs/2306.15063
  30. [30]Kyle J. Ray, Paul M. Riechers, and Adam S. Shai. The geometry of nonergodic composition. Belief Updates (Simplex Blog), 2026. URL https://belief-updates.pub/nonergodic-geometry/.
  31. [31]Gautam Reddy. The mechanistic basis of data dependence and abrupt learning in an in-context classification task. In The Twelfth International Conference on Learning Representations, 2024. URL https://openreview.net/forum?id=aN4Jf6Cx69.arxiv.org/abs/2312.03002
  32. [32]Paul M Riechers, Henry R Bigelow, Eric A Alt, and Adam Shai. Next-token pretraining implies in-context learning. arXiv preprint arXiv:2505.18373, 2025.arxiv.org/abs/2505.18373
  33. [33]Adam Shai, Paul M. Riechers, Lucas Teixeira, Alexander Gietelink Oldenziel, and Sarah Marzen. Transformers represent belief state geometry in their residual stream. In The Thirty-eighth Annual Conference on Neural Information Processing Systems, 2024. URL https://openreview.net/forum?id=YIB7REL8UC.arxiv.org/abs/2405.15943
  34. [34]Murray Shanahan, Kyle McDonell, and Laria Reynolds. Role play with large language models. Nature, 623(7987):493–498, 2023.arxiv.org/abs/2305.16367
  35. [35]Aaditya K Singh, Stephanie C.Y. Chan, Ted Moskovitz, Erin Grant, Andrew M Saxe, and Felix Hill. The transient nature of emergent in-context learning in transformers. In Thirty-seventh Conference on Neural Information Processing Systems, 2023. URL https://openreview.net/forum?id=Of0GBzow8P.arxiv.org/abs/2311.08360
  36. [36]Joel A. Tropp. User-friendly tail bounds for sums of random matrices. Foundations of computational mathematics, 12(4):389–434, 2012. doi: 10.1007/s10208-011-9099-z. URL https://link.springer.com/content/pdf/10.1007/s10208-011-9099-z.pdf.DOI
  37. [37]Daniel Wurgaft, Ekdeep Singh Lubana, Core Francisco Park, Hidenori Tanaka, Gautam Reddy, and Noah Goodman. In-context learning strategies emerge rationally. In The Thirty-ninth Annual Conference on Neural Information Processing Systems, 2025. URL https://openreview.net/forum?id=bBUUOQION6.
  38. [38]Sang Michael Xie, Aditi Raghunathan, Percy Liang, and Tengyu Ma. An explanation of in-context learning as implicit bayesian inference. In International Conference on Learning Representations, 2022. URL https://openreview.net/forum?id=RdJVFCHjUMI.arxiv.org/abs/2111.02080
  39. [39]Hao Yan, Haolin Yang, and Yiqiao Zhong. Task vector geometry underlies dual modes of task inference in transformers. arXiv preprint arXiv:2605.03780, 2026.arxiv.org/abs/2605.03780
  40. [40]Yedi Zhang, Aaditya K Singh, Peter E. Latham, and Andrew M Saxe. Training dynamics of in-context learning in linear attention. In Forty-second International Conference on Machine Learning, 2025. URL https://openreview.net/forum?id=aFNq6711os.arxiv.org/abs/2501.16265

Paper details

vlnc:W_q5ggdx6t
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 11

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Computer Science

generative AI tools

View statement
Looking for related papers…
Contents