What does a Bayes-filtered transformer believe? A predictive Monte Carlo approach

Afiq Abdillah Effiezal Aswadi, Haotong Ma, Susan WeiNeurIPS 2026

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.

Figure 2: Prediction-space measurement is fragile. 2-D Bayesian linear regression: posterior over the coefficient w ∈R2 given a single observation (x1, y1) = ([1, 1], 1), computed under two different priors. The Gaussian and spike-and-slab priors yield posteriors that share the mean (0.5, 0.5) (marked ×) but differ in shape (left, middle). At the test query x′ = [1, −1], the two predictive distributions over y′ are unimodal vs bimodal (right), yet the posterior-mean predictions coincide. A comparison of posterior means therefore cannot distinguish the two posteriors.

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:

  1. Rollout: Given a prompt of length $\ell$, autoregressively generate $N$ future tokens from the BFT (feeding each sampled token back into the context).
  2. 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!

PMC schematic: rolling out R future sequences from a prompt and taking their sample means recovers the BFT's implicit prior and posterior.

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$).
In linear regression trained on M=8 tasks, PMC rollouts from an empty prompt concentrate sharply around the 8 memorized training tasks (green lines) rather than the smooth population prior.
  • 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

Abstract

A \emph{Bayes-filtered transformer} (BFT) is a transformer trained on sequences that are generated in two steps: first a latent task is drawn from a prior, then observations are drawn conditional on that task. Trained under autoregressive log loss, the BFT's next-token prediction, in the idealized limit, \emph{is} the Bayesian posterior predictive distribution (PPD) induced by that prior and that conditional law. In practice the trained BFT is only an approximation of this ideal PPD, raising an interpretive question: what prior and posterior over the latent task has the trained BFT actually internalized? Existing work answers this question by comparing the trained BFT's predictions against the predictions of various ``reference'' posteriors, each standing in for a different candidate algorithm or computation the BFT might be implementing. This prediction-space comparison is fragile: different posteriors can share the same posterior-mean predictions. We use \emph{predictive Monte Carlo} (PMC) as an interpretability tool for BFTs: using only next-token generation, we obtain with PMC an approximation to the implicit prior and posterior over the latent task, answering the interpretive question directly in latent space. We apply PMC to three stylized task families spanning 0-Markov and 1-Markov exchangeability. We reproduce previously reported phenomena in latent space and show that comparisons of PMC priors and posteriors can reveal patterns in model behavior that the corresponding prediction-space comparisons miss. Code is available at \url{https://github.com/afiq-aswadi/bft-pmc}.
BibTeX
@inproceedings{aswadi2026what,
  author = {Afiq Abdillah Effiezal Aswadi and Haotong Ma and Susan Wei},
  title = {{What does a Bayes-filtered transformer believe? A predictive Monte Carlo approach}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=qZ5gMk6Gpd},
}
Figure