← All publications

A Bayesian Perspective on the Role of Epistemic Uncertainty for Delayed Generalization in In-Context Learning

  • Bayesian Deep Learning
  • Uncertainty Quantification
  • Large Language Models
  • Deep Learning Theory

We study delayed generalization in modular-arithmetic in-context learning and find that epistemic uncertainty changes sharply near the grokking transition, with supporting analysis in a Bayesian linear model.

Paper ProbML Workshop 2026

Abdessamed Qchohi1, Simone Rossi1

  1. EURECOM

A transformer can memorize training examples long before it learns to infer an unfamiliar task from a prompt. We study this delayed generalization, called grokking, through disagreement among approximate posterior weight samples. On modular arithmetic tasks, epistemic uncertainty rises and then collapses around the transition to generalization. A tractable Bayesian linear model links the delay in accuracy and uncertainty to slowly learned spectral modes, while distinguishing their transition times.

Presented at the ProbML 2026 Workshop Track as A Bayesian perspective on learning to grok in-context examples.

Transformer accuracy and epistemic uncertainty beside the corresponding curves for the simplified linear model
Accuracy and epistemic uncertainty in the transformer and simplified model. The uncertainty peak precedes the marked accuracy threshold in both, motivating a shared account of their delayed transitions.

Task inference and input memorization

Each task hides a coefficient pair (a,b)(a,b) and supplies numerical examples of a modular linear function:

zi=(axi+byi) mod 29,prompt=(x1,y1,z1),…,(xt−1,yt−1,zt−1),(xt,yt,?).\begin{aligned} z_i &= (a x_i+b y_i)\bmod 29,\\ \text{prompt} &= (x_1,y_1,z_1),\ldots,(x_{t-1},y_{t-1},z_{t-1}),(x_t,y_t,?). \end{aligned}

All values belong to {0,…,28}\{0,\ldots,28\}; the model must infer the coefficients from preceding triples to predict the final answer. We independently withhold coefficient pairs and input pairs. In-distribution (ID) validation tests unseen inputs on seen tasks. Out-of-distribution (OOD) Train tests unseen tasks on seen inputs, and OOD validation withholds both. This separation makes task inference and input memorization independently observable.

We use a six-layer decoder-only transformer with width 512, four attention heads, rotary positional embeddings, and tied embeddings. Training supervises answer positions in sequences of 32 triples. The experiments report medians and 95% quantile intervals over four seeds.

Disagreement over predictions

Improved Variational Online Newton (IVON) learns a diagonal Gaussian over all weights during training. Last-Layer Laplace fits a Gaussian to the final layer of an AdamW-trained model, using Kronecker-factored curvature and fixed preceding layers. For a prompt x\boldsymbol{x}, predictions from SS posterior samples θ(s)\boldsymbol{\theta}^{(s)} define

pˉ(y∣x)=1S∑s=1Sp(y∣x,θ(s)),EU(x)=H[pˉ]−1S∑s=1SH[p(y∣x,θ(s))]⏟AU(x).\begin{aligned} \bar p(\boldsymbol{y}\mid\boldsymbol{x}) &=\frac1S\sum_{s=1}^{S}p(\boldsymbol{y}\mid\boldsymbol{x},\boldsymbol{\theta}^{(s)}),\\ \mathrm{EU}(\boldsymbol{x}) &=\mathbb H[\bar p] -\underbrace{\frac1S\sum_{s=1}^{S}\mathbb H[p(\boldsymbol{y}\mid\boldsymbol{x},\boldsymbol{\theta}^{(s)})]}_{\mathrm{AU}(\boldsymbol{x})}. \end{aligned}

Here H\mathbb H denotes entropy. Total uncertainty measures the spread of the averaged prediction; the aleatoric term averages individual entropies; their difference measures disagreement across weights. Computing these quantities requires the prompt and sampled predictions, with no query label. Their values depend on the posterior approximation.

Our uncertainty-scaling study uses the same entropy decomposition to examine how predictive disagreement changes with training-set size.

Task diversity changes generalization and uncertainty together

We sweep effective task counts T∈{32,64,128,256,512}T\in\{32,64,128,256,512\} and training-input fractions α∈{0.3,0.4,0.5,0.6,0.7,0.8}\alpha\in\{0.3,0.4,0.5,0.6,0.7,0.8\}. Both methods achieve high accuracy on unseen tasks with seen inputs at T=256T=256 and 512512. Laplace generalizes across a broader range of configurations when both tasks and inputs are unseen; IVON performs competitively there at high training fractions.

Accuracy heatmaps for IVON and Laplace on ID validation, OOD Train, and OOD validation across task counts and training fractions
Generalization across task diversity and training fraction. The two methods agree on the benefit of many tasks, while Laplace covers a wider region of successful OOD validation, showing that posterior construction and training matter.
Stacked epistemic and aleatoric uncertainty for both posterior approximations across the same task and training-fraction grid
Uncertainty decomposition across task counts and training fractions. Epistemic uncertainty falls at the higher task counts where generalization emerges, while the aleatoric component can remain substantial. The agreement links the predictive diagnostic to the accuracy landscape.

