Manuscript Offprint
arXiv:2610.18725Learning Source Structure: Bayesian Prediction with Transformers
ABSTRACT
A transformer trained on sequences whose source parameters are drawn afresh each time can learn only what the sequences share: the source family and its prior. The Bayesian predictor that knows both, which we call informed Bayes, is the unique minimizer of the training loss and is computable from the family alone; we use it as a quantitative, falsifiable reference. Where earlier work compared transformers with Bayes on sources whose contexts can be learned independently, we build Markov sources with up to 64 symbols in which observations in one context inform prediction in another: product sources with known or hidden encodings, transition rows sharing an unknown base law and depth, and a mixture of three families. Informed Bayes is evaluated numerically from the row integrals of the layered simplex architecture. Our main result is that informed Bayes predicts, from the family and prior alone, how a trained transformer behaves in four tests that go beyond the learning curve: the loss that remains under a source outside the training family (predicted 2.237 bits, measured 2.309), the doubling of the extra loss when two independent components change rather than one (0.345 predicted, 0.350 measured), the benefit of other contexts when a token appears for the first time, and the depth at which copying an earlier continuation starts to pay. On the learning curves themselves, small transformers match informed Bayes when the shared structure is visible in the tokens, and hidden structure needs more layers and training, with gaps below 0.01 bits per token for the largest models. We explain why the imitation is possible and where it must fail: informed Bayes decomposes into sufficient statistics that attention selects and accumulates and an estimator, fixed by the prior, that the feed-forward network learns; in the architecture-as-prior framework, training pays the complexity of informed Bayes under the architecture's prior, and finite-memory universal prediction bounds how closely a bounded network can reach it.
1 INTRODUCTION
A transformer that is trained on many sequences can learn what their sources have in common. Suppose every sequence comes from a source with freshly drawn parameters. Then training cannot reveal the parameters of the next sequence. It can reveal the family of sources, and how the parameters within one source are related: each token may be a pair whose two parts follow independent chains, or all contexts may share a preference for certain tokens. A predictor that knows such a relation can pool observations across contexts. How well does a transformer learn to use this shared structure?
There is a natural yardstick. The informed Bayesian predictor, informed Bayes for short, is told the source family and the prior. It is not told the parameters of the sequence at hand; after each token it updates its posterior belief about them and averages the next-token prediction over this belief. When sequences are drawn from the family and the prior, no predictor that sees the same tokens has a smaller expected log loss. The transformer is trained to minimize this same loss and has the memory to approximate the informed Bayes. We ask two questions. How close does a transformer, which must learn the family from examples, get to informed Bayes, even in shared structure? And can this correspondence predict the transformer's behavior from what we can infer for informed Bayes?
Earlier work points out the following. The prediction over a new test sequence (prompt) was called in-context learning and has been explained as inference about a hidden source (Xie et al., 2022). Networks trained on samples from a prior learn to predict like the posterior (Müller et al., 2022). Regression experiments find Bayesian behavior within and across task families (Panwar et al., 2024). Information-theoretic work separates what is learned across tasks from what is inferred within a new task (Jeon et al., 2024). Meta-trained transformers and LSTMs were shown to reach the universal predictor of their training class (Grau-Moya et al., 2024). For sequential sources, the closest studies use Markov chains with independently drawn transition rows (Edelman et al., 2024; Bondaschi et al., 2026), smoothing across context orders (D'Angelo et al., 2026), variable-order context trees (Zhou et al., 2026), and hidden causal structures (Wei et al., 2026). None of this guarantees that a trained network reaches the Bayesian optimum; we measure in bits how close it gets when contexts are tied together (Appendix A compares these papers in detail).
In the experiments reported in this paper each of the sources tests one kind of shared structure. Coins test whether the prior on one unknown bias is learned. In product sources every token is a pair of independent coordinates. The table that maps pairs to token labels, the encoding, is either known or hidden. In the shared-base source all transition rows are built from one unknown base law and one unknown depth, so tokens seen in one context help in every other context. The uniform-base source, with a known uniform base law, is a control, and in pooled training the family itself is unknown. The Bayesian predictors are built from the row integrals of the layered simplex architecture (LSA) (Feder et al., 2026).
Our main finding is that informed Bayes predicts, in bits, how a trained transformer responds in four tests that deviate from the training conditions (Section 4; Table 1). In each test we first work out what informed Bayes does, from the family and prior alone, and then measure the transformer. Two tests change the test source: permuting the token labels of a product source, where Bayes predicts the loss that remains however long the sequence is, and replacing one or both transition matrices mid-sequence, where Bayes predicts that two new matrices cost twice as much as one. Two stay inside the training family: whether tokens seen in other contexts help when a token appears for the first time, and at which source depth copying an earlier continuation starts to pay. The transformer meets all four predictions.
The precondition for these predictions is that the transformers learn the shared structure at all, and Section 3 shows that they do. Two-layer models are close to informed Bayes when the structure is visible in the tokens: for coins, for the known encoding and for the uniform base. When the encoding or the base law is hidden, two layers are not enough, and eight-layer models trained on four times as many sequences close most of the remaining gap.
Section 5 asks why the transformer can imitate (approximately) the informed Bayes: the training objective is minimized by informed Bayes whose prediction structure is a function of some statistics of the prefix that attention can select and accumulate, leaving only a map from, e.g., counts to a forecast to be learned. In the framework where an architecture is a prior over predictors (Feder et al., 2025), training pays the complexity of informed Bayes under that transformer architecture's prior, while informed Bayes pays the complexity of the source under the family's prior. What the sources examples discussed here add is that these statistics are global rather than local, which explains which sources need more capacity and training, and where the residual gap sits.
2.1 THE SOURCE FAMILIES
All sources except the coins are first-order Markov chains; the context of a prediction is the previous token, and its transition row is the distribution of the next token. Table 2 in Appendix B summarizes, for each source, what all sequences share and what each sequence draws afresh.
Coins. The tokens are zeros and ones. Draw a bias once per sequence, then draw the tokens independently with probability of one. We use two priors in separate training conditions:
LSA row prior. The other sources draw their transition rows from the following prior (Feder et al., 2026): draw independent vectors uniformly from the simplex on symbols, multiply them entry by entry, and normalize. We write for the resulting distribution and call its depth. For the vector is uniform, for uniform on the simplex, and the larger , the more it concentrates on a few symbols.
Product source: known encoding. Each token is a pair with and . A fixed and known table, the encoding, maps the pairs to token labels. The two coordinates follow independent Markov chains, so . For each coordinate , draw a depth uniformly from , and then draw every row of independently from ; the initial coordinates are independent and uniform. We use and . The factorization helps because two matrices are learned from far fewer tokens than one matrix.
Product source: hidden encoding. Here the encoding is hidden, and it changes from sequence to sequence. For each sequence, draw every row of and of from , draw a one-to-one table uniformly at random, and run the two coordinate chains and from independent uniform starting states. The observed token is , so . The matrices and the encoding stay fixed within one sequence and are drawn anew for the next, so the same label can stand for different pairs in different sequences. Informed Bayes knows , and the sampling rule, but none of the drawn quantities; it integrates over the matrices in closed form and sums over all encodings (Appendix B.4). We use and , giving 16 labels.
Uniform-base source. Set , draw one depth uniformly from , draw each of the 64 rows independently from , and start from a uniform token. The rows share the depth and nothing else. This is the case of the next source, with a known uniform base law.
Shared-base source. Tokens are with . Draw independently an exponent uniformly from , a depth uniformly from , and a uniform random permutation of the tokens. The base law is a Zipf distribution with exponent , and assigns its ranks to the tokens:
For each context , draw a probability vector from independently, and set the transition row:
Draw from and from . One base law, one depth and one transition matrix are used for the whole sequence. For every row equals , and the tokens are independent. For every row is the shared base law , reshaped by the row's own vector . Because and are shared by all rows, tokens seen in one context help prediction in every other context.
Pooled families. For each sequence, draw one of the three 64-symbol families (product with known encoding, uniform base, shared base) with probability 1/3 each, and then draw a source from that family as above. Neither the family nor the parameters are revealed.
2.2 WHAT THE PREDICTORS KNOW
The transformer is trained by next-token prediction on sequences drawn from its family and prior, never seeing the parameters. With its weights fixed, on a test sequence it sees and predicts token ; the first token is given and not scored.
Informed Bayes, written B, is told the training family and prior but not the parameters of the test sequence. Its probability for a sequence and for the next token are
Equation (1) averages over all source parameters using the likelihood of the entire sequence. Parameters shared across context rows appear in several factors of this likelihood, so observations in one context affect predictions in another, with no separate parameter estimation. In pooled training, also includes the unknown family, so the same formula averages the three families' predictions with their posterior weights. Appendix B gives the formulas and numerical methods for each source.
2.3 PREDICTION ACCURACY
All losses are in bits. Let be the next-token probabilities of a predictor . We write for a trained transformer and for informed Bayes; thus is the transformer's predictive distribution. Let denote the distribution of source parameters used in the test. It equals the training prior in full-prior tests; in fixed-setting tests, the specified parameters are held fixed. The regret of after observed tokens is the expected extra loss compared with a predictor that knows the parameters of the sequence:
Here is the Kullback–Leibler divergence in bits. The expectation first draws the source parameters from and then the observed sequence from that source. The gap to Bayes of the transformer is
In a full-prior test the parameters of each test sequence are drawn from the training prior ; then the next token given has distribution by (1), and
In a full-prior test no predictor has a smaller expected loss than informed Bayes, and the gap measures how far the two predictive distributions are apart. The identity holds with any predictor in place of ; this is the sense in which is the universal probability for the source family (Merhav & Feder, 1998). In a fixed-setting test we fix some parameters, for example and , and draw the others from the prior; informed Bayes still uses the full prior, and the gap can then be negative.
Both predictors are evaluated on the same test sequences; differences are formed within each sequence before averaging, and each denotes one standard error of the mean across sequences. Cumulative quantities sum over all scored predictions (Appendix D.1.2).
3 HOW CLOSE DO TRANSFORMERS GET TO INFORMED BAYES?
Figure 1 compares trained transformers with informed Bayes on six sources, from a prior on one coin bias to a mixture of families. Where shared structure is visible, two-layer transformers are close to informed Bayes, and increasing capacity brings them closer still. When the structure is hidden, more layers and training close most of the gap. Table 16 in Appendix F summarizes the gaps; Appendix D gives the models, training, test sets and numerical checks.
Two-layer transformer -- Larger transformers o Informed Bayes -- Unstructured Bayes
(a) Coins
Prior {0.2, 0.8}; test
Uniform [0, 1]; test
Uniform [0, 1]; test
(b) Product source
Known encoding

(d) Uniform-base control

(e) Shared-base LSA
(c) Product source
Hidden encoding
2 layers: 6.4M
4 layers: 25.6M
8 layers: 25.6M
(f) Pooled sources
Expected next-token regret (bits)


Observed tokens, t

Figure 1: Transformers and informed Bayes on six sources. Expected next-token regret on held-out test sequences. Solid curves show two-layer transformers; dashed curves show four layers in (b,d,f), four or eight in (c), and eight in (e). Open circles show informed Bayes. Colors distinguish source settings in (a,b,d,e) and models in (c). (a) Coins: two-point prior at ; uniform prior at . (b) Known product encoding at four depth pairs. (c) Hidden encoding. Gray dash-dot “Unstructured Bayes” treats the 16 symbols as one Markov chain with independent transition rows, each under a uniform Dirichlet prior, ignoring the product factorization. (d) Uniform base and (e) shared base with , at . Bayes points in (e) extend through at all four depths. (f) Equal mixture of three 64-symbol families; Bayes points through . Panels (b)–(f) show run 1. Appendix D gives both runs and protocols, including the additional training for larger models in (c,e); budgets are equal within (b,d,f).
3.1 A SOURCE PRIOR: COINS
We train one two-layer model on biases 0.2 and 0.8 with equal probability, and another on biases drawn uniformly from [0, 1]. Both follow informed Bayes at all tested biases and all t (panel (a); Appendix D.2 shows the other biases).
What is the prior worth? We test both models on the same sequences with bias 0.2 or 0.8. Over 256 predictions, the two-point-prior model loses bits less than the uniform-prior model; for the two Bayesian predictors the difference is bits. The transformer has learned what the prior is worth.
3.2 A KNOWN ENCODING: PRODUCT SOURCE
With a known encoding, the two-layer transformer is close to informed Bayes (panel (b)). Four-layer models trained on the same number of sequences reduce the largest gap from 0.124 bits to 0.044 and 0.049 bits in two runs (Appendix D.3). The Bayesian curve also predicts how many tokens are needed to reach a target regret (Appendix D.3.1).
3.3 DISCOVERING A FACTORIZATION: HIDDEN ENCODING
When the encoding is hidden, the transformer must find out in each sequence which labels belong together (panel (c)). After 1024 tokens, the two-layer models have regrets of 0.1430 and 0.1335 bits, near the 0.124 bits of unstructured Bayes, which ignores the product factorization. Eight-layer models with more training reach 0.0402 and 0.0397 bits, close to the 0.0378 bits of informed Bayes. Four-layer models lie in between; Appendix D.4 gives the full capacity and training comparisons.
3.4 A KNOWN BASE LAW: UNIFORM-BASE SOURCE
With the base law known, increasing capacity brings the transformer close to informed Bayes at all four depths (panel (d)). With the same training budget, four layers reduce the largest gap from 0.087 bits to 0.037 and 0.041 bits in two runs. At L = 0 the tokens are independent and informed Bayes soon predicts uniformly; the four-layer models learn this behavior too (Appendix D.5).
3.5 AN UNKNOWN SHARED BASE LAW: SHARED-BASE SOURCE
With the base law unknown, eight-layer models with more training close most of the two-layer gap (panel (e)). For both runs, all four depths and all tested , the gap is below 0.007 bits. At and , its absolute value is below 0.0052 bits at all four depths. All shared-base tests use ; Appendix D.6 gives the capacity and training comparisons.
3.6 INFERRING THE SOURCE FAMILY: POOLED TRAINING
Here neither predictor is told which family generated the sequence (panel (f)). We train on an equal mixture of the three 64-symbol families; informed Bayes combines their predictions with posterior family weights. Panel (f) shows Bayes points through ; the paired comparisons reported here use (Appendix D.7). On 1024 new sequences per family, they show that the transformer reproduces this mixture prediction. With the same training sequences, four-layer models reduce the gap after four tokens from 0.0197 and 0.0190 bits to 0.0052 and 0.0025 bits in the two runs (Appendix D.7).
Appendix D.7.1 compares the cumulative cost of not knowing the family with its Bayesian prediction.
4 FOUR PREDICTIONS BEYOND THE LEARNING CURVE
We now test trained transformers in four further, more challenging, ways. In every test the transformer keeps its weights, informed Bayes keeps the training family and prior, and neither is told anything about the test. Each test yields a number that the family and prior fix in advance; Table 1 collects them next to the measured values, Figure 2 shows the curves, and Appendix E gives derivations and all results.
4.1 SOURCE MISMATCH
The transformer was trained on product sources with a known encoding. In the test we apply a random permutation to the 64 labels of a product source, fixed throughout the sequence, which neither predictor is told. Both still read every label as a pair with the training encoding, but under the permutation the two coordinates are no longer independent chains. Informed Bayes can only fit a product of two chains, and its regret approaches
where follows and the entropies are those of the test source: the information a product of two chains cannot use.
After 1024 tokens, the two-layer transformer closely matches informed Bayes at both tested depths (panel (a)). Increasing capacity brings the intermediate predictions closer too: with the same training budget, both four-layer runs reduce the depth-four gap at 32 tokens from 0.209 to 0.062 bits, about 70%. Appendix E.2.1 gives the predicted limits and both runs at both depths.
4.2 TIME-VARYING SOURCE
The transformer was trained on product sources that do not change, and informed Bayes uses that family and prior. The test source starts as a product source from the family. After 256 tokens, one
Table 1: Predicted versus measured. Each row is a quantity that informed Bayes fixes from the family and prior alone, next to the trained transformer's value on the same test sequences. Bits; one standard error; “Bayes” is the reference’s own value on the same sequences where it is a random quantity.
| Test (§) | Quantity | Predicted | Bayes | Transformer |
|---|---|---|---|---|
| Prior (3.1) | bits saved by the two-point prior (256 tokens) | — | ||
| Mismatch (4.1) | residual regret, depths (1, 1), | |||
| residual regret, depths (4, 4), | ||||
| Change (4.2) | extra regret, two new matrices, | — | ||
| Unseen (4.3) | gain over uniform, shared base, , | — | ||
| gain over uniform, uniform base, any | ||||
| Copying (4.4) | gain from token order, | |||
| gain from token order, , | — |
coordinate or both coordinates switch to a new transition matrix, drawn independently from the same prior. The current state and the encoding carry over. The predictors see only the tokens; they are not reset and are not told about the change.
Informed Bayes keeps updating as if the source had not changed. At each prediction, both the true next-token law and Bayes’s forecast factor across the two coordinates. Their KL divergence therefore adds across coordinates. Let be the expected regret of one coordinate when its matrix stays unchanged, and when it is redrawn. The coordinates have identical laws and priors, and changing one affects neither the data nor the forecast for the other. Consequently, the expected regrets with no, one, and two new matrices are , and , respectively. Subtracting the no-change regret gives, at every after the change:
Panel (b) shows close transformer–Bayes agreement before the switch, through the jump at the change, and during the subsequent decline. The additional regret also agrees with the factor of two (panel (c)). Simultaneous 95% bands for the paired differences include zero at both depths and all 14 tested times after the change. Any predictor that treats the coordinates separately and symmetrically has this doubling. Panel (c) therefore tests whether the transformer retains the factorization; panel (b) tests whether its regret matches informed Bayes. Appendix E.3.1 gives the derivation and full comparison.
4.3 AN UNSEEN CONTEXT
We look at the predictions made when the current token appears for the first time, so that nothing has been observed of its transition row, and measure the bits saved over a uniform prediction; a predictor that uses only token counts is added for comparison. In the shared-base source informed Bayes can still predict, because transitions out of other tokens tell it about the shared base law; in the uniform-base source the rows share no base law and it predicts uniformly.
The transformers do the same (panels (d–f)): both eight-layer shared-base models are within 0.015 bits of informed Bayes at every tested depth and context length. The token-count predictor is close to Bayes at small depth, where token frequencies approximate the base law, but at and it loses bits to Bayes while the transformer loses . In the uniform-base source the transformer predicts almost uniformly, while token counts increase loss. Each transformer thus uses the other contexts exactly when its family makes them informative (Appendix E.4).
4.4 WHEN COPYING STARTS TO PAY
When token appears again, a copying predictor raises the probability of the token that followed before. This uses the order of the tokens, which a frequency-only predictor cannot. At depth every row of the shared-base source equals the base law, so the order is worth nothing and looking for it costs; at positive depth the order helps once enough tokens have been seen. We ask whether copying emerges in the transformer where informed Bayes says it should. Next to informed Bayes
Two-layer transformer -- Larger transformers o Informed Bayes ⋅ Token counts
(a) Mismatch: predicted residual loss

(b) Time-varying: adaptation
(c) Time-varying: additivity
(d) Unseen shared base, L = 1
(e) Unseen shared base, L = 8
(f) Unseen uniform base, L = 1
(g) Copying: gain per token
(h) Copying: summed gain
Figure 2: Four further tests of trained transformers against informed Bayes. (a) Regret under randomly permuted product labels; gray dotted line: predicted limit . (b,c) New transition matrices at t = 256: regret with two new matrices (b); additional regret with two versus twice that with one (c). Panels (a)–(c) use depths (4, 4). (d)–(f) Bits saved over uniform prediction when the current token is new: shared base at L = 1, 8 (d,e); uniform base at L = 1 (f). (g,h) Run-1 shuffled-trained minus ordered-trained loss, per token (g) and cumulative (h), compared with the Bayesian gain over its frequency-only predictor through t = 16, and at t = 32, 64, 128 in (g). At t = 128, Bayes uses 256 sequences for each of L = 2, 3. Curves show transformers; open markers show Bayes in matching colors. Solid curves show two layers; dashed curves show four layers in (a,g,h) and eight in (d,e). The second four-layer run in (a) is dotted. Gray curves show controls, including token counts in (d)–(f). In (g,h), blue circles denote L = 2 and orange squares L = 3. Horizontal axes use base-2 scales; shared-base panels use . Intervals are pointwise 95% in (a)–(c), (g) and (h); markers in (d)–(h) show one sequence standard error.
we use a Bayesian predictor that keeps the same prior and first-token law but models every later token as an independent draw from the stationary law of the source (Appendix E.5.1); it approximates the training law of the shuffled-trained transformer below. With the loss of predictor M on token , the gain from the order and its running sum are
For the transformer we compare a matched pair of four-layer models. One sees ordered training sequences; the other sees positions 2, ..., 1025 shuffled within each sequence, preserving the first token and all token counts. It can learn frequencies but cannot learn to copy. Both are tested on the same ordered sequences; their loss difference and its running sum measure what copying is worth to the transformer.
Copying emerges where Bayes says it should. At both gains are negative at every measured context. At and both gains become positive, larger at the greater depth, and of the same size at the measured contexts. At and , Bayes gains bits and the run-1 transformer gains bits. The shuffled-trained transformer matches within 0.0043 bits at all sixteen tokens, so it has learned the frequencies and nothing more. At longer contexts the transformer's gain keeps growing, to 0.57 and 0.91 bits per token at for (panels (g,h)); Appendix E.5.1 gives both runs and matched training settings.
5 WHY A TRANSFORMER CAN APPROXIMATELY IMITATE INFORMED BAYES
Three facts make the imitation possible. First, informed Bayes minimizes expected training loss: for any predictor Q, when source parameters follow the training prior ,
(8)
because has distribution . The divergence vanishes only when , so in (4) measures the remaining excess training loss without requiring parameter labels. Ignoring structure means using the universal probability of a larger family and paying its larger regret (Merhav & Feder, 1998), as in Figure 1(c). The same argument explains why transformers and LSTMs meta-trained on random tree sources reach, e.g., the loss of the universal context-tree-weighting mixture (Grau-Moya et al., 2024).
Second, informed Bayes needs memory even for memoryless sources: coin prediction uses the counts of zeros and ones. Shared-base prediction uses all rows; pooled prediction also uses each family's evidence. A transformer reads the prefix and can approximate this growing state. Finite-state prediction bounds relate the remaining regret to the number of states (Meron & Feder, 2004; Ingber & Feder, 2006; Dar & Feder, 2011); likewise, a transformer's context, width, depth and training limit its approximation. In the framework of Feder et al. (2025), the randomly initialized architecture is a prior over predictors and the sequences needed to reach a target are set by the target's complexity under that architecture prior; here the target is , so the transformer pays two universality costs: across sequences for relative to the architecture, and within a sequence for relative to the family; the gaps of Sections 3,4 measure the first.
Third, Bayesian prediction decomposes as : sufficient statistics followed by a forecast map . For the independent-row chain of Edelman et al. (2024), counts successors in the current context and is the add-one rule. Attention to earlier occurrences of the current token supplies selection and accumulation; the feed-forward network learns the prior-specific estimator . Here is global: the shared base and depth use all rows, the hidden partition must be inferred from the count matrix, and family selection uses a softmax of accumulated evidence. Appendix C develops this decomposition, its relation to architecture-based complexity, and its implications for capacity and training.
6 DISCUSSION
Training on freshly drawn source parameters teaches transformers what sequences share, and their predictions approach informed Bayes, with larger models and more training needed when the encoding or base law is hidden. From the family and prior alone, informed Bayes predicts the costs of a wrong factorization and a source change, the benefit of other contexts for a new token, and when copying starts to pay. A trained network can fail each prediction, so these tests measure what it has learned and give circuit and training-dynamics studies a target (Raventós et al., 2023; Falck et al., 2024).
The same account makes predictions for language models, where the family is not specified: documents sharing latent structure across contexts are the shared-base case, and the unseen-context test says when a model should generalize to a context never seen continued; retrieval of a first-occurrence continuation is the copying test, with a depth-dependent onset; the mismatch test says that a model keeps paying its training family’s price on out-of-distribution text however long the prompt, and the change test that adaptation to a shift is as slow as a stationary posterior. When pretraining data are not fresh draws from a stable class (Raventós et al., 2023; Chan et al., 2022; Falck et al., 2024) there is no informed Bayes to imitate, and that is where the correspondence should break.
Our evidence is limited to synthetic sources, alphabets of at most 64 symbols, at most 26 million parameters, some baselines with one training run, and shared-base tests at ; the hidden-encoding and shared-base comparisons change size, training amount and schedule together. Agreement in loss does not establish posterior computation. Section 5 suggests a design to test: learned selection, exact accumulation, and the family’s closed-form estimator.
AI USE STATEMENT
We used large language models to write and test the code for the sources, the Bayesian predictors, the training and the evaluation, to draft and edit the text, to search the literature and to make the figures. They did not propose experiments. The authors checked all derivations, numerical results and citations, and take full responsibility for the content of the paper.
REPRODUCIBILITY STATEMENT
Appendix B defines all Bayesian predictors. Appendices D and E give the models, the training settings, the test sets and the numerical checks, including the numerical error allowances applied to every reported Bayesian value. The code is available at https://github.com/urbanke/learning-source-structure.
REFERENCES
Ekin Akyürek, Bailin Wang, Yoon Kim, and Jacob Andreas. In-context language learning: Architectures and algorithms. In International Conference on Machine Learning, 2024. arXiv:2401.12973.
Tatsuya Aoyama, Ethan Gotlieb Wilcox, and Nathan Schneider. Predicting the emergence of induction heads in language model pretraining. In International Conference on Machine Learning, 2026. URL https://arxiv.org/abs/2511.16893v3. arXiv:2511.16893v3, revised 5 July 2026.
Yu Bai, Fan Chen, Huan Wang, Caiming Xiong, and Song Mei. Transformers as statisticians: Provable in-context learning with in-context algorithm selection. In Advances in Neural Information Processing Systems, volume 36, 2023. URL https://proceedings.neurips.cc/paper_files/paper/2023/hash/b2e63e36c57e153b9015fece2352a9f9-Abstract-Conference.html. arXiv:2306.04637.
Alberto Bietti, Vivien Cabannes, Diane Bouchacourt, Herve Jegou, and Leon Bottou. Birth of a transformer: A memory viewpoint. In Advances in Neural Information Processing Systems, volume 36, 2023. arXiv:2306.00802.
Marco Bondaschi, Nived Rajaraman, Xiuying Wei, Kannan Ramchandran, Razvan Pascanu, Caglar Gulcehre, Michael Gastpar, and Ashok Vardhan Makkuva. From Markov to Laplace: How Mamba in-context learns Markov chains. arXiv:2502.10178v2, 2026. URL https://arxiv.org/abs/2502.10178v2. Revised 22 June 2026.
Stephanie C. Y. Chan, Adam Santoro, Andrew K. Lampinen, Jane X. Wang, Aaditya Singh, Pierre H. Richemond, James McClelland, and Felix Hill. Data distributional properties drive emergent in-context learning in transformers. In Advances in Neural Information Processing Systems, volume 35, 2022. arXiv:2205.05055.
Bertrand S. Clarke and Andrew R. Barron. Information-theoretic asymptotics of Bayes methods. IEEE Transactions on Information Theory, 36(3):453–471, 1990.
Imre Csiszár and Paul C. Shields. The consistency of the BIC Markov order estimator. The Annals of Statistics, 28(6):1601–1619, 2000.
Francesco D'Angelo, Francesco Croce, and Nicolas Flammarion. Selective induction heads: How transformers select causal structures in context. In International Conference on Learning Representations, 2025. URL https://proceedings.iclr.cc/paper_files/paper/2025/file/d7ed243b13831bdd468f35039936bcef-Paper-Conference.pdf.
Francesco D'Angelo, Oğuz Kaan Yüksel, Swathi Shree Narashiman, and Nicolas Flammarion. Induction heads interpolate N-grams. In International Conference on Machine Learning, 2026. URL https://arxiv.org/abs/2607.02800v1. arXiv:2607.02800v1.
Ronen Dar and Meir Feder. Finite-memory prediction as well as the empirical mean. In Proceedings of the IEEE International Symposium on Information Theory, 2011. Extended version: arXiv:1102.2836.
Puneesh Deora, Bhavya Vasudeva, Tina Behnia, and Christos Thrampoulidis. In-context Occam's razor: How transformers prefer simpler hypotheses on the fly. In Second Conference on Language Modeling, 2025. URL https://openreview.net/forum?id=ZSMnX3LBva.arXiv:2506.19351v1.
Ezra Edelman, Nikolaos Tsilivis, Benjamin L. Edelman, Eran Malach, and Surbhi Goel. The evolution of statistical induction heads: In-context learning Markov chains. In Advances in Neural Information Processing Systems, volume 37, 2024. arXiv:2402.11004.
Nelson Elhage, Neel Nanda, Catherine Olsson, et al. A mathematical framework for transformer circuits. Transformer Circuits Thread, https://transformer-circuits.pub/2021/framework/index.html, 2021.
Eric Elmoznino, Tom Marty, Tejas Kasetty, Leo Gagnon, Sarthak Mittal, Mahan Fathi, Dhanya Sridhar, and Guillaume Lajoie. In-context learning and Occam's razor. In Proceedings of the 42nd International Conference on Machine Learning, volume 267 of Proceedings of Machine Learning Research, pp. 15296–15319, 2025. URL https://proceedings.mlr.press/v267/elmoznino25b.html.
Fabian Falck, Ziyu Wang, and Christopher C. Holmes. Is in-context learning in large language models Bayesian? A martingale perspective. In Proceedings of the 41st International Conference on Machine Learning, volume 235 of Proceedings of Machine Learning Research, pp. 12784–12805, 2024. URL https://proceedings.mlr.press/v235/falck24a.html.
Meir Feder and Neri Merhav. Hierarchical universal coding. IEEE Transactions on Information Theory, 42(5):1354–1364, 1996.
Meir Feder, Ruediger Urbanke, and Yaniv Fogel. Information-theoretic framework for understanding modern machine-learning. arXiv preprint arXiv:2506.07661, 2025.
Meir Feder, Yaniv Fogel, and Ruediger Urbanke. A layered simplex architecture for large alphabets. arXiv preprint arXiv:2608.19908, 2026.
Tim Genewein, Gregoire Deletang, Anian Ruoss, Li Kevin Wenliang, Elliot Catt, Vincent Dutordoir, Jordi Grau-Moya, Laurent Orseau, Marcus Hutter, and Joel Veness. Memory-based meta-learning on non-stationary distributions. In Proceedings of the 40th International Conference on Machine Learning, volume 202 of Proceedings of Machine Learning Research, pp. 11173–11195, 2023. URL https://proceedings.mlr.press/v202/genewein23a.html.
Jordi Grau-Moya, Tim Genewein, Marcus Hutter, Laurent Orseau, Grégoire Delétang, Elliot Catt, Anian Ruoss, Li Kevin Wenliang, Christopher Mattern, Matthew Aitchison, and Joel Veness. Learning universal predictors. In Proceedings of the 41st International Conference on Machine Learning, volume 235 of Proceedings of Machine Learning Research, 2024. arXiv:2401.14953.
David Haussler and Manfred Opper. Mutual information, metric entropy and cumulative relative entropy risk. The Annals of Statistics, 25(6):2451–2492, 1997.
Amir Ingber and Meir Feder. Prediction of individual sequences using universal deterministic finite state machines. In Proceedings of the IEEE International Symposium on Information Theory, pp. 421–425, 2006.
Hong Jun Jeon, Jason D. Lee, Qi Lei, and Benjamin Van Roy. An information-theoretic analysis of in-context learning. In Proceedings of the 41st International Conference on Machine Learning, volume 235 of Proceedings of Machine Learning Research, pp. 21522–21554, 2024. URL https://proceedings.mlr.press/v235/jeon24a.html.
Raphail Krichevsky and Victor Trofimov. The performance of universal encoding. IEEE Transactions on Information Theory, 27(2):199–207, 1981.
David J. C. MacKay and Linda C. Bauman Peto. A hierarchical Dirichlet language model. Natural Language Engineering, 1(3):289–308, 1995.
Neri Merhav and Meir Feder. Universal prediction. IEEE Transactions on Information Theory, 44(6):2124–2147, 1998.
Neri Merhav, Michael Gutman, and Jacob Ziv. On the estimation of the order of a Markov chain and universal data compression. IEEE Transactions on Information Theory, 35(5):1014–1019, 1989.
Eado Meron and Meir Feder. Finite-memory universal prediction of individual sequences. IEEE Transactions on Information Theory, 50(7):1506–1523, 2004.
Samuel Müller, Noah Hollmann, Sebastian Pineda Arango, Josif Grabocka, and Frank Hutter. Transformers can do Bayesian inference. In International Conference on Learning Representations, 2022. URL https://openreview.net/forum?id=KSugKcbNf9. arXiv:2112.10510.
Eshaan Nichani, Alex Damian, and Jason D. Lee. How transformers learn causal structure with gradient descent. In Proceedings of the 41st International Conference on Machine Learning, volume 235 of Proceedings of Machine Learning Research, pp. 38018–38070, 2024. URL https://proceedings.mlr.press/v235/nichani24a.html.
Catherine Olsson, Nelson Elhage, Neel Nanda, et al. In-context learning and induction heads. Transformer Circuits Thread; arXiv:2209.11895, https://transformer-circuits.pub/2022/in-context-learning-and-induction-heads/index.html, 2022.
Madhur Panwar, Kabir Ahuja, and Navin Goyal. In-context learning through the Bayesian prism. In International Conference on Learning Representations, 2024. URL https://arxiv.org/abs/2306.04891. arXiv:2306.04891v2.
Nived Rajaraman, Marco Bondaschi, Kannan Ramchandran, Michael Gastpar, and Ashok Vardhan Makkuva. Transformers on Markov data: Constant depth suffices. In Advances in Neural Information Processing Systems, volume 37, 2024. URL https://arxiv.org/abs/2407.17686. arXiv:2407.17686.
Allan Raventós, Mansheej Paul, Feng Chen, and Surya Ganguli. Pretraining task diversity and the emergence of non-Bayesian in-context learning for regression. In Advances in Neural Information Processing Systems, volume 36, 2023. arXiv:2306.15063.
Jorma Rissanen. Modeling by shortest data description. Automatica, 14(5):465–471, 1978.
Jorma Rissanen. Universal coding, information, prediction, and estimation. IEEE Transactions on Information Theory, 30(4):629–636, 1984.
Boris Ya. Ryabko. Twice-universal coding. Problems of Information Transmission, 20(3):173–177, 1984.
Aaditya K. Singh, Ted Moskovitz, Felix Hill, Stephanie C. Y. Chan, and Andrew M. Saxe. What needs to go right for an induction head? A mechanistic study of in-context learning circuits and their formation. In Proceedings of the 41st International Conference on Machine Learning, volume 235 of Proceedings of Machine Learning Research, pp. 45637–45662, 2024. URL https://proceedings.mlr.press/v235/singh24c.html.
Anzo Teh, Mark Jabbour, and Yury Polyanskiy. Solving empirical Bayes via transformers. arXiv:2502.09844, 2025.
Yee Whye Teh. A hierarchical Bayesian language model based on Pitman–Yor processes. In Proceedings of the 21st International Conference on Computational Linguistics and 44th Annual Meeting of the ACL, pp. 985–992, 2006.
Tim van Erven, Peter Grünwald, and Steven de Rooij. Catching up faster in Bayesian model selection and model averaging. In Advances in Neural Information Processing Systems, volume 20, 2007.
Tim van Erven, Peter Grünwald, and Steven de Rooij. Catching up faster by switching sooner: A predictive approach to adaptive estimation with an application to the AIC–BIC dilemma. Journal of the Royal Statistical Society: Series B, 74(3):361–417, 2012.
Jianzhe Wei, Siyu Chen, Jianliang He, and Zhuoran Yang. How transformers learn causal structures in-context: Explainable mechanism meets theoretical guarantee. In International Conference on Learning Representations, 2026. URL https://proceedings.iclr.cc/paper_files/paper/2026/hash/934ebba637be11105cff78e86a99eb08-Abstract-Conference.html.
Frans M. J. Willems, Yuri M. Shtarkov, and Tjalling J. Tjalkens. The context-tree weighting method: Basic properties. IEEE Transactions on Information Theory, 41(3):653–664, 1995.
Qun Xie and Andrew R. Barron. Asymptotic minimax regret for data compression, gambling, and prediction. IEEE Transactions on Information Theory, 46(2):431–445, 2000.
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:2111.02080.
Yufeng Zhang, Fengzhuo Zhang, Zhuoran Yang, and Zhaoran Wang. What and how does in-context learning learn? Bayesian model averaging, parameterization, and generalization. In Proceedings of the 28th International Conference on Artificial Intelligence and Statistics, volume 258 of Proceedings of Machine Learning Research, pp. 1684–1692, 2025. URL https://proceedings.mlr.press/v258/zhang25d.html.
Ruida Zhou, Chao Tian, and Suhas Diggavi. An information-theoretic approach to understanding transformers' in-context learning of variable-order Markov chains. In Proceedings of the 29th International Conference on Artificial Intelligence and Statistics, volume 300 of Proceedings of Machine Learning Research, pp. 1351–1359, 2026. URL https://proceedings.mlr.press/v300/zhou26b.html. arXiv:2410.05493v3.
A RELATED WORK: BAYESIAN PREDICTION AND LEARNED SOURCE STRUCTURE
This paper brings together four lines of work: Bayesian accounts of in-context learning, transformer prediction on sequential sources, hierarchical models that share information across contexts, and universal prediction under log loss. The Bayesian interpretation itself is established in prior work. Our use of it is quantitative: for fully specified structured source priors, we compute the informed posterior predictive distribution at every number of observed tokens and ask whether it predicts both transformer loss and the response to controlled interventions.
A.1 BAYESIAN ACCOUNTS OF IN-CONTEXT LEARNING
Xie et al. (2022) model pretraining data as a mixture of latent concepts and explain in-context learning as implicit Bayesian inference of the concept generating the prompt. Their analysis gives asymptotic guarantees for a hidden-Markov construction. Müller et al. (2022) take a complementary amortized-inference approach: prior-data fitted networks are trained on samples from a specified prior and learn its posterior predictive map. Together, these works establish the central possibility used here: training examples can convey a prior, while the prompt updates beliefs about the latent parameters of a new example.
Several subsequent results sharpen that connection. In regression, Panwar et al. (2024) find that sufficiently capable transformers track tractable Bayesian predictors across individual function families and mixtures of families, while also documenting departures from the Bayesian rule outside the training families. Zhang et al. (2025) show that perfect pretraining implements Bayesian model averaging under their dynamic prompt model, and separate the resulting in-context error from approximation and pretraining errors. Jeon et al. (2024) decompose Bayes-optimal prediction error into learning the task distribution across sequences and learning the current task within a sequence. This distinction corresponds directly to our setup: the transformer must acquire the source family and prior during training, then infer the freshly drawn parameters from the test prefix. Bai et al. (2023) provide a different, constructive route: a transformer can run several statistical procedures in context and select among them using validation. Our pooled predictor averages source families with their posterior probabilities, so both constructions address algorithm selection but implement different decision rules.
Bayesian behavior cannot be inferred from good average loss alone. Raventós et al. (2023) show that the effective in-context estimator in linear regression changes with pretraining task diversity. Falck et al. (2024) derive a necessary martingale condition for Bayesian prediction in exchangeable settings and find violations in language models. We therefore treat informed Bayes as an optimal, numerically testable reference rather than as an assumption about a trained network. Relative to these works, our focus is next-token prediction from dependent discrete sequences, with the complete training prior specified and with transformer and Bayesian losses evaluated on the same prefixes. The source interventions in Section 4 test additional consequences of the same posterior predictive rule rather than relying on a single agreement in average loss.
A.2 MARKOV SOURCES, INDUCTION HEADS, AND LEARNED ESTIMATORS
The copying mechanism associated with Markov prediction has a well-developed mechanistic literature. Elhage et al. (2021) identify induction-head circuits that use an earlier occurrence of a token to retrieve its continuation. Olsson et al. (2022) connect the formation of such heads to a sharp change in in-context learning during training, with causal evidence in small attention-only transformers and correlational evidence in larger models. Singh et al. (2024) causally isolate interacting subcircuits that drive induction-head formation, while Aoyama et al. (2026) relate formation time to repetition, continuation reliability and the amount of training data. These works motivate our experiments on token order, but our claims concern predictive distributions and losses, not the presence of a particular attention circuit.
Random Markov sources make the learned estimator explicit. Edelman et al. (2024) show a training progression from uniform to unigram and then bigram prediction, and identify statistical induction heads that estimate bigram probabilities in context. Rajaraman et al. (2024) show that a constant-depth transformer can represent the in-context conditional empirical distribution for Markov sources of arbitrary fixed order, while their attention-only construction composes induction heads. Bondaschi et al. (2026) show that a single-layer Mamba can implement Laplace smoothing for Markov chains and compare this behavior with transformers. Akyürek et al. (2024) likewise find that transformers trained on random formal languages use in-context n-gram statistics. These papers establish counting and smoothing of context-conditioned continuations as learned sequential algorithms.
Other work lets the dependency structure itself vary. For variable-order Markov chains, Zhou et al. (2026) use context-tree weighting as the reference, construct a transformer that implements it exactly, and find that two or more layers can learn the task empirically. Wei et al. (2026) study prompts with randomly sampled causal dependencies and show that a two-layer transformer can implement, and trained models can approximate, Bayesian model averaging over those structures. Their numerical transition kernel is shared across the data set, whereas our source parameters are drawn afresh for every sequence. D'Angelo et al. (2026) show that induction heads need not merely count exact matches: finite attention scales interpolate across partial context matches, while a beginning-of-sequence token supplies Dirichlet-like pseudo-count smoothing. Their hierarchical Dirichlet experiment also shows that trained models use suffix-related evidence from other contexts. It compares learned smoothing with count-based baselines; our comparison evaluates the full posterior predictive distribution under a different shared hierarchy. D'Angelo et al. (2025) show that transformers can select the relevant lag when examples with different Markov orders are interleaved, locating an explicit circuit for context-dependent structural selection. Work on training dynamics explains how such rules arise. For example, Bietti et al. (2023) analyze the staged formation of associative memories, and Nichani et al. (2024) prove that gradient descent can learn latent causal structure in a simplified prediction problem.
Our sequential experiments start from these results and change what must be inferred. Product sources test a known or sequence-specific hidden factorization; shared-base sources couple all transition rows through an unknown base law and depth; pooled training adds uncertainty over the source family. Rather than compare only with empirical counts or a generic smoothing rule, we marginalize the stated prior and compare the transformer with that finite-sample posterior predictive distribution. The result complements representational and optimization analyses: it identifies the prediction that full use of the training distribution would produce and separates that output-level question from the circuit and training path that realize it.
A.3 HIERARCHICAL PRIORS, SHARED STRUCTURE, AND TRANSFER
Sharing statistical strength across contexts is classical in language modeling. MacKay & Peto (1995) couple multinomial contexts through a hierarchical Dirichlet model, and Teh (2006) use hierarchical Pitman–Yor processes to share information across n-gram contexts while retaining power-law behavior. These models supply direct precedents for our shared-base source: observations from one transition row can improve prediction in another because the rows have common latent parameters. Our row prior and latent variables differ, but the pooling principle is the same and belongs to this hierarchical Bayesian tradition.
Transformers have also been studied as learners of an unknown population prior. Teh et al. (2025) train transformers for Poisson empirical Bayes and prove that sufficiently wide models can approach an oracle that knows the prior, while small models perform competitively in experiments. At the level of pretraining distributions, Chan et al. (2022) show that properties such as within-sequence burstiness and token meaning across sequences determine whether in-context learning emerges, and Raventós et al. (2023) show that task diversity changes whether a network behaves like inference over a finite task set or like a continuous prior predictor. Deora et al. (2025) explain selection among Markov orders through posterior weights that trade data fit against model complexity. Elmoznino et al. (2025) interpret next-token loss as prequential coding and connect in-context hypothesis choice to an Occam tradeoff. These results all emphasize that the structure of the training distribution, rather than sequence data alone, determines the learned rule.
There are also direct precedents for two applications in Section 4. Genewein et al. (2023) train memory-based sequence models, including transformers, on piecewise stationary sources and compare them with Bayesian algorithms that infer latent change points and segment parameters. Our source-change experiment freezes predictors trained on stationary sources, gives them no switching model, and tests the additive response implied by two independent components. Comparing early and cumulative log loss also belongs to the catch-up and switching literature (van Erven et al., 2007;
2012). Our ordered-versus-shuffled experiment uses this accounting to measure when copying an earlier continuation pays for fixed trained predictors; it does not propose a switching distribution.
The present paper makes that dependence directly measurable for sequential sources. Every sequence redraws its local parameters, while the training distribution fixes which coordinates, transition rows, and source families are related. The informed Bayesian predictor therefore isolates the value of each relation. The unseen-context experiment measures transfer through a shared base law; the source-change experiment tests additivity across independent latent components; the relabeling experiment measures the cost of retaining a factorization outside its assumed family; and the pooled experiment performs posterior averaging over source families. These are controlled consequences of the stated source priors, rather than a claim that hierarchical pooling or Bayesian model selection is new.
A.4 UNIVERSAL PREDICTION AND COMPUTABLE SOURCE PRIORS
Under log loss, the cumulative loss of a sequential probability assignment is a codelength. A Bayesian mixture is optimal in expectation under its stated prior. Universal and minimax codes instead control redundancy or regret over a source class (Merhav & Feder, 1998; Rissanen, 1984; Clarke & Barron, 1990; Xie & Barron, 2000). The Krichevsky–Trofimov probability gives a canonical universal code for unknown symbol probabilities (Krichevsky & Trofimov, 1981), while context-tree weighting averages efficiently over variable-memory sources (Willems et al., 1995). Mixtures across source classes and hierarchical universal coding extend this principle to uncertainty over the model itself (Ryabko, 1984; Feder & Merhav, 1996); classical work also connects compression to selection of Markov order (Merhav et al., 1989; Csiszár & Shields, 2000). Bayesian redundancy and cumulative prediction risk are also characterized through mutual information (Haussler & Opper, 1997). The minimum-description-length principle supplies a complementary model-selection interpretation (Rissanen, 1978). Our regret definitions and family mixtures use this established prediction-compression framework. A separate strand asks what a predictor with limited resources can achieve: Meron & Feder (2004) characterize the regret of finite-state universal predictors of individual binary sequences as a function of the number of states, Ingber & Feder (2006) design deterministic finite-state predictors non-asymptotically, and Dar & Feder (2011) extend the finite-memory analysis to continuous sequences. Our comparison of transformers of increasing depth and training with the unconstrained Bayesian predictor is the analogous question for a different resource, and Appendix C makes the connection explicit.
Feder et al. (2025) propose an information-theoretic framework for modern machine learning in which a randomly initialized architecture is a prior over predictors and learning is universal prediction with respect to that prior. The cost of learning a target predictor is its architecture-based complexity, the negative log of the prior mass that the architecture places near the target, and the distribution of this cost over targets—the architecture's complexity spectrum—is what distinguishes one architecture from another. Feder et al. (2026) carry the program out exactly for the layered simplex architecture: its prior on large-alphabet distributions has a computable Bayesian mixture, a computable learning curve and a complexity spectrum that is broad where a symmetric Dirichlet prior is narrow. The present paper uses that architecture in the opposite role. The LSA prior is here the source prior, and its row integrals are the building blocks from which informed Bayes is assembled for known and hidden products, shared latent bases and depths, and mixtures over source families; where these combinations no longer have closed forms, we use controlled numerical marginalization and validate the resulting predictive probabilities as described in Appendix D.1.3. The transformer, meanwhile, is the architecture whose prior over predictors is being probed, and informed Bayes is the target whose architecture-based complexity training has to pay. Appendix C.2 states this two-level picture.
Thus universal coding, the Bayesian interpretation of in-context learning, and Markov prediction by induction mechanisms all precede this work. Our contribution is to join them in a set of source families for which the learned structure has a quantitative price: informed Bayes predicts the learning curves, and the same source model predicts transfer, adaptation, misspecification loss, and the emergence of copying.
Table 2: The six sources. Training can teach what the middle column lists. A new sequence must reveal what the right column lists.
| Source | Shared by all sequences | Drawn afresh for every sequence |
|---|---|---|
| Coins | the prior on the bias | the bias |
| Known encoding | the two coordinates, the encoding, the prior on the depths | the two depths and the two transition matrices |
| Hidden encoding | the two coordinates | the encoding and the two transition matrices |
| Uniform base | the uniform base law, the prior on the depth | the depth and the 64 transition rows |
| Shared base | one base law reshaped by every row, the priors on and on the depth | , the ranks of the tokens, the depth and the rows |
| Pooled families | the three families and their priors | the family and its parameters |
B SUPPLEMENTAL MATERIAL FOR SECTION 2: THE BAYESIAN PREDICTORS
This appendix defines the Bayesian predictors used in the paper. For coins the posterior prediction has a simple formula. For the LSA-based sources we first derive the probability of the counts in one row from the integrals of Feder et al. (2026), and then combine the rows into the probability of a sequence. We then sum over the unknown encoding of the product source. The mixture over families is described with its experiment in Appendix D.7. The frequency-only predictor of Section 4.4 is defined in Appendix E.5.1. Table 2 summarizes the sources.
B.1 COINS: SEQUENCE PROBABILITY AND PREDICTION
For a prefix , let be its number of ones and its number of zeros. Under a prior on the coin bias, the Bayesian probability of this particular ordered sequence is
For the two priors used here, this gives
The probability of a one next is the ratio of the probability of the prefix followed by a one to that of the prefix itself:
For the two-point prior, this ratio is the average of the biases 0.2 and 0.8 weighted by their posterior probabilities, which are proportional to . For the uniform prior, the ratio gives . In both cases, the counts include the first token, although its loss is not scored.
B.2 LSA ROW PRIOR: ROW PROBABILITY AND PREDICTION
Let be a vector of nonnegative integer counts, with . A row with depth and base probability vector , where and , has the representation
Here ; the simplex-factor normalizations cancel. The probability of a particular ordered sequence of row observations with counts is
The expectation averages over the independent exponential factors above, with and fixed. The next-token prediction is .
Define the transforms
where has the common distribution of the and r is an integer. Conditioning on the last exponential factor gives
In particular, .
Lemma 1. For , the row probability is
For a uniform base, write . Then
Proof. Set . Substitute into the definition of , exchange the nonnegative integral and expectation, and use independence of the . For the uniform base, change the integration variable by a factor .
At depth zero, . At depth one with a uniform base,
B.3 LSA-BASED SOURCES: SEQUENCE PROBABILITY AND PREDICTION
Shared latent parameters must be averaged after multiplying the context-row probabilities. Let count transitions from to in the observed sequence, and write for the shared parameters with their stated prior . Then
The average over the base and depth is outside the product over contexts. For the uniform-base control, only the common depth is averaged. For a product chain, each coordinate has a uniform base, an initial factor and its own depth prior, giving . For the shared-base source, the informative factor remains in the inference even though the first token is not scored.
For the shared-base source, the posterior is
Here is determined by and . The next-token prediction is therefore
All contexts and the initial token inform the joint posterior on exponent, rank assignment and depth.
B.4 PRODUCT SOURCE WITH HIDDEN ENCODING: EXACT MARGINALIZATION
For a candidate encoding , decode into two coordinate sequences. Let count transitions from to in coordinate , whose alphabet has size . Integrating its independent uniform-simplex rows gives
Conditional on , the forecast multiplies two add-one coordinate predictions and maps back to observed labels. Bayes averages these forecasts with weights proportional to .
Relabeling either coordinate leaves its prior unchanged; when , interchanging the coordinates does too. Consequently we need only one encoding from each equivalence class, with a uniform prior on the
classes. The marginal probability is . This is exact finite summation with analytic row probabilities; no sampling approximation to the posterior is required. Its cost grows rapidly: the source used here has equivalence classes.
Relative to a reference given the encoding but not the transition matrices, cumulative excess loss is . The first-token law is identical, so excluding that token preserves the bound. The prior-averaged cost of encoding uncertainty need not attain it.
C WHY A TRANSFORMER CAN APPROXIMATE AN INFORMED BAYES: THE MECHANISM IN DETAIL
This appendix expands Section 5: first the objective, then the decomposition of informed Bayes into selection, accumulation and estimation, what each of the present sources adds to it, why and how the shared structure is selected, and what the decomposition predicts about capacity, training and context. The mechanistic statements are hypotheses; the learning curves of Section 3 are the evidence we have for them.
C.1 THE OBJECTIVE, CAPACITY-EXPRESSIBILITY AND TRAINING
Identity (8) says that the population training loss is the loss of the informed Bayes plus the expected divergence of the network's forecast from it. Two things separate a trained network from that target. The first is its capacity, or expressibility: the architecture must contain a function of that approximates on the prefixes the prior generates. The second is training: the population loss is estimated from a finite number of sequences, and the optimizer must find the approximation. The regret curves of Figure 1 separate the two only partly, but both are visible: the hidden-encoding source is matched at 1024 tokens by eight layers and not by two, and doubling the training of the eight-layer models still lowers their loss. In the language of Jeon et al. (2024), the weights learn the family and the prior across sequences; the activations then carry, for each sequence, whatever statistics of the prefix the posterior needs.
The required capacity question has a classical form. Universal prediction with a finite number of states asks how much regret a K-state machine must pay against the best constant or Markov predictor of an individual sequence; Meron & Feder (2004) bound the achievable regret as a function of K for deterministic and randomized machines under the 0–1, square and self-information losses, Ingber & Feder (2006) give non-asymptotic constructions with deterministic machines, and Dar & Feder (2011) extend the analysis to continuous sequences, where regret against the empirical mean decays as a power of K. In each case a resource-limited predictor pays a regret that vanishes only as the resource grows, and the rate is a property of the class. The transformer gaps of Section 3 are the same object for a different resource: depth and width, and the amount of training, in place of states. The ordering of sources by the capacity they need (Appendix C.6) is a first, qualitative version of such a rate for these classes.
The reason informed Bayes is the right target, and not merely a convenient one, is its regret guarantee. For a smooth k-parameter family with a positive prior, the cumulative regret of against every is about plus a constant that depends on the prior mass near (Merhav & Feder, 1998); for a finite mixture over m hypotheses it is at most in total. A predictor that ignores part of the structure pays the regret of a larger family, and one that assumes a wrong family pays a loss that does not vanish with t (Section 4.1). The structure is therefore not optional for a network trained on the family: the objective rewards exactly those computations that use it.
C.2 TWO UNIVERSALITIES: THE SOURCE FAMILY AND THE ARCHITECTURE
The regret guarantee just stated concerns the inner problem, prediction within one sequence, where the class is the source family and the price of not knowing is paid in tokens. A trained transformer faces a second, outer problem, and the framework of Feder et al. (2025) gives it the same form. A randomly initialized architecture defines a prior over the predictors it can realize; training on sequences from the family is universal prediction with respect to ; and the price of reaching a target predictor is its architecture-based complexity, (predictors within of ), paid in training sequences rather than in tokens. Here the target is informed Bayes itself. A network trained on sequences of length therefore carries, at test time, a residual expected loss of the order of the architecture-based complexity of divided by , on top of the inner regret that pays against . The decomposition of Jeon et al. (2024) into across-task and within-task terms is this two-level structure stated for Bayes-optimal meta-learning; the framework adds that the across-task term is determined by how much of the architecture's prior mass lies near .
Three consequences connect this picture to the experiments. First, the gap of (4) measures the outer cost that training has not yet paid, at each inner time ; a network with enough training and capacity drives it to zero at every , and the shared-base and hidden-encoding curves of Figure 1 show it doing so. Second, the ordering of sources by required depth is an ordering of the targets by their architecture-based complexity under the transformer prior. The decomposition of Appendix C.3 says why: a target whose statistic is one attention head's worth of selection and counting, and whose estimator is a smooth map of a few numbers, sits in a region of predictor space that shallow transformers reach with high prior mass; a target that needs a partition inferred from a count matrix before can be applied sits where only deep compositions reach, and the prior mass there is small until the depth is available. Third, the same framework explains a transformer's preference among predictors that fit the training data equally well: it prefers those of low architecture-based complexity, so when the family leaves a choice open, as the pooled and depth posteriors do, the network's tie-breaking is the architecture's, not the data's; Appendix C.5 discusses where this can and cannot be distinguished from the Bayesian Occam factor of the family.
The training-size data already in hand give a first test of the outer cost. If the architecture can represent , the residual gap should fall roughly as the inverse of the number of training sequences; if it cannot, the gap should stall at a floor set by capacity. Both regimes appear. For the hidden encoding, the two-layer gap at falls only from 0.105 to 0.091 bits when training grows four-fold from 6.4 to 25.6 million sequences (Table 6), a floor; the eight-layer gap falls from 0.0057 to 0.0024 bits when training doubles from 12.8 to 25.6 million, close to the inverse-proportional rate. For the shared-base source the four-layer gap at changes by less than 0.0002 bits under the same four-fold increase while the eight-layer gap is still falling (Appendix D.6). The pattern is what the framework predicts: a target of low architecture-based complexity under the deeper prior is reached at the universal rate, and one of high complexity under the shallow prior is not reached at all. A dedicated scaling study, with several training sizes per architecture, would turn this into a measured exponent.
Two remarks on scope. The complexity spectrum of the layered simplex architecture is computable (Feder et al., 2026), and that is why the LSA prior serves here as the source prior: informed Bayes can be evaluated. The complexity spectrum of a transformer is not computable in the same sense, and the present paper does not attempt it; what it measures is, for six computable targets, how much depth, width and training the architecture needs to reach them, which is the empirical shadow of that spectrum. The meta-learning experiments of Grau-Moya et al. (2024) are the same measurement for a different target, the context-tree-weighting mixture and, aspirationally, Solomonoff's mixture, and their finding that transformers and LSTMs reach the same loss says that both architectures place adequate prior mass near that target at the scale they used; which of the two does so with the smaller complexity, and hence with fewer sequences, is the question the framework poses and their length-generalization results begin to answer.
C.3 SELECTION, ACCUMULATION, ESTIMATION
For every source studied here the Bayesian prediction can be written as a composition , where is a set of statistics of the prefix and maps these statistics to a distribution over the alphabet. The simplest case, and the one in which the imitation has been observed mechanistically, is a Markov chain whose rows are drawn independently from the uniform simplex (Edelman et al., 2024). There consists of the successor counts in the current context, with , and is the add-one rule ; equation (12) gives the LSA generalization at depth one. A transformer realizes this in two steps. An attention head whose query is the current token and whose keys are the past tokens attends to the positions with , and averages the one-hot successors at those positions; the output is the empirical successor distribution in the current context, and the number of matches is recoverable from the attention mass on the start token. This is the statistical induction head. The feed-forward blocks and the unembedding then have to represent . Attention thus supplies two of the three ingredients for free—selection of the positions that share the current situation, and accumulation of counts over them—and the third, the estimator , is learned by the feed-forward network. The estimator is what the prior fixes: the same counts lead to different predictions under different priors, and the coin experiment of Section 3.1 is the case with no selection at all, where the two-point-prior model and the uniform-prior model must and do learn the two different maps of (24).
Three properties of this decomposition carry over to the harder sources. Selection is content-addressed and need not be consecutive, so the same mechanism serves a context defined by the current token, by one of its coordinates, or by the whole prefix. Accumulation is exact and costs no parameters. Estimation has to be learned on the count configurations that the prior actually produces; the network is never trained on configurations it will not see, and it is trained most on the ones that occur most, which is why the residual gap depends on t in the way described in Appendix C.6.
C.4 WHAT IS DIFFERENT ABOUT THE PRESENT SOURCES
In the independent-row chain, and in the coins, regression tasks and n-gram families of earlier work, the statistics S are local: the prediction in context a depends on the prefix only through the counts in row a, and F acts row by row. The sources of Section 2 break this locality in three distinct ways, and each way has a distinct signature.
Global statistics: the shared-base source. Under the shared-base prior the prediction in row is, by (15), the posterior average of over the base law (that is, over the exponent and the rank permutation ) and the common depth . The row's own counts enter as before, but and are inferred from all rows together: the rank assignment mainly from the total token frequencies , which order the labels; the exponent from how steeply those totals fall; and the depth from how concentrated every row looks, i.e. from the count profiles of the rows. So the sufficient statistics contain a global part—the totals and the profiles—that requires attention over all past positions, not only the matching ones, and the estimator has to combine the global part with the local counts. The uniform-base control removes the global part: is known, and the only shared quantity is the depth, which matters little for prediction. The unseen-context test of Section 4.3 isolates the global part experimentally. When the current token appears for the first time, the local counts are empty and the prediction is the posterior mean of the base law, , which is a function of the global statistics alone. The transformer's gain over uniform there, 0.793 bits against Bayes's 0.799 at , , and its near-zero gain on the uniform-base control where Bayes predicts none, is direct evidence that it computes the global statistics and uses them where the family says they are informative, and only there.
A hidden partition: the product source. With a known encoding, the product structure changes selection but not estimation: the head for coordinate u must attend to the positions whose token shares the current token's u-coordinate, which is a fixed linear function of the token embedding, and the two coordinate predictions are multiplied. Two heads and one layer suffice in principle, and the two-layer model is matched to Bayes at 1024 tokens. With a hidden encoding the partition of the 16 labels into coordinates is itself a latent variable of the sequence. Bayes handles it by summing the factorized evidence over all 259 459 200 equivalence classes of encodings (Appendix B.4); no network can enumerate them, so a transformer has to infer the partition from statistics of the prefix. Labels that share a coordinate have successor distributions that agree on that coordinate's marginal, so the partition is readable from the count matrix, but only after the counts are formed: one layer to accumulate per-label successor statistics, further layers to compare them and form a soft partition, and then the factorized estimate. This is, we suggest, why the hidden-encoding source needed eight layers and 25.6 million sequences where the known-encoding source needed two layers and 6.4 million, and why the residual gap concentrates at intermediate contexts: at 256 tokens the gap is 0.022–0.025 bits while at 1024 it is 0.002, and 256 tokens is where the posterior over encodings is neither flat nor concentrated, so that the soft sum over encodings—the hardest part of F to imitate—matters most (Figure 4, Table 6).
Selecting the family: pooled training. Under pooled training the family f is one more latent variable. The Bayesian prediction is the mixture (20)–(21) of Appendix D.7, whose weights are a softmax of the cumulative log-likelihoods of the three family predictors. Family selection is therefore the same computation as parameter selection one level up: each family's evidence is a sum over positions of that family's per-position log-probabilities, a quantity attention can accumulate, and the weights are a softmax of those sums. A network trained on the pooled prior has to carry three family-specific predictions and their running evidences at once, which requires the network to combine within-family inference with an additional weighting step. At four observed tokens, increasing the model from two to four layers reduces the gap to the Bayesian mixture from 0.0197 to 0.0052 bits in run 1 and from 0.0190 to 0.0025 bits in run 2, at the same training budget.
C.5 WHY AND HOW THE STRUCTURE IS SELECTED
Why a trained network uses the shared structure rather than ignoring it follows from Section 5: under the training prior, ignoring the structure costs regret at every context length, and the objective is the expected loss over exactly that prior. The size of the incentive is the difference between the regret of the family and the regret of the larger family the network would otherwise be learning. For the shared-base source at depth zero, the family has the parameters of the base law and the tokens are independent; a predictor that treats the 64 rows as independent would have to learn parameters from the same tokens, and its regret would be far larger at every tested . The pooled setting makes the incentive explicit: not knowing the family costs Bayes at most bits cumulatively (Appendix D.7.1), whereas predicting with the wrong family costs bits on every token (Section 4.1). A network that did not select would pay the second cost; one that selects as Bayes does pays the first.
How the structure is selected is the posterior over the discrete latent variables—the family, the depth, the encoding—which is a softmax of accumulated log-evidence, and the posterior over the continuous parameters, which the estimator F represents implicitly. Two consequences follow. First, selection is soft and stays soft: the posterior over families does not always concentrate, because the shared-base and uniform-base priors both place positive mass on every positive transition matrix and remain ambiguous with unlimited data (inequality (23)). A network imitating must remain equally undecided, and the pooled comparisons at longer contexts, once the Bayesian references are complete, test exactly this. Second, the preference for the simpler structure that transformers display when the evidence is ambiguous (Deora et al., 2025) is, in our setting, the prior's preference and not the architecture's: when one family is nested in another, or a lower depth is nested in a higher one, the evidence of the smaller family integrates over fewer parameters, so its posterior weight is larger at short contexts and yields only as the counts accumulate. This is the Bayesian universality or Occam factor. A network that imitates inherits it, and departs from it only where it departs from ; the depth posterior of the shared-base source, which selects the lower depth until the row profiles rule it out, is the place to test this directly. Where the network does depart from , the architecture's own preference of Appendix C.2—for predictors of low architecture-based complexity—is the natural candidate for the direction of the departure, and a test that separates the two universality factors would compare the network's family weights with the Bayesian ones on prefixes where the family evidence is balanced.
C.6 WHAT THIS PREDICTS ABOUT CAPACITY, TRAINING AND CONTEXT
The decomposition turns the open questions of the introduction into concrete expectations, which the present experiments partly test and future ones can test further.
Capacity which allows the expressibility of the approximated target is set by the depth of the composition and by the size of S. Local counts need one layer of selection and one map; a hidden partition needs layers to form statistics, compare them and select; global statistics need width to carry d totals and row profiles beside the local counts. The sources here order themselves accordingly: coins and the known-encoding product are already well approximated by two layers; four layers improve both the known-encoding and uniform-base comparisons; and eight layers bring the hidden-encoding and shared-base models close to informed Bayes. Four layers also improve the pooled model, which must carry three family-specific predictions.
Training is set by how many distinct count configurations the estimator has to be learned on. Configurations that the prior produces rarely are learned last; for the shared-base source these are the deep, sparse rows at long contexts, and it is at that doubling the eight-layer training still helps at every depth (Figure 7).
Context enters through the nonlinearity of . At short contexts the posterior is close to the prior and is nearly constant; at long contexts the posterior is concentrated and is nearly the empirical frequency; in between, is most curved and the network's approximation is weakest. This predicts that the residual gap peaks at intermediate , and this occurs in several comparisons: at for the two-layer depth-(1, 1) product model (Figure 3), at for the two-layer uniform-base control, and at for the hidden encoding (Section 3.3). The Bayesian curve says where the hard part of each source lies, and the transformer's gap sits there.
These expectations are consistent with the comparisons reported here; they are not established by them. A direct test of the mechanism would read the attention patterns and the count-like activations against the statistics that needs, source by source.
D DETAILS FOR SECTION 3: HOW CLOSE TRANSFORMERS GET TO INFORMED BAYES
This appendix follows the same progression as Section 3 and Figure 1. Appendix D.1.1 first gives the common experimental and numerical protocol. The remaining subsections then treat the six inference problems in panel order: a source prior, a known factorization, a hidden factorization, fixed shared structure, inferred shared structure, and an unknown source family.
D.1 COMMON EXPERIMENTAL AND NUMERICAL PROTOCOL
D.1.1 MODELS, TRAINING AND TEST SETS
All models are decoder-only transformers with learned token and positional embeddings, pre-layer-normalized causal-attention and feed-forward blocks, residual connections, a final layer normalization and linear output. The feed-forward width is four times the model width, with GELU and no dropout. Table 3 specifies every model used in Section 3. Run 1 uses random seed 0 and run 2 uses seed 1. Within a run, all tests of a model at a given training length use the same saved weights.
Training minimizes mean next-token cross-entropy in single precision. AdamW uses , matrix-parameter weight decay 0.1 (none for biases or layer-normalization parameters), and gradient norm clipping at 1. The learning rate rises linearly to then follows a cosine schedule to . Warmup lasts 500 updates for coins, 3000 for the pooled model, and 1000 for the other models. Continuations instead retain the final learning rate for their additional 300000 updates. The eight-layer models use a cosine schedule over 400000 updates; their final evaluations therefore change size, amount of training and learning-rate schedule relative to the earlier 100000-update models. All next-token positions enter the training loss; each sequence receives newly drawn source parameters under its full training prior. The pooled training schedule balances the three families, giving 6.4 million sequences per family and 19.2 million in total. Training, monitoring and test data come from separate random streams. The code repository lists the configuration and the command for
| Source and model | Layers | Width | Heads | Parameters | Updates | Seq. () | Runs |
|---|---|---|---|---|---|---|---|
| Coins, each prior | 2 | 64 | 4 | 116736 | 20000 | 1.28 | 1 |
| Product, known encoding | 2 | 128 | 4 | 544256 | 100000 | 6.4 | 1 |
| Product, known, four-layer | 4 | 256 | 8 | 3454464 | 100000 | 6.4 | 2 |
| Product, hidden, two-layer | 2 | 128 | 4 | 531968 | 100000 | 6.4 | 2 |
| Product, hidden, continued | 2 | 128 | 4 | 531968 | 400000 | 25.6 | 2 |
| Product, hidden, four-layer | 4 | 256 | 8 | 3429888 | 100000 | 6.4 | 2 |
| Product, hidden, four-layer continued | 4 | 256 | 8 | 3429888 | 400000 | 25.6 | 2 |
| Product, hidden, eight-layer | 8 | 512 | 8 | 25760768 | 400000 | 25.6 | 2 |
| Uniform-base LSA, | 2 | 128 | 4 | 544256 | 100000 | 6.4 | 1 |
| Uniform-base LSA, four-layer | 4 | 256 | 8 | 3454464 | 100000 | 6.4 | 2 |
| Shared-base LSA, two-layer | 2 | 128 | 4 | 544256 | 100000 | 6.4 | 2 |
| Shared-base LSA, four-layer | 4 | 256 | 8 | 3454464 | 100000 | 6.4 | 2 |
| Shared-base LSA, four-layer, shuffled | 4 | 256 | 8 | 3454464 | 100000 | 6.4 | 2 |
| Shared-base LSA, four-layer continued | 4 | 256 | 8 | 3454464 | 400000 | 25.6 | 2 |
| Shared-base LSA, eight-layer | 8 | 512 | 8 | 25809920 | 400000 | 25.6 | 2 |
| Pooled, three families | 2 | 128 | 4 | 544256 | 300000 | 19.2 | 2 |
| Pooled, four-layer | 4 | 256 | 8 | 3454464 | 300000 | 19.2 | 2 |
Table 3: Training settings for the reported models. Contexts are 256 tokens for coins and 1024 otherwise; sequences contain one additional target token. Every update uses 64 fresh sequences. Continued models retain their checkpoint parameters and optimizer state; other model sizes are trained from fresh initialization.
| Source | Fixed test condition | Sequences | Length |
|---|---|---|---|
| Two-point coins | ; 0.8 | 2076; 2020 | 257 |
| Uniform-prior coins | Each , 0.3, 0.5, 0.7, 0.9 | 4096 | 257 |
| Product | Each , , , | 256 | 1025 |
| Hidden encoding | Full prior | 3840 | 1025 |
| Uniform-base LSA | , 1, 4, 8, respectively | 112, 101, 115, 119 | 1025 |
| Shared-base LSA | ; each , 1, 4, 8 | 256 | 1025 |
| Pooled families | Each family's full prior | 1024 | 1025 |
Table 4: Test sets for the main comparisons. The parameters that define a test setting are never shown to the predictors. The uniform-base groups are parts of one full-prior test set of 1024 sequences. The hidden-encoding test set leaves out the 256 sequences that we used while developing the experiment.
every model and every figure. In the product source with known encoding, the generator also relabels the values of each coordinate at random for every sequence. This does not change the distribution of the source, because the rows are independent and exchangeable.
The four-layer known-product and uniform-base models use the same source priors, training budgets and learning-rate schedules as their two-layer counterparts, with independently drawn training sequences. Both larger runs are compared with the same two-layer checkpoint on the same test sequences. For pooled training, the two sizes additionally receive the same indexed training sequences within each run. All comparisons use the final checkpoint; no run is selected by its test performance.
D.1.2 SCORING AND UNCERTAINTY
A sequence of length supplies scored predictions: after observing , the predictor scores , for . The first token informs inference but is not scored. Conditional expected next-token loss is
We suppress when the realized source is understood. For a Markov source the scoring law is its current true transition row. Subtracting that row's entropy and averaging gives (2). Source parameters are used only for scoring and grouping, never supplied to the predictors. Histories follow the specified initial law; stationarity is not assumed.
With the first token supplied, cumulative loss and regret through token n are
In particular, . For independent sequences , uncertainty in a statistic uses
Model differences and cumulative sums are formed within each sequence before aggregation. Tokens are not independent replicates; training-run variation is reported separately. Unless stated otherwise, numerical values give one standard error across sequences, not numerical integration error or simultaneous coverage across times.
Averaging over the full training prior gives the population identity
An estimated gap can nevertheless be negative through sampling error. If evaluation fixes parameters or selects a different source distribution while Bayes retains its training prior, the identity and ordering need not hold even in the population.
D.1.3 BAYESIAN EVALUATION AND NUMERICAL PRECISION
Rows, coins and known-encoding chains. We tabulate the transforms in (9) once and reuse them. The row integral is computed on a grid in . Products are evaluated as sums of logarithms, and a base weight enters as the shift . For sources with a common depth, the row probabilities are multiplied first, and the average over the depth is taken afterwards. Independent coordinates are then combined. We check the results in four ways: against the closed forms at depth zero and depth one, against the product factorization, by comparing sequential with batch evaluation, and by refining the grid. In 198 row checks with up to 1024 observed tokens, a wider integration range and half the grid spacing changed the log probabilities by less than bits, and the closed-form cases agreed within bits. These checks cover the tested count vectors, not every possible history. For coins, closed-form count formulas and finite binomial sums check the Bayesian predictions and regrets. A separate script recomputes every reported number from the saved predictions. It checks the identity of source and model, that every prediction uses only earlier tokens, that the probabilities sum to one, and the averages and paired standard errors. We never rescale probabilities to make results agree.
Shared-base inference. At , we sum over the ranks of observed labels and integrate over exponent and shared depth. There are 15 repetition patterns at four tokens. Small-alphabet enumeration checks this calculation; refinement changes the reported regrets by less than bits. At , posterior sampling covers the unknown rank assignment and exponent while integrating over the common depth and rows. Every sequence has two independently seeded calculations at 16 and 32 exponent nodes, each with four chains and 16384 warmup moves. Retained draws are extended from 4096 to as many as 65536 per chain at , and 262144 at . A separate script checks chain agreement, effective sample sizes, predictive moments and refinement of both integration rules, requiring split for all monitored coordinates, probability effective sample sizes at least 200, maximum probability Monte Carlo standard error at most 0.005, and raw conditional and averaged predictive normalization errors at most .
Numerical error is assessed separately from source-to-source variation. For a test set of N sequences, the numerical variance of its mean is the sum of individual numerical variances divided by . The numerical error bound combines twice the numerical standard error and twice the estimated bias from taking a logarithm of a sampled probability. It must be below 0.01/3 bits and below one quarter of the sequence standard error after subtracting estimated numerical variance. All 256 sequences enter every reported depth-specific mean. The largest accepted numerical error bounds are 0.0023 bits at t = 16 and 0.0017 at t = 64; the largest time-64 change between integration orders is 0.00050 bits. All 2048 individual time-64 references (two orders for each of four test sets of 256 sequences) pass the checks.
(a) ,

(b) ,

(c) ,
(d) ,


Observed tokens, t
Figure 3: A known factorization: the two-layer gap to informed Bayes. Each panel uses 256 independent sequences at its fixed coordinate-depth pair, matching panel (b) of Figure 1. Positive values mean larger expected next-token loss for the transformer. Bars give one standard error of the paired differences across sequences. The common vertical scale makes the different transient gaps visible.
D.2 A SOURCE PRIOR: COINS
The other coin comparisons confirm that the transformer learns the training prior. Figure 1 shows . For the two-point prior, the test sequences at and at are the two parts of one full-prior test set. For the uniform prior we drew new sequences at each displayed bias. Closed-form binomial sums confirm the means of informed Bayes.
For 4096 independent full-prior sequences per coin model, cumulative gap over 256 predictions is bits for the two-point prior and for the uniform prior. The sequence-averaged predictive divergences are respectively and bits. We reconstruct binary probabilities from the saved probability of the observed token, verify them against full vectors and replay fixed sequences against the checkpoints, avoiding lower-precision vectors when estimating these small divergences.
D.3 A KNOWN ENCODING: PRODUCT SOURCE
Four layers bring the transformer closer to informed Bayes at the same training budget. Across the four depth pairs, the gaps after 1024 observed tokens are 0.0012–0.0031 bits in run 1 and 0.0026–0.0056 bits in run 2, compared with 0.004–0.009 bits for the two-layer model. The largest gaps across the evaluated contexts are and bits for the four-layer runs, both at after 16 tokens; the two-layer maximum is bits after 32 tokens. The comparison uses the same 256 sequences at each depth pair and . Figure 5 shows both larger runs.
The full-distribution comparison also measures the two-layer model’s agreement. Figure 6(a) reports at every evaluated context. On 128 independent full-prior sequences, its accumulated transient contributes a cumulative gap of bits over 1024 predictions.
| Depths | ||||||
|---|---|---|---|---|---|---|
| Inf. Bayes | Transformer | Inf. Bayes | Transformer | Inf. Bayes | Transformer | |
| (1,1) | 725 | 862 | 363 | 363 | 91 | 108 |
| (1,8) | 609 | 725 | 256 | 305 | 77 | 91 |
| (4,4) | 725 | 725 | 305 | 305 | 91 | 91 |
| (8,8) | 512 | 512 | 216 | 216 | 64 | 77 |
Table 5: First tested context reaching each regret target. Six pairs coincide; six differ by one grid step, a ratio of about 1.18–1.20. Simultaneous uncertainty sets overlap for every pair; the two predictors therefore require the same context within the resolution of this experiment.
D.3.1 PREDICTING THE REQUIRED CONTEXT
For target regret and tested times , define
with nonattainment if the set is empty. Close curves can have different crossings near a flat region. We therefore fixed targets bits and a refined grid before independent confirmation. Starting with , we added , around each development Bayesian crossing , clipped to [1, 1024]. The resulting grid has 26 times. At each of four depth pairs, 1024 fresh sequences of length 1025 were drawn; all Bayesian forecasts were saved before evaluating the trained transformer. Neither predictor receives the source depths. No interpolation, monotonic smoothing or deletion of unreached outcomes is used.
For uncertainty, 4096 whole-sequence bootstrap resamples retain all times and both predictors together within each depth condition, while conditions are resampled independently. The maximum standardized mean deviation gives a simultaneous band with multiplier 3.60. A crossing time is compatible if its lower bound reaches the target and no earlier upper bound forces a crossing; nonattainment is retained if every upper bound remains above the target. Both sets are finite and overlap in all twelve comparisons. This concerns one fixed model. Exact depth-one checks, wider integration, causal token-index tests and independent aggregation of all 4096 sequences pass.
D.4 DISCOVERING A FACTORIZATION: HIDDEN ENCODING
The source makes the factorization latent while retaining an exact informed Bayes. Every draw has fresh transition matrices and a fresh encoding. At , each transformer and informed Bayes receive the same tokens; informed Bayes integrates over the unknown encoding. An oracle that is told the encoding provides a separate measure of the cost of discovering the factorization.
Scaling brings the transformer to the informed Bayesian curve. At , the two-layer models have regrets 0.1430 and 0.1335 bits in the two runs, compared with 0.03781 bits for informed Bayes. The eight-layer models trained on 25.6 million sequences reach 0.0402 and 0.0397 bits, leaving gaps of and bits. Doubling their training from 12.8 to 25.6 million sequences reduces the final gap by a further 0.0033 bits in each run.
The intermediate models show the same progression. Increasing the two-layer models' training from 6.4 to 25.6 million sequences reduces their endpoint regret by and bits. At 6.4 million sequences, moving from two to four layers reduces it by and bits. The final four-layer regrets are 0.1067 and 0.0563 bits, establishing the contribution of size before the eight-layer models nearly close the remaining gap.
The oracle comparison separates this scaling result from the intrinsic cost of the hidden encoding. At , regret is 0.03781 bits when the encoding is hidden and 0.03727 when it is revealed; integrating this difference over 1024 predictions gives bits. The two-layer transformers have additional cumulative gaps of and bits, which size and training reduce to and bits.
All reported comparisons use the same 3840 evaluation sequences and exclude the 256 development sequences. A separate script checks the test set, the checkpoint identities, the informed-Bayes values,
| Predictor | Run | Next-token regret | Gap to informed Bayes | Cumulative gap |
|---|---|---|---|---|
| Informed Bayes | - | 0.0378 ± 0.0004 | 0 | 0 |
| 2 layers, 6.4M | 1 | 0.1430 ± 0.0014 | 0.1052 ± 0.0013 | 108.38 ± 0.63 |
| 2 layers, 6.4M | 2 | 0.1335 ± 0.0013 | 0.0957 ± 0.0012 | 105.35 ± 0.62 |
| 2 layers, 25.6M | 1 | 0.1283 ± 0.0013 | 0.0905 ± 0.0012 | 99.81 ± 0.59 |
| 2 layers, 25.6M | 2 | 0.1199 ± 0.0012 | 0.0821 ± 0.0011 | 98.63 ± 0.58 |
| 4 layers, 6.4M | 1 | 0.1091 ± 0.0011 | 0.0713 ± 0.0010 | 94.07 ± 0.58 |
| 4 layers, 6.4M | 2 | 0.0751 ± 0.0008 | 0.0373 ± 0.0007 | 55.99 ± 0.41 |
| 4 layers, 25.6M | 1 | 0.1067 ± 0.0011 | 0.0689 ± 0.0009 | 88.83 ± 0.53 |
| 4 layers, 25.6M | 2 | 0.0563 ± 0.0007 | 0.0185 ± 0.0005 | 37.19 ± 0.28 |
| 8 layers, 25.6M | 1 | 0.0402 ± 0.0005 | 0.0024 ± 0.0002 | 9.57 ± 0.10 |
| 8 layers, 25.6M | 2 | 0.0397 ± 0.0005 | 0.0018 ± 0.0001 | 8.49 ± 0.09 |
Table 6: Discovering a factorization: scaling toward informed Bayes. All quantities are in bits, averaged over the same 3840 test sequences of length 1025, excluding the 256 development sequences. Next-token regret scores prediction of token 1025; the gap subtracts the informed Bayesian regret. The cumulative gap sums the loss difference over predictions of tokens 2 through 1025. Uncertainties are one standard error across sequences, using paired differences for both gap columns.

Observed tokens, t
Figure 4: Discovering a factorization: size and training. Left: training run 1; right: training run 2. Each panel shows the two-layer transformer as a solid curve and the larger transformers as dashed curves; colors distinguish their sizes and training lengths. Legend numbers give training sequences in millions. Unconnected open circles show informed Bayes. All comparisons use the same 3840 test sequences and axes. Shading and bars give one standard error across sequences.
the model scores and the paired statistics. Table 6 gives the endpoint values; Figure 4 gives both runs at every context.
D.5 A KNOWN BASE LAW: UNIFORM-BASE SOURCE
With a known, uniform base law, this source tests whether the transformer learns the prior on the rows. Increasing the model from two to four layers at the same training budget improves agreement at all four displayed depths (Figure 5). At , the four-layer gaps range from 0.00007 to 0.02762 bits in run 1 and 0.00003 to 0.01460 bits in run 2. In particular, both models nearly close the two-layer model's 0.030-bit endpoint gap at . Their largest gaps over the evaluated contexts are and bits, both at , .
Figure 6(b) shows the two-layer model's full-predictive divergence. On 128 independent full-prior sequences, the transient gives a cumulative gap of bits over 1024 predictions. Together, the two panels compare the two-layer models in the known-product and uniform-base experiments.
Two-layer transformer -- Four-layer transformer o Informed Bayes
(a) Known product, run 1
Expected next-token regret (bits)

(b) Known product, run 2
(c) Uniform base, run 1

(d) Uniform base, run 2


Observed tokens, t
Figure 5: Known structure: increasing model size at fixed training budget. Rows show the known product encoding and the uniform-base source; columns show the two independent four-layer runs. Solid curves show the same two-layer baseline in both columns, dashed curves the four-layer model, and open circles informed Bayes. All models receive 6.4 million training sequences from the corresponding prior and use the fixed test sets in Table 4. Colors identify the same source settings as Figure 1; shading and bars give one standard error across test sequences.
D.6 AN UNKNOWN SHARED BASE LAW: SHARED-BASE SOURCE
More layers and more training brings both runs close to informed Bayes. After 64 tokens, the eight-layer models' gap ranges from -0.0017 to 0.0066 bits across all four depths and both runs. The two-layer models have gaps as large as 0.220 bits, while the four-layer models trained on the same 6.4 million sequences reduce the largest gap to 0.040 bits. Table 7 gives the paired comparison at every depth.
Training the eight-layer models for 25.6 rather than 12.8 million sequences reduces their regret after 1024 tokens at every depth and in both runs, by 0.0045–0.0096 bits. At , the final eight-layer gaps are and bits, compared with and for the four-layer models at 6.4 million sequences. Figure 7 shows the complete scaling sequence. All models are evaluated on the same 256 sequences per depth, with checkpoints fixed before evaluation.
The long-sequence calculations in Appendix D.6.1 apply the same independent-chain and integration-order checks at 256 and 1024 tokens. All eight depth-and-context combinations use complete test sets of 256 sequences. Their numerical error bounds are at most 0.000605 bits and are reported separately from source variation in Table 8.

Observed tokens,

Figure 6: Informed-Bayes-to-transformer predictive divergence. Full-distribution comparison of the two-layer models for (a) the known product factorization and (b) the uniform-base LSA source at . The horizontal axis counts observed tokens. Points show the mean of , in bits, over 128 independent sequences of length 1025 from each training prior; bars give one standard error. Lines join the evaluated contexts. Both panels use the same vertical scale.
| L | Run | 2 layers, 6.4M | 4 layers, 6.4M | 4 layers, 25.6M | 8 layers, 25.6M |
|---|---|---|---|---|---|
| 0 | 1 | 0.2167 ± 0.0088 | 0.0395 ± 0.0038 | 0.0281 ± 0.0030 | 0.0065 ± 0.0010 |
| 0 | 2 | 0.2199 ± 0.0090 | 0.0287 ± 0.0032 | 0.0263 ± 0.0029 | 0.0034 ± 0.0008 |
| 1 | 1 | 0.1149 ± 0.0099 | 0.0169 ± 0.0043 | 0.0144 ± 0.0039 | 0.0066 ± 0.0015 |
| 1 | 2 | 0.1213 ± 0.0093 | 0.0103 ± 0.0039 | 0.0079 ± 0.0035 | 0.0005 ± 0.0013 |
| 4 | 1 | 0.0122 ± 0.0116 | 0.0146 ± 0.0057 | 0.0103 ± 0.0052 | 0.0026 ± 0.0026 |
| 4 | 2 | 0.0227 ± 0.0118 | 0.0141 ± 0.0055 | 0.0129 ± 0.0055 | 0.0037 ± 0.0021 |
| 8 | 1 | 0.0892 ± 0.0128 | 0.0049 ± 0.0048 | 0.0056 ± 0.0043 | -0.0017 ± 0.0020 |
| 8 | 2 | 0.0822 ± 0.0130 | 0.0103 ± 0.0043 | 0.0129 ± 0.0049 | 0.0028 ± 0.0021 |
Table 7: Inferring shared structure: the gap to informed Bayes after 64 tokens. Next-token loss differences in bits at , averaged over 256 paired sequences per depth. Uncertainties are one standard error across sequences.
D.6.1 AGREEMENT AT LARGE
Table 8 gives the comparisons at all four depths after 256 and 1024 tokens, on 256 sequences each. Every sequence is evaluated twice with different random seeds, using 16 and 32 integration nodes, or 32 and 64 nodes for . We report a mean only if every sequence and the mean itself pass the numerical checks of Appendix D.1.3. Sequences from an earlier trial with eight sequences are included in the 256 and are not counted twice.
The numerical Monte Carlo uncertainty is distinct from variation between sources. The table reports one source standard error for regret and paired differences, and the separate numerical error bound. Informed Bayesian optimality is prior-averaged, so fixed-setting differences can have either sign.
At , four-layer models after 100000 updates have gaps and bits. Extending training to 400000 gives and . The final eight-layer models reduce these gaps to and bits. This comparison uses both runs and the models at the end of training. No model was selected by its test performance.
D.7 INFERRING THE SOURCE FAMILY: POOLED TRAINING
The pooled transformers closely reproduce the informed Bayesian mixture. After four tokens, increasing from two to four layers reduces the gap from 0.0197 to 0.0052 bits in run 1 and from
2 layers: 6.4M --- 4 layers: 25.6M ○ Informed Bayes 4 layers: 6.4M --- 8 layers: 25.6M
(a) L = 0, run 1

(b) L = 0, run 2
(c) L = 1, run 1

(d) L = 1, run 2

(e) L = 4, run 1

(f) L = 4, run 2

(g) L = 8, run 1

(h) L = 8, run 2

Observed tokens, t

Figure 7: Inferring shared structure: size and training. Rows show source depths L = 0, 1, 4, 8; columns show the two training runs. Each panel shows the two-layer transformer as a solid curve and the larger transformers as dashed curves; colors distinguish their sizes and training lengths. Legend numbers give training sequences in millions. Unconnected open circles show informed Bayes at all six displayed contexts. Each depth uses the same 256 sequences for every predictor, and the two runs share a vertical scale. Shading and bars give one standard error.
| L | t | Informed Bayesian regret | Run 1 gap | Run 2 gap | Numerical error bound |
|---|---|---|---|---|---|
| 0 | 256 | 0.08323 ± 0.00123 | 0.00470 ± 0.00051 | 0.00303 ± 0.00034 | 0.000108 |
| 0 | 1024 | 0.02739 ± 0.00040 | 0.00409 ± 0.00017 | 0.00246 ± 0.00014 | 0.000033 |
| 1 | 256 | 0.47945 ± 0.01265 | 0.00508 ± 0.00137 | 0.00130 ± 0.00114 | 0.000443 |
| 1 | 1024 | 0.31776 ± 0.01116 | 0.00240 ± 0.00089 | 0.00315 ± 0.00070 | 0.000147 |
| 4 | 256 | 0.98501 ± 0.03914 | 0.00318 ± 0.00151 | 0.00263 ± 0.00133 | 0.000551 |
| 4 | 1024 | 0.52011 ± 0.02917 | 0.00327 ± 0.00097 | 0.00141 ± 0.00104 | 0.000242 |
| 8 | 256 | 1.16128 ± 0.05668 | 0.00078 ± 0.00179 | -0.00103 ± 0.00163 | 0.000605 |
| 8 | 1024 | 0.57885 ± 0.03987 | 0.00158 ± 0.00129 | 0.00423 ± 0.00116 | 0.000359 |
Table 8: Inferring shared structure at large . All quantities are in bits and use 256 paired sequences per row. The transformer gaps use the eight-layer 400000-update checkpoints. The last column is the numerical error bound of the Bayesian value, not a source standard error; its uncertainty is shared by the two model comparisons in that row.
Table 9: Two-layer cumulative gap to the informed Bayesian mixture. Loss differences over four predictions, in bits. Each family has 1024 independent test sequences; the final row averages the three family means equally. Values are means one paired standard error.
| Generating family | Training run 1 | Training run 2 |
|---|---|---|
| Product | ||
| Shared-base LSA | ||
| Uniform-base control | ||
| Equal-family average |
0.0190 to 0.0025 bits in run 2. After one token, the four-layer gaps are 0.0080 and 0.0067 bits. Thus the same agreement holds when prediction requires both inference within each source family and inference over the family itself.
Each model is trained without family labels on equal proportions of product, shared-base and uniform-base sources, receiving 6.4 million sequences per family. For the family probability , integrated over its prior, informed Bayes uses
All three initial-token probabilities are 1/64, and every component probability and prediction concern the same observed history.
The test set has 1024 independent sequences from each family, drawn from its full prior. We average within families and then weight families equally; the variance of this average is the sum of family-mean variances divided by nine. Both runs use the same test set. Figure 8 compares both model sizes with informed Bayes through . Bayesian estimates at use a fixed subset of 64 histories per family. At , the four-layer models have regrets 0.3787 and 0.3751 bits, improving on the two-layer models by and bits. Table 9 gives the two-layer models' cumulative comparison through four predictions. Conditional family differences may have either sign because Bayesian optimality applies to the complete mixture prior.
Reference validation. Product and uniform-base probabilities use the checked row integrals and common-depth averaging. At , shared-base probabilities use exhaustive short-pattern integration over exponent, depth and permutation. Its raw normalization error is below , and an independent initial-prediction check agrees within . Sequential mixture predictions and direct agree within bits on 24 sequences through four predictions. For longer histories, annealed sequential Monte Carlo estimates the shared-base sequence and successor probabilities jointly. Their ratio gives the predictive probabilities used in the mixture.
Two-layer transformer --- Four-layer transformer ○ Informed Bayes
Expected next-token regret (bits)
(a) Training run 1

(b) Training run 2
Observed tokens, t

Figure 8: Inferring the source family: two independent runs. Each panel compares a two-layer transformer (solid curve) and a four-layer transformer (dashed curve), trained on the same 19.2 million indexed sequences from the three 64-symbol families. Open circles show the informed Bayesian mixture through t = 1024. Transformer curves and Bayes at t = 1, 4 use 1024 histories per family; Bayes at longer contexts uses 64 per family. Both runs share their test histories. Shading and bars give one standard error across histories.
The estimate at uses eight repetitions per history. At , each of the 192 histories uses 32 independent repetitions with 8192 particles. Separate particle, exponent and row-integration refinements give a total numerical allowance of 0.00205 bits for the pooled mean, below the 0.01/3-bit budget. This numerical allowance is distinct from the standard error across test histories.
D.7.1 THE COST OF FAMILY UNCERTAINTY
Following Bayesian model-averaging comparisons (Zhang et al., 2025; Bai et al., 2023; Panwar et al., 2024; Deora et al., 2025), let score tokens with the generating family known but its parameters unknown. Define
Every family assigns the same probability, so
Thus bounds the cost; is the cumulative transformer–mixture gap in Table 9.
For , validated component likelihoods allow a population sum. Separate coordinate relabeling represents each history by equality patterns , with multiplicity ; there are at most pairs for five tokens. For representatives ,
Total-mass checks pass without renormalization. For the costs are 0.01163, 0.04415, 0.10227, 0.17562 bits, without test-sample uncertainty. Adding the paired transformer–mixture sample mean gives and bits for runs 1 and 2. This paired estimate has variance equal to the sum of within-family paired variances divided by ; numerical error is assessed separately. Informed Bayes explains most of the early cost.
Residual family ambiguity. The limiting cost obeys
An infinite trajectory identifies its positive transition matrix through empirical transition frequencies. Conditional on , future tokens contain no further information about , so the limit is . The product prior lies on the lower-dimensional set of product matrices; the depth-zero shared-base and uniform-base priors give identical nonuniform Zipf rows and the uniform matrix, respectively. These components are mutually singular, so is identified almost surely there.
The positive-depth shared-base and uniform-base priors instead have positive densities over all positive transition matrices. At depth one, uniform-simplex rows multiplied by positive base weights and normalized are an invertible smooth image of the simplex interior; conditioning on the other factors extends absolute continuity to larger depths. Thus both families remain possible on this continuous component, whose prior mass is . At most one bit of family entropy remains there and strictly positive entropy does remain. Hence , proving the bound. Even unlimited data need not identify the generating family.
Across all six source constructions, the detailed comparisons support the same progression as Section 3. The two-layer transformer closely tracks informed Bayes when the relevant structure is directly accessible; more layers and more training closes the gap when the encoding or shared structure must be inferred; and pooled training extends the same correspondence to inference over source families.
E DETAILS FOR SECTION 4: FOUR FURTHER TESTS
This appendix follows the four scenarios in Section 4 and Figure 2: source mismatch, a time-varying source, an unseen context, and the emergence of copying. Each subsection first specifies the scenario and the informed Bayesian response, then gives the complete transformer comparison and its numerical checks.
E.1 COMMON EXPERIMENTAL AND NUMERICAL PROTOCOL
The transformer’s weights are fixed before evaluation. Informed Bayes continues to use the family and prior represented in the transformer’s training sequences. During evaluation, neither predictor receives the test parameters or a signal identifying the test condition. Test sets are independent at the level of complete source draws or sequences. Paired conditions share histories, source parameters and the random numbers that drive the source wherever their test laws permit.
All losses and regrets are in bits. Means compare predictions on the same histories, and uncertainty is computed across whole sequences, preserving all tested times and paired conditions. Unless a caption states otherwise, curves show pointwise 95% intervals and textual ± values give one standard error. Training-run variation is reported separately from sequence-to-sequence variation.
Exact finite sums are used when available. Calculations with continuous or latent variables are repeated with independent integration rules or chains, and, except for explicitly marked preliminary estimates, test-set means are reported only after every required reference passes the criteria in Appendix D. Saved forecasts are checked in raw probability space; none is clipped or renormalized for agreement.
E.2 SOURCE MISMATCH
The fixed predictors receive sequences from a product test source whose 64 states have random token labels, rather than the coordinate-revealing labels used in training. This source has the same entropy and predictability as the ordinary product source, but its labels hide the coordinate factorization. Informed Bayes retains the training product prior and approaches the product projection derived below. At and , its predicted stationary regrets are and bits. At depth four and , informed Bayes has regret 2.299 bits. The two-layer transformer has 2.309 bits, and the two four-layer runs have 2.300 and 2.305 bits.
E.2.1 MATCHED PRODUCT TEST CONDITIONS
We use run 1 of the known-encoding product transformer (two layers, width 128, 544256 parameters, 100000 updates) and its informed Bayesian predictor. Bayes assigns independent uniform depth priors on to the two coordinates, with each coordinate's depth shared across its rows.
For the random-label condition we also evaluate both four-layer known-encoding product models: width 256, eight heads and 3454464 parameters. All three transformers have 100000 updates and see 6.4 million sequences from the same training prior, with independently drawn training sequences. The two four-layer runs use the same 1024 test histories per depth and the same Bayesian forecasts as the two-layer model. We report the runs separately.
At each of and , we generate 1024 matched sets of four test histories: a stationary product source, a product source observed through random joint labels, a time-varying source with one new coordinate matrix after the change point, and a time-varying source with two. The initial state is uniform. The random-label condition uses a fresh uniform permutation of the 64 labels,
without shuffling token positions. Common initial states and uniform random numbers pair all four conditions. Histories extend untruncated through the transformer’s limit of 1024 tokens.
Regret is the KL divergence from the actual current transition row to the forecast. We also measure the paired transformer-minus-Bayes regret and .
Pairing, the random label mapping and the parameter boundary are checked against the full 64-state matrices. Sixteen test histories spanning all conditions and depths pass wider-integration and exact depth-one checks; the largest depth-one probability discrepancy is below . All saved forecasts pass raw normalization checks and agree on the shared prefixes. The four-layer forecasts also pass separate-prefix causal checks. Their regrets, predictive divergences and paired standard errors are recomputed from the saved forecasts on all test histories.
E.2.2 PRODUCT PROJECTION AND RESIDUAL INFORMATION LOSS
The product projection identifies the exact information excluded by the visible factorization and therefore predicts the random-label mismatch cost.
Let be the true transition matrix on the visible states, with stationary law and stationary pair law . The assumed model is . Maximizing its stationary expected log likelihood separately over each stochastic row gives
The coordinate processes need not themselves be Markov: these are conditionals of stationary pairs. Positivity makes the full chain ergodic and both row-wise maximizers unique.
For every history, the assumed likelihood factors into coordinate transition-count likelihoods. Independent factor priors therefore give independent posteriors even when the true coordinates are dependent. Empirical pair frequencies converge to the marginals of J. Each factor prior gives positive mass to every neighborhood of every positive transition matrix, since its depth-one component has independent uniform Dirichlet rows. The limiting log likelihood has the unique maximizer , so posterior mass outside its neighborhoods vanishes and the predictive matrix approaches . Averaging over depth shared across rows changes the predictions at finite t, but not this limit.
Residual information loss. The stationary regret of this product projection is
| Two layers | Four layers, run 1 | Four layers, run 2 | ||
|---|---|---|---|---|
Table 10: Product mismatch with two- and four-layer transformers. Paired transformer-minus-Bayes regret, mean ± one standard error in bits, on the same 1024 random-label histories per depth. All models have the same training prior and sequence budget. Negative differences are possible because the test source lies outside the training family.
| Condition | Transformer | Bayes | Paired difference | |
|---|---|---|---|---|
| Visible product labels | ||||
| Random joint labels | ||||
| One new matrix after | ||||
| Two new matrices after | ||||
| Visible product labels | ||||
| Random joint labels | ||||
| One new matrix after | ||||
| Two new matrices after |
Table 11: Regret after 1024 tokens under four product test sources. The transformer has two layers. Mean ± one standard error in bits over 1024 paired test sets per depth. The last column is the paired transformer–Bayes difference; informed Bayes retains its training product prior in every condition.
These are the predictive dependencies excluded by the assumed factorization. They vanish with visible product labels. The random-label test law has the same entropy rate but generally contains predictive dependencies that visible-product Bayes excludes, making . Since uniform prediction is itself a product of two coordinate predictions, . This bounds the optimal stationary product regret, not the regret at every finite . The stationary average also differs from the realized current-row regret, which varies with state.
For each saved random-label test condition, we calculate the stationary law from its two coordinate matrices and saved label mapping. The finite sums above then give the following means ± one standard error over the 1024 test sources per depth, without fitting any prediction curve:
| limiting expected loss | |||
|---|---|---|---|
A direct 64-state KL calculation agrees with the entropy formula within bits; an independent stationary solve agrees within . These are unbounded-history informed-Bayesian limits. The experiments start from a uniform state and stop at 1024 tokens; their curves at finite approach the limits from that common initial law.
E.2.3 COMPLETE PRODUCT COMPARISONS
Table 11 gives all eight two-layer endpoint comparisons, and Figure 9 gives the complete depth-one curves. For this model, final predictive divergence is below 0.005 bits in every condition. On the random-label test sequences, its gap reaches 0.320 bits at depth one and 0.209 bits at depth four, both after 32 tokens, before the gap becomes small.
Both four-layer runs reduce this intermediate-context gap (Table 10). Their largest gaps on the tested grid occur after 16 tokens: 0.129 and 0.137 bits at depth one, and 0.087 and 0.095 bits at depth four. Predictive divergence also decreases at : from 0.0795 to 0.0117 and 0.0115 bits at depth one, and from 0.0724 to 0.0137 and 0.0140 bits at depth four.
Two-layer transformer
Informed Bayes
(a) Visible product labels

(b) Random joint labels
(c) One new matrix after t = 256
(d) Two new matrices after t = 256

Observed tokens, t
Observed tokens, t
Figure 9: Complete product comparisons at depth one. Source depths are . Solid curves show the two-layer transformer and unconnected open circles show informed Bayes; all conditions average 1024 paired draws, with pointwise 95% intervals. The dotted random-label limit, 0.966 bits, is calculated from the test-source matrices.
E.3 TIME-VARYING SOURCE
Both fixed predictors receive sequences from a time-varying product source. One condition uses a new transition matrix for one coordinate after 256 tokens; the other uses new matrices for both coordinates. The state, encoding and observed history continue across the boundary, so the first new matrix generates from the observed . Neither predictor is reset or receives a change signal. The new matrices have the same fixed depths, and the one- and two-matrix conditions use the same new first matrix. Informed Bayes updates under its stationary product prior and predicts that two independent changes produce twice the additional regret of one. The transformer follows both the Bayesian adaptation curve and this factor-of-two prediction.
E.3.1 ADDITIVITY FOR A TIME-VARYING SOURCE
The factor of two in (6) is an exact population identity at every t for additional regret in the paired experiment of Appendix E.2.1.
Factorization and additivity. The independent coordinate priors imply, for every history,
A common depth couples rows within each coordinate, but not the two coordinates. Bayes continues to use this stationary product model when the test source varies with time. The actual post-boundary next-token law also factors into current rows . Therefore, for every sequence,
Let be the expected regret of a coordinate that continues with its first matrix and that of a coordinate using a new matrix. The coordinate alphabets, depth laws, initial-state laws and predictor priors are identical, so
Subtracting the stationary regret proves the doubling identity. No equilibrium start or large-context approximation is required. Different coordinate laws would still yield additive contributions, but not generally equal contributions. A transformer’s predictions need not factor, so the same relation is a separate behavioral test.
Paired contrast and simultaneous uncertainty. For source draw i and predictor M, define
where is conditional next-token regret. The paired construction makes the difference between the two coordinates' additional regrets. Hence , although individual need not vanish. We estimate uncertainty from whole paired test sets, preserving correlations across conditions and times.
A centered nonparametric bootstrap resamples the test sets of the two depths independently, retaining both predictors and all 14 post-change times ( on the tested grid) within each draw. For each of 10000 resamples we take the largest absolute mean deviation divided by its reported paired standard error over all 56 depth/predictor/time combinations. The 95% quantile is 3.156; the largest observed standardized discrepancy is 2.272. All contrasts lie within these simultaneous bands. At depth four and , transformer additional regret with two new matrices is 0.3500 bits versus the predicted 0.3451 from twice the one-new-matrix condition; the paired contrast is bits (one standard error). Thus the transformer reproduces the additive mean relation derived from the source factorization.
E.3.2 EXACT COIN CONTROL
Models and scoring. We use the coin transformers trained with equal mass on or a uniform bias on (two layers, width 64, 116736 parameters, 20000 updates). Three independent test sets contain 4096 sequences of length 257 each: iid Bernoulli(0.4), or a time-varying source with bias 0.2 for the first or 128 tokens and bias 0.8 thereafter. Both trained models receive the same sequences, keep all tokens and receive no signal at the boundary. The new bias first affects , so the prediction at uses only old tokens from before the change to predict a token from after it. At every , we score conditional expected log loss relative to the actual next-token bias. Intervals are across independent test sequences; there is one trained model per prior.
Exact count formulas. For equal prior weights on and , , a prefix with ones in tokens has posterior odds in favor of . Thus
Write and let denote the binary KL divergence in bits. Under iid test bias , the exact expected next-token regret is
Let denote the random number of ones. For , the law of large numbers gives ; bounded convergence, since , gives . At , the residual is 0.151 bits. The uniform prior instead includes the true bias and its regret vanishes.
After tokens at bias and at , the two independent numbers of ones have laws and . Their convolution gives the exact regret for this time-varying test source:
Two new matrices …… Twice the one-new-matrix value
(a) Source depth

Two-layer transformer
(b) Source depth

Informed Bayes
(c) Source depth

(d) Source depth

Observed tokens, t
Figure 10: Doubling prediction and paired departures. Top: transformer additional regret with two new matrices (solid) and twice the one-new-matrix value (dotted), at both depths. Bottom: for the transformer (filled squares) and informed Bayes (open circles), without connecting lines. Bars give approximate 95% simultaneous intervals over both depths, predictors and all post-change grid points. Every interval includes zero. Each depth averages 1024 paired draws; the multiplier two is fixed by the Bayesian identity.
Before the switch, use (25) with . These are population expectations with no fitted parameters or Monte Carlo error. Enumerating all binary histories through eight tokens, including a switch after three, verifies the count formulas within bits.
The learned prior determines adaptation. The uniform-prior transformer follows the exact Bayesian regrets closely: the maximum absolute paired mean regret difference across the three tested curves is below 0.009 bits. The two-point prior predicts persistent mismatch and delayed adaptation, and the transformer reproduces both effects (Figure 11). For iid bias 0.4, its largest paired difference is -0.0391 bits at t = 97; for the change it reaches -0.1741 bits at t = 228. For the largest magnitude is 0.1425 bits at t = 150. These are the largest values on the grid of tested t; Table 12 reports all endpoints. On these two-bias test sequences, the two-point transformer's smaller transient regret reflects prediction outside the training prior.
The saved float32 weights are evaluated with float64 log-softmax and scoring. Checks reproduce sources from fixed seeds, verify raw normalization and causal prefix predictions, and independently recompute saved summaries. Bayesian sample means additionally pass simultaneous Bernstein checks against the exact expectations over all six curves and 256 times. Predictions are neither clipped nor renormalized to pass validation.
— Prior {0.2, 0.8}
— Prior uniform on [0, 1]
— Two-layer transformer
○ Informed Bayes (exact)
(a) Mismatch: test bias

(b) Change after 128 tokens

Figure 11: Exact coin predictions under mismatch and time variation. Regret under fixed bias 0.4 (a) and under a time-varying source with bias 0.2 through 128 tokens and 0.8 thereafter (b). Solid curves are trained transformers; open circles are exact informed-Bayesian expectations. Color denotes the two-point (blue) or uniform (orange) training prior. Shading gives pointwise intervals over 4096 sequences; exact expectations have no Monte Carlo error.
| Training prior | Test source | Transformer | Exact Bayes | Paired difference |
|---|---|---|---|---|
| Two-point | 0.15109 | |||
| Uniform | 0.00279 | |||
| Two-point | 0.2 through 64, then 0.8 | |||
| Uniform | 0.2 through 64, then 0.8 | 0.08086 | ||
| Two-point | 0.2 through 128, then 0.8 | 0.56871 | ||
| Uniform | 0.2 through 128, then 0.8 | 0.27985 |
Table 12: Coin regret after 256 tokens, in bits. Transformer means and paired differences show one standard error across 4096 sequences. The Bayesian column is a population expectation; the last column instead subtracts Bayesian regret on each sampled prefix and therefore need not equal the difference of the preceding columns.
E.4 AN UNSEEN CONTEXT
When the current token appears for the first time, no continuation from its transition row has been observed. Shared-base Bayes nevertheless uses the other rows to infer their common latent base; uniform-base Bayes instead predicts uniformly. The transformers reproduce both responses. Across all twelve shared-base depth-time conditions, both larger-model runs remain within 0.015 bits of informed Bayes. In the uniform-base control, the transformer's loss above the exact uniform prediction is only 0.00035–0.00052 bits, compared with 0.071–0.411 bits for token counts.
E.4.1 SHARED-BASE TRANSFER FROM EARLIER CONTEXTS
Select histories satisfying : no continuation of the current token has previously been observed. Equivalently, first appears at time . Selection depends only on the observed tokens, so Equation (15) reduces to
Other rows and the initial token inform the shared posterior. At positive depth, the posterior mean row is generally different from ; with uniform base weights it is exactly 1/64 at every depth.
| L | t | n | Larger, run 1 | Larger, run 2 | Token counts |
|---|---|---|---|---|---|
| 0 | 4 | 210 | 0.0018 ± 0.0011 | 0.0023 ± 0.0012 | 0.0067 ± 0.0030 |
| 0 | 16 | 136 | 0.0106 ± 0.0022 | 0.0090 ± 0.0022 | 0.0173 ± 0.0062 |
| 0 | 64 | 64 | 0.0143 ± 0.0026 | 0.0123 ± 0.0018 | 0.0552 ± 0.0046 |
| 1 | 4 | 214 | 0.0005 ± 0.0016 | 0.0026 ± 0.0020 | -0.0038 ± 0.0038 |
| 1 | 16 | 136 | 0.0027 ± 0.0033 | -0.0030 ± 0.0031 | -0.0098 ± 0.0108 |
| 1 | 64 | 59 | 0.0057 ± 0.0058 | 0.0003 ± 0.0058 | 0.0497 ± 0.0107 |
| 4 | 4 | 223 | 0.0024 ± 0.0021 | 0.0041 ± 0.0022 | -0.0059 ± 0.0037 |
| 4 | 16 | 145 | -0.0031 ± 0.0042 | -0.0059 ± 0.0040 | 0.0137 ± 0.0144 |
| 4 | 64 | 66 | 0.0139 ± 0.0109 | 0.0106 ± 0.0098 | 0.0317 ± 0.0271 |
| 8 | 4 | 228 | 0.0035 ± 0.0028 | -0.0011 ± 0.0029 | -0.0013 ± 0.0051 |
| 8 | 16 | 161 | 0.0021 ± 0.0041 | 0.0076 ± 0.0042 | 0.0721 ± 0.0169 |
| 8 | 64 | 57 | 0.0117 ± 0.0110 | 0.0067 ± 0.0098 | 0.2110 ± 0.0487 |
Table 13: Loss above informed Bayes after a new token. Shared-base source at : expected next-token loss difference in bits, plus or minus one standard error across the selected sequences. Positive values favor informed Bayes. Both larger-model runs use the same histories; Bayesian numerical error is assessed separately.
With expected loss from (17), define
The saving over uniform measures useful prediction before a continuation has been seen. The comparison uses 256 independent shared-base sequences of length 1025 per depth , with . Selection varies with time, and all differences pair predictions on the same eligible histories.
E.4.2 UNIFORM-BASE CONTROL
By symmetry and conditional row independence, an unobserved row has posterior mean , also conditional on any fixed generating depth. Hence
The two-layer uniform-base transformer of Section 3.4 is evaluated on 1024 sequences whose depth is uniform on . At depths , the eligible counts at times are respectively , , and . Every eligible sequence enters. At , , transformer and token-count losses above the uniform prediction are and bits.
E.4.3 NUMERICAL VALIDATION
Time 4 uses deterministic rank marginalization; times 16 and 64 use independent 16- and 32-node calculations with the criteria in Appendix D. All twelve selected test sets pass. At time 64, the refinements retain all 66 and 57 eligible histories at . Their coarse/refined numerical error bounds are 0.00213/0.00207 and 0.00243/0.00217 bits, below the 0.00333-bit budget; the corresponding integration-rule shifts are 0.00111 and 0.00271 bits. A separate script recomputes and checks source identities, probabilities and paired loss statistics.
E.5 WHEN COPYING STARTS TO PAY
The final comparison asks when a fixed predictor begins to profit from copying an earlier continuation of the current token. The shared-base ordered-versus-shuffled experiment measures this for the transformer: shuffling preserves token frequencies but destroys the order. Informed Bayes and the frequency-only Bayesian predictor give the corresponding Bayesian prediction. Their next-token gains through sixteen tokens and at agree in size and depth ordering; the longer transformer curves show how the gain from copying grows with the number of tokens.
| Depth | Run | Next-token gain at 1024 | Cumulative gain through 1024 |
|---|---|---|---|
| 0 | 1 | ||
| 0 | 2 | ||
| 2 | 1 | ||
| 2 | 2 | ||
| 3 | 1 | ||
| 3 | 2 |
Table 14: The gain from copying increases with source depth. Loss of the shuffled-trained model minus that of the ordered-trained model, in bits; means paired standard errors across 256 sequences per depth. Positive values favor the model that can learn context–successor associations.
E.5.1 BEHAVIORAL EMERGENCE OF COPYING
The matched control isolates the context–successor associations used for copying while preserving every sequence's token counts. The tables compare both training runs on the same 256 test sources per depth. The transformer curves use 16384 sources per depth: run 1 through 1024 tokens in Figure 2(g,h), and both runs through 16 tokens in Figure 12. The Bayesian points through use the paired 256-source test set. Both training runs show the same depth ordering. At , run 1 gains 0.569 bits per prediction at and 0.880 bits at , with cumulative gains of about 417 and 704 bits; run 2 gives 0.568 and 0.883 bits per prediction and cumulative gains of about 418 and 705 bits. The control remains negative in both runs. The matched experiment therefore measures when learning transitions becomes useful, without identifying a particular internal circuit.
Matched training and evaluation. For each shared-base training sequence , the control keeps and independently permutes positions . This preserves the first token and full count vector exactly. Token frequencies estimate the realized stationary law , rather than generally the latent base ; conditional on , the shuffled training law is invariant to the order of the remaining tokens.
Each of two ordered/shuffled model pairs shares its initialization, matched batches of 64 source sequences, architecture, optimizer and learning-rate schedule. Both receive 100000 updates and 6.4 million sequences. The four-layer, width-256 models have 3454464 parameters. Indexed batch regeneration, independent replay and first-token/count preservation verify the match. The paired tables use the same 256 ordered sequences of length 1025 per condition, with and ; neither model receives these test parameters. Let be the expected loss under the true row, from (17). The difference between the shuffled-trained and the ordered-trained model, , defines the transformer gain of (7), and its sum within a sequence defines . Whole-sequence resampling retains all times and pairings. For the 16384-source evaluation, the endpoint gains at are and bits per token, with cumulative gains of and bits. The control gives bits per token. Figure 2(g,h) uses 1000 paired whole-sequence bootstrap replicates for its pointwise 95% bands.
The first tokens. Figure 12 shows how copying begins to pay. At both depths, the mean next-token gain is positive from in both training runs. Cumulative mean gains become positive within the first seven observations, and the benefit grows more quickly at .
The frequency-only Bayesian predictor. For comparison we need a Bayesian predictor that, like the shuffled-trained transformer, can use token frequencies but not token order. Draw from the training prior and let be its stationary law. The corresponding independent-token surrogate, retaining the distinguished first-token law, is
This predictor integrates the source prior and receives none of the test source's or . It learns frequencies rather than transitions and approximates the finite shuffled-training law.
- ○ - - □ - ---- Four-layer transformer ○ Informed Bayes
(a) Run 1: Next-token gain

(b) Run 2: Next-token gain

(c) Run 1: Cumulative gain

(d) Run 2: Cumulative gain

Figure 12: The early gain from copying increases with source depth. The first 16 tokens at (blue) and (orange), with training runs in separate columns. Rows show next-token and cumulative gains. Dashed curves compare the four-layer ordered- and shuffled-trained transformers on 16384 sources per depth. Open circles and squares compare informed Bayes with the frequency-only predictor on 256 sources per depth. Shading gives pointwise paired whole-sequence bootstrap intervals; bars give one standard error for Bayes. Zero marks equal loss.
| Depth | t | Informed Bayes | Transformer run 1 | Transformer run 2 |
|---|---|---|---|---|
| 0 | 16 | -0.0642 ± 0.0077 | -0.0854 ± 0.0089 | -0.0858 ± 0.0088 |
| 2 | 16 | 0.0601 ± 0.0151 | 0.0537 ± 0.0158 | 0.0599 ± 0.0150 |
| 3 | 16 | 0.0788 ± 0.0185 | 0.0839 ± 0.0190 | 0.0848 ± 0.0182 |
| 0 | 32 | -0.0311 ± 0.0045 | -0.0670 ± 0.0066 | -0.0607 ± 0.0065 |
| 2 | 32 | 0.0616 ± 0.0163 | 0.0545 ± 0.0172 | 0.0568 ± 0.0165 |
| 3 | 32 | 0.1829 ± 0.0265 | 0.1842 ± 0.0274 | 0.1813 ± 0.0269 |
Table 15: The Bayesian and transformer gains from token order. Next-token gain after 16 and 32 observations, in bits; means ± paired standard errors on the same 256 test sources per depth. Bayes is compared with its stationary-frequency predictor, and each transformer with its matched shuffled-trained model.
At every , its mean expected loss is within 0.0043 bits of either shuffled transformer across . After one token it gives a repeat of that token probability 0.06790, close to the 0.06491 of informed Bayes. The Bayesian order gain and its cumulative sum are negative throughout at and positive from at . At , the per-token gains are and bits, and the cumulative gains are and bits.
Table 15 compares the predictors on the same histories. The surrogate is specified entirely by the source prior, independently of transformer scores. Its calculation averages alphabet permutations analytically over 256 independent source banks, with 32- and 16-node exponent rules and equal weight on depths 0, ..., 8. The informed Bayesian calculation uses 16- and 32-node exponent rules on all 768 histories at each and at ; the first four tokens use deterministic rank marginalization. Shared canonical references and shared source banks are accounted for in the numerical uncertainty. All 96 per-token and cumulative coordinates through , and the three next-token coordinates at , pass the sampler, integration-order and aggregate-precision checks. The largest numerical allowance is 0.00311394 bits; each coordinate must stay below both 0.00333333 bits and one quarter of its sequence standard error.
The preliminary estimates use the first 32 test sequences per depth and the same frequency-only predictor, evaluated with one integration bank, 32 exponent nodes, and one draw at each positive depth. The depth-zero contribution and equal prior weights on are retained.
F SUMMARY OF TRANSFORMER-BAYES GAPS
Table 16 summarizes the gaps of Section 3 across models, settings and training runs; the underlying comparisons are in Appendix D.
Table 16: Gap between transformer and informed Bayes, in bits per token. “Largest gap” ranges over the displayed settings; “last gap” uses their largest . Pooled rows summarize . Two values separated by a slash are the two training runs; ranges include all listed settings and runs.
| Source | Layers | Runs | Largest gap | Last gap |
|---|---|---|---|---|
| Known encoding | 2 | 1 | 0.124 () | 0.004–0.009 () |
| Known encoding | 4 | 2 | 0.044 / 0.049 () | 0.0012–0.0056 () |
| Hidden encoding | 2 | 2 | 0.13 / 0.13 () | 0.105 / 0.096 () |
| Hidden encoding | 8 | 2 | 0.025 / 0.022 () | 0.0024 / 0.0018 () |
| Uniform base | 2 | 1 | 0.087 (, ) | 0.024–0.068 () |
| Uniform base | 4 | 2 | 0.037 / 0.041 (, ) | 0.00003–0.028 () |
| Shared base | 2 | 2 | 0.217 / 0.220 (, ) | — |
| Shared base | 8 | 2 | 0.0066 / 0.0052 () | -0.0010–0.0051 () |
| Pooled families | 2 | 2 | 0.0197 / 0.0190 () | 0.0197 / 0.0190 () |
| Pooled families | 4 | 2 | 0.0080 / 0.0067 () | 0.0052 / 0.0025 () |