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
- 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.

Task inference and input memorization
Each task hides a coefficient pair and supplies numerical examples of a modular linear function:
All values belong to ; 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 , predictions from posterior samples define
Here 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 and training-input fractions . Both methods achieve high accuracy on unseen tasks with seen inputs at and . Laplace generalizes across a broader range of configurations when both tasks and inputs are unseen; IVON performs competitively there at high training fractions.


The inference-time sweeps fix 64 base tasks, expanded to 256 by parallelogram augmentation, and . 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.

Replacing context answers with uniformly random tokens, with probability , 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.

Slow spectral modes explain a delay in a linear model
For Gaussian linear regression, let contain the training inputs, be likelihood variance, and prior variance. Gaussian variational inference has an exact Bures-Wasserstein flow:
Here and are the weight mean and covariance, and 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 with , the lower Marchenko-Pastur edge controls late-time excess risk . Matched interpolation assumes the stationary mean equals the teacher weights and the stationary training residual vanishes. Thresholding squared residuals at tolerance gives a binary success event whose entropy is entirely epistemic. Using the effective Gaussian residual approximation,
Here is binary entropy and 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.

