TL;DR
When transformers learn in-context, they act like approximate Bayesian reasoners—but figuring out what they actually believe about a hidden task just by looking at their next-token predictions is surprisingly error-prone. This paper repurposes a statistical technique called Predictive Monte Carlo (PMC) to extract a transformer's internal prior and posterior beliefs directly, using nothing more than standard next-token rollouts. It turns out that letting a model "dream" into the future reveals the shape of its beliefs in ways single-step predictions completely miss.
What Problem Does This Paper Address?
To study in-context learning (ICL) in a clean lab setting, researchers often train transformers on synthetic data generated in two steps: first, sample a hidden "task" (like a coin’s bias or regression weights) from a prior distribution; second, generate a sequence of observations from that task. A transformer trained on this data—which the authors coin a Bayes-filtered transformer (BFT)—theoretically learns to output the exact Bayesian posterior predictive distribution.
In reality, finite models only approximate Bayes' rule. So, what prior and posterior has a trained BFT actually internalized? Is it memorizing the finite set of $M$ tasks it saw during training, or generalizing to the continuous population of tasks?
Until now, researchers answered this in prediction space: feed the model a prompt, look at its next-token prediction, and see which theoretical baseline it matches. The catch? Prediction-space comparisons are fragile. Two wildly different internal beliefs (say, a smooth Gaussian vs. a bimodal spike-and-slab posterior) can share the exact same mean—producing identical point predictions while hiding completely different underlying worldviews.
Methods
To peer directly into latent space without cracking open the model's weights or training linear probes, the authors borrow Predictive Monte Carlo (PMC) from Bayesian predictive inference and turn it into a black-box interpretability tool.
The intuition comes from de Finetti’s theorem: if a sequence is exchangeable (order doesn't matter), imagining an infinitely long continuation of that sequence reveals the hidden parameter governing it. PMC operationalizes this in two steps using only forward passes:
- Rollout: Given a prompt of length $\ell$, autoregressively generate $N$ future tokens from the BFT (feeding each sampled token back into the context).
- Evaluate: Estimate the latent task parameter on the completed sequence (e.g., take the sample mean of coin flips, or run Ordinary Least Squares on $(x,y)$ pairs).
Repeat this $R$ times independently, and the resulting histogram of $R$ estimates forms the PMC posterior—an approximation of the model's implicit belief given the prompt. Do the exact same thing starting from an empty prompt, and you get the model's PMC prior!
Datasets
Rather than static benchmarks, BFTs are trained on freshly sampled synthetic sequences where exact Bayesian baselines are mathematically tractable. The authors unify three classic ICL testbeds under the umbrella of $k$-Markov exchangeability:
- Balls-and-urns ($0$-Markov / exchangeable): Categorical token sequences drawn from a Dirichlet prior.
- In-context linear regression ($0$-Markov): Sequences of $(x, y)$ pairs with Gaussian covariates and weights drawn from a standard normal prior $\mathcal{N}(0, I_d)$.
- Markov chains ($1$-Markov exchangeable): Sequences governed by random transition matrices with row-wise Dirichlet priors.
Each setup is trained across varying levels of task diversity ($M$)—restricting pretraining to $M$ fixed tasks—and evaluated on both in-distribution prompts (seen tasks) and out-of-distribution prompts (novel tasks) of length $\ell = 32$.
Key Insights and Ideas
- Unifying synthetic ICL: Seemingly disparate ICL studies (regression, urns, Markov chains) are all instances of $k$-Markov exchangeable BFTs, allowing one interpretability framework to rule them all.
- Black-box belief extraction: You don't need ground-truth labels or internal activations to see what a transformer believes; its long-horizon rollouts are its latent beliefs made manifest.
- Latent space catches what prediction space misses: In categorical tasks like balls-and-urns, next-token probabilities depend only on the posterior mean. PMC exposes the full distribution—variance, multimodality, and spikes around memorized tasks—detecting behavioral shifts at lower task diversities than prediction metrics can.
Key Results
Across all three task families, PMC cleanly reproduces famous ICL phenomena directly in latent space (measured via Energy Distance and Sliced Wasserstein-1 distance):
- Exact prior/posterior recovery: At low task diversity (e.g., $M = 8$ in linear regression, $M = 4$ in Markov chains), the BFT's PMC prior visibly clusters around the exact discrete atoms of the memorized training tasks ($\Pi_M$).
- Task-diversity threshold: Sweeping $M$ upward shows the PMC posterior smoothly transitioning from the memorizing baseline to the generalizing population posterior. In balls-and-urns, latent-space metrics catch this transition earlier (at smaller $M$) than prediction-space KL divergence.
- Transient generalization: Tracking training dynamics at intermediate diversity ($M = 32$ for regression and urns; $M = 8$ for Markov chains) confirms that BFTs initially learn the broad generalizing posterior early in training before eventually specializing to memorize the $M$ training tasks.
Limitations and Future Work
- Theoretical guarantees are tough to verify: PMC formally relies on the model's predictions being exchangeable (or asymptotically exchangeable). Real neural networks rarely satisfy strict symmetry, and empirically verifying asymptotic exchangeability requires massive Monte Carlo budgets. Moreover, an asymptotic theory for $k$-Markov exchangeability ($k \ge 1$) doesn't exist yet.
- Compute overhead: While prediction-space evaluation takes 1 forward pass per prompt, PMC takes $R \cdot N$ forward passes (though the $R$ rollouts can be batched in parallel over $N$ sequential steps).
- Future outlook: While scaling directly to frontier LLMs remains an open question, BFTs + PMC offer a clean "model organism" for studying murky LLM behaviors. For instance, training a BFT on a mixture of behavioral personas could let researchers use PMC to watch how narrow finetuning shifts latent persona beliefs during emergent misalignment.
Summary updated