The inference-time sweeps fix 64 base tasks, expanded to 256 by parallelogram augmentation, and α=0.8\alpha=0.8. Increasing context from one to 32 examples improves accuracy overall and reduces aleatoric uncertainty. Epistemic uncertainty initially rises before falling, exposing a non-monotonic response to additional context.

Accuracy, epistemic uncertainty, and aleatoric uncertainty as context length increases for IVON and Laplace
Context-length sweep with fixed trained weights. Accuracy improves with additional examples, while epistemic uncertainty first rises and then declines. The curves distinguish task evidence at inference from data supplied during training.

Replacing context answers with uniformly random tokens, with probability pnoisep_{\mathrm{noise}}, lowers accuracy and raises both uncertainty components. Inputs and evaluation targets remain clean. Laplace's epistemic uncertainty rises more strongly than IVON's, illustrating method-dependent sensitivity to misleading prompts.

Accuracy and uncertainty under increasing corruption of context answer tokens, with clean final queries
Context-label corruption from probability zero to one. Both uncertainty components rise as accuracy deteriorates, with a stronger epistemic response for Laplace. In this setting, the decomposition responds to uncertainty about the task encoded by the prompt.

Slow spectral modes explain a delay in a linear model

For Gaussian linear regression, let X∈Rn×d\boldsymbol{X}\in\mathbb R^{n\times d} contain the training inputs, σ2\sigma^2 be likelihood variance, and τ2\tau^2 prior variance. Gaussian variational inference has an exact Bures-Wasserstein flow:

qt(w)=N(μt,Σt),μ˙t=b−Aμt,Σ˙t=2I−AΣt−ΣtA,A=σ−2X⊤X+τ−2I,b=σ−2X⊤y.\begin{aligned} q_t(\boldsymbol{w})&=\mathcal N(\boldsymbol{\mu}_t,\boldsymbol{\Sigma}_t),\\ \dot{\boldsymbol{\mu}}_t&=\boldsymbol{b}-\boldsymbol{A}\boldsymbol{\mu}_t,\\ \dot{\boldsymbol{\Sigma}}_t&=2\boldsymbol{I}-\boldsymbol{A}\boldsymbol{\Sigma}_t-\boldsymbol{\Sigma}_t\boldsymbol{A},\\ \boldsymbol{A}&=\sigma^{-2}\boldsymbol{X}^{\top}\boldsymbol{X}+\tau^{-2}\boldsymbol{I}, \qquad\boldsymbol{b}=\sigma^{-2}\boldsymbol{X}^{\top}\boldsymbol{y}. \end{aligned}

Here μt\boldsymbol{\mu}_t and Σt\boldsymbol{\Sigma}_t are the weight mean and covariance, and y\boldsymbol{y} contains responses. The same precision operator drives both dynamics. Training risk downweights small sample-covariance eigenvalues, while population risk retains their contribution. Those slow modes therefore delay generalization.

Under isotropic Gaussian design, matched interpolation, self-averaging initialization, and n,d→∞n,d\to\infty with λ=d/n<1\lambda=d/n<1, the lower Marchenko-Pastur edge controls late-time excess risk L~(t)\widetilde{\mathcal L}(t). Matched interpolation assumes the stationary mean equals the teacher weights and the stationary training residual vanishes. Thresholding squared residuals at tolerance ϵ\epsilon gives a binary success event whose entropy is entirely epistemic. Using the effective Gaussian residual approximation,

EUth(t)≈h2 ⁣(erf⁡ϵ4L~(t)),ΔtEU,peak(λ)≃log⁡ ⁣(11−λ)nσ2(1−λ)2+1τ2.\begin{aligned} \mathrm{EU}_{\mathrm{th}}(t) &\approx h_2\!\left(\operatorname{erf}\sqrt{\frac{\epsilon}{4\widetilde{\mathcal L}(t)}}\right),\\ \Delta t_{\mathrm{EU,peak}}(\lambda) &\simeq\frac{\log\!\left(\frac{1}{1-\sqrt\lambda}\right)} {\frac{n}{\sigma^2}(1-\sqrt\lambda)^2+\frac1{\tau^2}}. \end{aligned}

Here h2h_2 is binary entropy and ΔtEU,peak\Delta t_{\mathrm{EU,peak}} separates population and training peaks, provided both occur in the late-time regime. The peak occurs at 50% thresholded success, before the 95% accuracy criterion; both delays share the leading spectral scaling.

Four panels showing linear-model accuracy, epistemic uncertainty, transition times, and uncertainty-peak delay as aspect ratio increases
Simplified-model dynamics. As λ\lambda approaches one, training and population transitions separate. The entropy peak precedes the accuracy threshold, while the asymptotic expression captures the growing delay between training and population peaks.
Held-out-task transformer accuracy reaches high values after a peak in epistemic uncertainty during training
A representative transformer trajectory on OOD validation. The uncertainty peak precedes attainment of high accuracy, providing an empirical counterpart to the ordering of milestones in the thresholded linear model.