WorksComputer Science
Toward a Theoretical Understanding of Transformer Attention: Bayesian Estimation and Predictive Sufficiency
Abstract
This paper develops a theoretical account of Transformer attention by organizing existing probabilistic and information-theoretic results. It identifies the assumptions under which attention computes a posterior mean and the additional conditions required for accurate next-token prediction. Posterior-mean optimality under squared-error loss does not by itself establish predictive sufficiency; even a sufficient representation requires a prediction head that uses its information correctly. An excess-log-loss decomposition makes this distinction precise by separating representation information loss from prediction-head error. The analysis clarifies the conditions required for predictive guarantees. Determining when these conditions hold in trained models, and how architectural or training choices can support them, could guide the development of AI systems that preserve and use predictive information more effectively.
Introduction
Transformer-based large language models have transformed artificial intelligence, yet their predictive success has outpaced our theoretical understanding of the representations and computations that support it. Their training algorithm is explicit: a prediction objective guides parameter updates through backpropagation and numerical optimization. Knowing this algorithm, however, does not fully explain which internal representations emerge, which regularities they capture, or how they support accurate predictions on new inputs. This paper addresses a narrower question: under what assumptions does attention compute a Bayesian posterior mean, and under what additional conditions do its outputs support accurate next-token prediction? By connecting existing probabilistic interpretations of attention with predictive sufficiency and an excess-log-loss decomposition, we distinguish the conditions governing attention’s representations from those governing the prediction head’s use of them. The analysis clarifies requirements for predictive guarantees. Identifying architectural and training choices that help satisfy these conditions would connect the theoretical analysis to practical improvements in how AI systems retain and use information for prediction.
The problem of next-token prediction
One of the fundamental tasks performed by modern large language models is predicting the next token in a sequence. Consider the incomplete sentence:
The Earth revolves around the ...
An effective language model assigns a high probability to a continuation such as “sun” and much lower probabilities to unrelated words.
This apparently simple task requires considerable contextual and conceptual information. The model must recognize grammatical structure, semantic relationships, factual associations, and dependencies among the observed words. Formally, let
denote a sequence of tokens from a vocabulary . The objective is to estimate
The general problem is therefore one of conditional prediction: given the information contained in an observed sequence, determine the probability distribution of the next symbol.
This problem predates modern artificial intelligence. It has deep connections to probability theory, statistical inference, information theory, and algorithmic information theory. Two developments are especially relevant to our investigation: Solomonoff induction and the Transformer architecture.
Solomonoff induction and universal prediction
Ray Solomonoff introduced a mathematical theory of prediction based on two ideas [13]. First, an observed sequence may be explained by different computational mechanisms. Second, simpler computational explanations should receive greater prior probability than more complicated ones. Solomonoff induction combines these ideas with Bayesian inference. It assigns weights to programs capable of generating observations and updates their relative support as additional symbols are observed. In this framework, prediction is obtained by averaging over competing generating mechanisms rather than committing prematurely to a single explanation.
Solomonoff induction provides important theoretical guarantees for computable sources of data, but its universal form is incomputable. It therefore represents a mathematical ideal rather than a directly executable prediction algorithm.
The Transformer architecture
The Transformer, introduced by Vaswani et al. in [15], takes a different approach [15]. Rather than explicitly enumerating possible generating programs, it learns numerical representations of tokens and uses attention to combine contextual information. The original architecture was designed for sequence-to-sequence tasks, particularly machine translation. Decoder-only variants subsequently became central to autoregressive language modeling. The central attention operation consists of three learned vector representations:
Query (Q)
Key (K)
Value (V)
Queries and keys determine how strongly different positions in the input sequence interact. Values contain information that is combined according to the weights assigned to source positions through these query–key comparisons. This mechanism enables a Transformer to construct representations that depend on the current context.
Research motivation
The computational formula for attention is straightforward:
Here, and store query and key vectors as rows, so the entry of is the dot product , comparing query with key . The quantity is the dimension of each query and key vector; dividing by helps keep these scores on a consistent numerical scale as changes.
Yet the mathematical simplicity of this expression contrasts with the sophisticated predictive behavior of large Transformer models. This motivates a deeper question: What theoretical principle explains why evaluating relationships between learned representations and combining their associated information is so effective for prediction?
Our investigation begins with the observation that attention resembles probabilistic hypothesis evaluation. A query specifies the information currently sought. Each key identifies a candidate contextual information source. Their compatibility score determines the relative support assigned to that source. The associated value supplies information that may be incorporated into the resulting contextual representation.
Through the lens of Bayesian statistics, this suggests interpreting attention as a form of posterior-weighted information aggregation. The main objective of this paper is to develop that interpretation mathematically.
In-context learning provides a related setting: examples or instructions change a model’s predictions without changing its pretrained parameters. Zhang et al. [16] establish connections to Bayesian model averaging and learning guarantees under specified statistical assumptions. These results support investigating Bayesian contextual computation, but do not transfer those guarantees automatically to general Transformer language models.
Research questions and scope
We address four questions.
Under what conditions can query–key compatibility be interpreted as evidence for a contextual hypothesis?
Under what conditions do attention weights correspond to Bayesian posterior probabilities over latent variables?
When can the weighted combination of value vectors be identified with a posterior expectation?
Can these operations help explain Transformer contextual prediction, representation refinement, and generalization?
The first three questions admit exact answers under suitable probabilistic assumptions. The fourth requires a broader theory of representation learning and prediction. We therefore treat it as an open research problem.
Structure of the paper
The rest of the paper is organized as follows. Sections 2–4 introduce Bayesian inference, Solomonoff induction, and Transformer attention. Section 5 distinguishes posterior support from predictive influence. Section 6 develops the direct conditional and generative latent-source models, interprets value aggregation as a conditional expectation or posterior mean, and examines estimation optimality and stability. Section 7 investigates when these representations preserve the information needed for next-token prediction, separating representation loss from prediction-head error and exploring connections to information compression and algorithmic prediction bounds. Section 8 considers the implications for Transformer contextual prediction. Section 9 presents limitations and open questions, including the gap between computational capability and learned prediction, and Section 10 concludes the paper.
Background: Bayesian inference
Hypotheses and evidence
Bayesian inference provides a mathematical framework for updating beliefs when new information becomes available. Suppose we observe the sequence
Several hypotheses might explain it. One hypothesis proposes that the numbers are consecutive positive even integers. Another proposes a more complicated mathematical rule that happens to generate the same first four values. Bayesian inference does not require choosing one explanation immediately. Instead, it assigns probabilities to the competing hypotheses and updates those probabilities as observations accumulate. Let represent a hypothesis and the observed data. Bayes’ rule states
The components have the following interpretations:
is the prior probability of the hypothesis.
is the likelihood of the observations under the hypothesis.
is the marginal probability of the observations.
is the posterior probability.
For a finite hypothesis class ,
The posterior is therefore determined jointly by prior plausibility and explanatory agreement with the observations.
Sequential Bayesian updating
Suppose observations arrive sequentially:
Write for the observations preceding position , and for the observations up to and including position . After observing , the posterior becomes
Every observation modifies the probability assigned to competing hypotheses, and the updated posterior becomes the prior for the next observation. For the complete sequence,
Using the probability chain rule,
Consequently,
s Taking logarithms yields
Equation (1) reveals that posterior inference incorporates accumulated evidence in the form of log-likelihood contributions.
Bayesian model averaging
Once posterior probabilities have been computed, prediction is obtained by averaging the conditional predictions of the hypotheses:
This operation is known as Bayesian model averaging. Each hypothesis contributes its next-token prediction, weighted by its posterior probability. The resulting prediction therefore depends both on the support for each hypothesis and on what that hypothesis predicts.
Sections 2.2–2.3 highlight two mathematical operations fundamental to Bayesian prediction:
Bayesian conditioning updates the probabilities of competing hypotheses.
Posterior-weighted aggregation combines their conditional predictions.
These operations will reappear in our probabilistic interpretation of attention.
Background: Solomonoff induction
Why prior probabilities matter
Bayesian inference requires a prior distribution over hypotheses. But how should such priors be assigned?
Solomonoff induction addresses this problem by representing explanations as computer programs and assigning greater prior weight to shorter descriptions. The underlying principle is closely related to Occam’s razor: among explanations consistent with the data, simpler explanations should generally receive greater initial preference.
Prefix Kolmogorov complexity
Prefix Kolmogorov complexity measures the length of a shortest computational description [10]. Let be a fixed universal prefix-free Turing machine, whose halting programs are self-delimiting: no valid halting program is a proper prefix of another. For a finite binary string , define
Here, means that the machine outputs exactly and halts, and is the program length in bits.
Regular strings can have short descriptions. For example, repetitions of 01 can be described by a repetition procedure and the number . Most binary strings of a given length, however, cannot be described substantially more briefly than by specifying their bits.
We also use this notion for integers and computable probability measures. The quantity is the complexity of a standard binary encoding of the integer , while is the length of a shortest self-delimiting description of a procedure computing the probability measure . Conditional complexity measures the shortest such description when is supplied as additional input. A procedure computing takes a finite string and a requested precision as inputs and returns an approximation to its probability with that precision; it need not output an entire infinite probability distribution and halt.
The prefix-free machine used here is distinct from the universal monotone machine used below to define Solomonoff’s semimeasure . We use separate symbols to distinguish the two constructions.
The universal semimeasure
Let be a fixed universal monotone Turing machine. It reads binary input in one direction and produces output without revising symbols already written. Unlike the prefix-free machine used in the previous section, it need not halt after producing the observed finite string, and its possible inputs need not form a prefix-free set.
Write to mean that the machine produces an output beginning with after reading no more than the input bits in the finite string . For a fixed observed string , define the set of minimal sufficient input prefixes by
Here, minimal means that no shorter input prefix of the same string already suffices; it does not mean shortest among all descriptions of .
For each fixed , the set is prefix-free. If one member were a proper prefix of another, the longer member would not be minimal. However, these prefixes are not necessarily self-delimiting programs in the sense of the previous section: their minimality depends on the particular observed output , rather than on a globally prefix-free domain of halting programs.
Suppose the machine is supplied with an infinite stream of independent, uniformly random input bits. The probability that this stream begins with a specified prefix is . Because is prefix-free, the corresponding input events are disjoint, so their probabilities can be added without double-counting. Solomonoff’s universal semimeasure is
Thus, is the probability that the output of begins with under fair random input. Each additional bit halves an individual prefix’s weight, implementing a preference for shorter descriptions while retaining the contributions of all minimal sufficient prefixes. Producing does not require producing any further output. After producing , the machine may halt, run indefinitely without further output, or continue producing symbols. For binary outputs this gives
The difference is the probability of input streams that produce but never produce a subsequent output bit. This possible loss of continuation mass makes a semimeasure rather than, in general, a probability measure on infinite output sequences.
Solomonoff sequential prediction
The conditional continuation weight below follows from the definition of conditional probability, applied to events about the machine’s output. We use the term “weight” to emphasize that is a semimeasure, so the weights assigned to possible next symbols may sum to less than one. Let be the event that its output begins with , and let be the event that it begins with the concatenation . Since (any output beginning with necessarily begins with ),
provided . Here, probabilities refer to independent, uniformly random input bits supplied to the machine. Thus, given an observed prefix , we define the conditional continuation weight of a finite string by
For the next binary symbol,
The missing mass corresponds to the possibility of no subsequent output.
Solomonoff induction combines the simplicity-weighted construction with Bayesian conditioning. As additional symbols are observed, conditioning changes the relative support assigned to compatible computational explanations. Prediction aggregates their contributions rather than committing to one explanation.
The universal semimeasure is incomputable, a limitation closely related to the undecidability of the halting problem. Computing requires summing the weights of all minimal input prefixes that cause a universal monotone Turing machine to produce an output beginning with . Although simulation can reveal contributions as they occur, no general algorithm can determine whether every remaining computation will eventually produce such an output or continue indefinitely without doing so. Hence, all that we can do is to approximate from below by progressively discovering contributions, obtaining increasingly accurate lower bounds. Thus, is lower semicomputable, but not computable. Still, has strong theoretical prediction properties. In particular, for any computable probability measure , there is a constant , independent of , such that
This property is called universal dominance. It says that, for every computable probability measure , the universal semimeasure assigns each finite string at least a fixed positive fraction of its probability under . Its predictive significance can be expressed through bounds on cumulative excess log loss. This is how.
Logarithmic loss measures the error of a probabilistic prediction. After observing an outcome, this loss is the negative logarithm of the probability assigned to that outcome; assigning a smaller probability incurs a larger loss. Define the cumulative excess log loss over observations by
Here, is the random symbol at position , and is the preceding random sequence. Lowercase denotes a particular observed value of . In language modeling, these symbols correspond to tokens from the model’s vocabulary. We use the convention for the empty string . The quantity compares the cumulative log loss of the semimeasure-based predictor with that of a predictor that already knows the true generating distribution . At step , subtracting the true predictor’s loss from Solomonoff’s loss gives
Summing these differences over the observations gives . Since a sum of logarithms is the logarithm of a product,
The probability chain rule gives . For , the definition of its conditional continuation weights gives:
Therefore,
The same true-to-predicted log-ratio comparison will reappear in our probabilistic interpretation of attention.
From universal dominance to a cumulative excess-loss bound. Universal dominance gives a bound for every finite sequence of positive probability under . Applying to Equation (2) reverses the inequality:
Subtracting the true predictor’s sequence loss, , from both sides and using the definition of gives
Because this holds for every sequence of positive probability under , it also holds after averaging over sequences generated by :
Since this upper bound is independent of , the expected excess log loss per symbol tends to zero as the number of observations grows:
This result says that as more observations arrive, Solomonoff’s predictor incurs, on average, less additional log loss per symbol compared with a predictor that knows the true generating process. This does not mean that every next symbol becomes predictable with certainty: the generating process may remain random. The result concerns the accuracy of the predicted probabilities, rather than whether a representation preserves all information needed for prediction.
Convergence to the true predictive probabilities. Solomonoff’s predictor has a strong theoretical property: for a computable data-generating probability measure, its next-symbol predictions converge to the true conditional probabilities with probability one. This result concerns learning the probabilities of outcomes, not predicting every outcome with certainty [8]. It applies to the ideal, incomputable predictor and does not automatically extend to Transformers or other computable predictors.
Relevance to Transformer prediction. Solomonoff induction and Transformer language modeling share an objective:
However, their computational methods differ fundamentally. Solomonoff induction averages over possible generating programs. A Transformer learns a finite family of vector transformations and combines contextual representations. There is no general mathematical equivalence between the two systems. Nevertheless, Solomonoff induction provides a useful conceptual starting point: prediction can be understood as combining explanations according to evidence. The remainder of the paper investigates under what assumptions Transformer attention can implement a tractable form of this general principle.
Background: The Transformer architecture
Token embeddings
A Transformer language model receives a sequence of tokens
Each token is mapped to a learned embedding in a -dimensional space. Let the embedding of token be denoted by
Positional information is also incorporated. In an additive positional-embedding formulation, the position is represented by a vector
which is computed using a fixed encoding. The initial input representation is then
Here, identifies the token’s position, is its token embedding, and represents its position. The superscript labels the initial representation, before any Transformer layers have processed it. More generally, denotes the representation at position after Transformer layers.
Query, Key, and Value
For each token representation , the attention mechanism constructs three vectors through learned linear projections: the query , the key , and the value :
The projection matrices , , and are learned during training. The input representation has dimension , whereas the queries and keys have dimension , and the values have dimension :
Using a column-vector convention, we have
The subscript stands for key. Queries and keys must have matching dimensions so that their dot product is defined; values need not have the same dimension. When , these query and key projections perform dimensionality reduction: they learn to combine the input components into fewer output components. For a sequence of length , computing all query–key dot products costs on the order of , rather than for full-dimensional queries and keys. The score matrix still has entries in full attention, so this reduction does not remove the quadratic dependence on sequence length. The sequence length is bounded by the Transformer’s context-window capacity.
In multi-head attention, and describe the query/key and value dimensions, respectively, within each head. A common choice with heads is . For example, the 175-billion-parameter GPT-3 model [1] has an embedding dimension of and attention heads per layer, giving : each head uses 128-dimensional query, key, and value vectors. Splitting a fixed total dimension among several heads allows different learned projections without multiplying the main attention computation by the number of heads, compared with a single full-dimensional head. With this choice, the total projection parameter count and the computation required for score calculation and value aggregation are approximately the same as for a single full-dimensional head.
The vectors , , and serve distinct computational roles. For a query position and an accessible source position , the query represents the information sought at position . The key is compared with to determine the source’s attention weight relative to other accessible sources. The value supplies the information combined according to that weight. The query and source positions may coincide; that is, a token can attend to its own position.
Query–Key compatibility
For query position and candidate source position , the compatibility score is
The dot product adds together products of query and key components:
As the vectors get longer, these sums tend to fluctuate more widely. Assuming that the query and key components are standardized (having mean zero and variance one) and are mutually independent, the dot product has variance , so its standard deviation is . Dividing by gives the scaled score a variance of one, keeping scores on a roughly consistent scale across different vector dimensions.
The resulting scores are passed through softmax:
where is the set of positions accessible to the query at position ; that is, the positions that token is allowed to attend to. In causal self-attention, includes all earlier positions and position itself:
Later positions are excluded, preventing the model from using future tokens when predicting the next token. The softmax outputs are called attention weights. They are nonnegative and sum to one over the accessible source positions:
Value aggregation
For each query position , attention produces an output vector by taking a weighted average of the value vectors at accessible source positions:
Here, supplies the information associated with source position . The attention weight determines how much that source contributes for query position . By contrast, is the attention output vector, obtained by combining the value vectors according to those weights. Thus, the attention weights specify the contributions, while the attention output contains the aggregated information. In matrix notation,
The -th row of is . Each row of , , and contains the corresponding query, key, or value vector, respectively, and softmax is applied separately to each row of the score matrix. The additive mask specifies which source positions are allowed for each query.
A causal mask implements causal self-attention by setting
Adding zero leaves an allowed score unchanged. Adding to a future-position score makes its softmax weight zero. Consequently, whenever , and Equation (4) reproduces the restricted sum in Equation (3).
Multi-head attention
Let contain the token representations as rows. Each of attention heads uses its own learned projections:
The transposes reconcile this row representation with the column-vector convention in § 4.2. Each head applies the attention operation and mask defined above:
The outputs are concatenated and projected back to the model dimension:
Each head returns one -dimensional output per token:
Concatenation places the heads’ outputs side by side for each token, preserving the number of rows:
The learned output projection has dimensions
Therefore,
Multiplication by mixes the heads’ contributions and returns each token’s representation to dimension .
Multiple attention heads provide different learned projections through which the model can detect and combine contextual regularities. This resembles the use of multiple filters in a Convolutional Neural Network, although attention weights adapt to the current input, whereas a standard convolution filter applies fixed learned coefficients within a prescribed neighborhood.
Transformer layers
A Transformer layer combines attention with a feed-forward neural network, commonly called a multilayer perceptron (MLP), together with residual connections and layer normalization. Attention combines information across token positions, while the MLP transforms each token’s components independently. Residual connections add learned updates to existing representations, and normalization helps stabilize their numerical scale during training.
Stacking layers allows later queries, keys, and values to be computed from representations already transformed by earlier layers. Our probabilistic model concerns source weighting and value aggregation within attention; it does not model the complete Transformer layer or its training dynamics.
Posterior Support and Predictive Relevance
We begin by comparing Bayesian model averaging with attention. Bayesian model averaging takes the form:
Now consider attention:
Both expressions combine candidate contributions using normalized weights. The resemblance suggests the following correspondence:
| Bayesian inference | Transformer attention |
| Candidate hypothesis | Candidate contextual information source |
| Observed evidence | Observed query at position |
| Posterior weight | Attention weight |
| Conditional contribution | Value vector |
| Posterior averaging | Weighted value aggregation |
Table 1.
This structural resemblance does not automatically make attention weights Bayesian posterior probabilities. Sequential Bayesian inference accumulates evidence about hypotheses, whereas attention computes query–key scores from contextual representations. Section 6 specifies conditions under which these scores yield posterior source probabilities. Before developing those models, we distinguish support for a hypothesis from its influence on prediction.
We note that posterior support and predictive influence answer different questions. Posterior support asks how strongly the observed evidence favors a hypothesis. Predictive influence asks how changing its weight changes the predicted continuation. A highly plausible hypothesis need not strongly affect the next-token distribution if competing hypotheses make similar predictions.
To make this precise, let denote the observed context and suppose are exhaustive alternatives with . Bayesian model averaging gives
Holding the conditional predictions fixed, a change therefore changes the predicted probability by
Thus, sensitivity to the posterior weight depends on the difference between the hypotheses’ conditional predictions. For example, if and the two likelihoods are 0.70 and 0.69, the mixture assigns it probability . The strong support for has little effect relative to a different allocation of weights because the conditional predictions are so similar.
When the conditional predictions differ substantially, however, a relatively unlikely hypothesis can preserve a distinctive predictive possibility. Keep , but suppose that a particular next token has conditional probabilities
The predictive mixture assigns that token probability
This shows that although is relatively unlikely, it supplies the entire 4% probability assigned to . Retaining only would rule out this token. However, because a conditional probability cannot exceed one, its contribution is bounded by its posterior weight:
Thus, a small posterior weight can therefore preserve a distinctive predictive possibility without making it highly probable. This illustrates the value of averaging over explanations rather than retaining only the most plausible one, a principle also central to Solomonoff induction.
The corresponding distinction in attention. Attention separates scalar source weights from the information associated with those sources:
A weight determines how much source contributes, while its value vector determines what it contributes. Holding the values and other weights fixed, shifting an amount of weight from source 2 to source 1 changes the output by
If , this redistribution changes the source weights but leaves the output unchanged. Even when the attention output changes, the final prediction need not change if the subsequent prediction function is insensitive to that change. Thus, a large attention weight alone does not establish a large influence on next-token prediction. Predictive influence depends on the values, the allocation of weights among sources, and the downstream computations. Interpreting these weights as posterior support additionally requires the probabilistic assumptions introduced in the following sections.
This motivates examining attention’s weighted value aggregation and whether the resulting representation preserves everything needed for next-token prediction, as required by predictive sufficiency, a concept discussed in § 7.
Probabilistic Models of Transformer Attention
This section develops two models of a categorical latent source , which identifies a candidate contextual information source. The direct conditional model defines its probabilities using attention weights, . Under the payload and conditioning assumptions in § 6.3, value aggregation is a conditional expectation. No model of how the query was generated is required.
The generative model instead specifies source priors and query likelihoods, then derives posterior source probabilities through Bayes’ rule. Under the stated Gaussian and prior assumptions, these probabilities equal the attention weights, and value aggregation becomes a Bayesian posterior mean. The distinction is between specifying source probabilities directly and deriving them from a probabilistic model of the evidence.
The direct interpretation has precedents in latent-alignment and latent-connectivity work [5, 12]; the Gaussian construction follows Gabbur et al.’s framework, including their norm-dependent prior [7]. We develop the direct model first, followed by the generative model, then examine estimation optimality, predictive limitations, and stability. These interpretations describe what attention can compute under explicit assumptions.
Latent variables and contextual relationships
A latent variable is an unobserved variable introduced into a model to represent underlying states, sources, or relationships inferred from observed data. A categorical latent variable takes one of a specified set of labels. For example, consider the following sentence:
The scientist placed the sample in the refrigerator because it needed cooling.
The pronoun “it” most plausibly refers to the sample, although the refrigerator is another possible interpretation. The intended referent is not explicitly annotated. We can introduce
and ask for , the posterior probability of each candidate referent. This illustrates a latent contextual relationship.
A latent source and its conditional probabilities in Transformer attention
For a query at position , let be the finite, nonempty set of accessible contextual source positions. Introduce a categorical latent variable
The event identifies position as the information source in the latent-variable model. Each possible source therefore defines a candidate hypothesis:
A conditional categorical model. For finite query–key scores , let
This is a direct probabilistic interpretation of the attention weights. These probabilities are nonnegative and sum to one over accessible sources. Here, the query and keys are conditioning inputs: we specify the categorical distribution of for those inputs without modeling their probability of occurrence.
Value aggregation as a conditional expectation
At the first Transformer layer, let
This vector represents a learned projection of the information available at position . It is computed before the first layer’s attention aggregation. In that limited computational sense, it is information available prior to contextual integration by the current attention head.
We view the value vector as a candidate information payload: it contains the numerical information available from source position , while the attention weight determines how strongly that vector contributes to the attention output for query position :
Here, “candidate” indicates that the source is one of the accessible positions that can contribute, and “payload” refers to its value vector. In deeper layers,
so the value can already contain information integrated from earlier context.
Fixed values and a random payload. For a particular attention computation, the value vectors have already been computed by the Transformer, so we treat them as given, fixed information payloads in our latent-variable model. They are fixed for this computation, but can change across input contexts or during training as the learned value-projection matrix and the representations it acts on change.
Define the random payload by
Although the possible value vectors are fixed, is random because the source index is uncertain in the model. Once the source is known, however, the payload is fully determined: it equals . Thus the payload is random before the source is known, but deterministic conditional on the source and the given value vectors. The attention operation itself need not make a random selection. Transformer attention does not sample a source; it directly computes the weighted average of the value vectors
More general source-associated payloads. The payload , which is fully determined once the source is known, is sufficient for the direct interpretation. More generally, uncertainty about the payload may remain even after the source is known. Let be a random payload satisfying
The value vector represents the source-specific mean, rather than an outcome the source always supplies. Here, there are two levels of uncertainty: which source supplies the information, and what payload that source supplies. The overall mean is obtained by averaging the source-specific means using the source probabilities. This is the law of total expectation, developed explicitly below.
This generalization requires neither payloads fully determined by the source nor Gaussian payload distributions. The Gaussian payload model in § 6.7 is one way to ensure that each source’s conditional expected payload equals its value vector .
Computing the conditional expectation. For the direct conditional model, assume that additionally conditioning on the given values does not change the specified source probabilities. The law of total expectation gives
Specifically, we assume
By the direct specification in § 6.2,
By the conditional-mean assumption above,
Therefore,
The right-hand side is exactly the Transformer attention output. In plain terms, we average within each source through its conditional mean and then average across sources using their probabilities. Hence,
The source-determined payload as a special case. For , which is random but fully determined once the source and value vectors are given, the same argument gives
Source priors, query evidence, and Bayes’ rule
We now introduce the generative interpretation. Unlike direct conditional specification, it assigns likelihoods to possible query observations under each source hypothesis and derives the source probabilities using Bayes’ rule. These additional assumptions justify the weights as Bayesian posteriors.
Before conditioning on the query, assign each source a prior probability conditional on the candidate keys :
The prior satisfies
A simple initial choice is a uniform prior:
Other choices can encode source preferences or depend on the keys.
For the observed query , specify a conditional density
Evaluated at that query, it gives the likelihood of each source hypothesis. We use lowercase for densities of continuous query distributions and uppercase for probabilities of categorical source events. Bayes’ rule gives
The posterior assigns probabilities to the candidate source hypotheses after accounting for the query evidence. We next establish when this posterior equals the attention weights specified in § 6.2.
Bayes’ rule expressed through softmax. For positive source priors and query likelihoods, define . Rewriting Equation (6) yields
Thus, softmax gives Bayesian posterior source probabilities when each score equals the log prior plus the log query likelihood, possibly with an added constant shared by all candidate sources. This rewriting of Equation (6) specifies what attention scores must represent for their softmax weights to equal the posterior probabilities under the stated model. § 6.5–§ 6.6 supply a specific construction: Gaussian query likelihoods and an appropriate source prior make the log prior plus log likelihood equal the scaled query–key dot product, up to a source-independent constant.
A Gaussian generative model and its likelihood
Consider query and key vectors belonging to . Conditional on the latent source variable , suppose the query is generated by
The key vector therefore acts as the mean of the query distribution under hypothesis . The covariance is isotropic, , with the same variance parameter for every candidate source. The conditional density is
Consequently, a source whose key is closer to the observed query in Euclidean distance (a smaller ) assigns that query a higher likelihood. Combining this likelihood with the source’s prior probability, using Bayes’ rule, gives
If the priors are equal, the likelihood alone determines the ranking: the closest key receives the highest posterior probability. If the priors differ, a more distant source can receive the higher posterior probability.
For example, suppose the query likelihoods under two sources are 0.4 and 0.2. Source 1 assigns the observed query twice the likelihood density assigned by source 2. With equal priors, their posterior probabilities are
Source 1 receives greater posterior support. But if the prior probabilities are 0.1 and 0.9, the prior-weighted likelihoods become
After normalization, the posterior probabilities are approximately
Source 2 now receives greater posterior support despite its lower query likelihood.
This distinction matters for our derivation: Gaussian proximity determines likelihood, while Transformer attention corresponds to the posterior only after the source prior has also been accounted for. The following expansion makes this connection explicit.
Taking logarithms in Equation (8) gives
To make the connection to the query–key dot product explicit, expand the squared distance:
Substituting into Equation (9) gives
where is independent of the source . For a fixed query, the term involving is also independent of . Combining these terms into , we obtain
The term depends on the query , but does not depend on the candidate source . It therefore contributes the same multiplicative factor to every source’s likelihood. The likelihood is
Computing the normalized posterior, using Bayes’ rule, gives
The common factor cancels out, and since the denominator is independent of , we can write:
where is the reciprocal of the remaining normalization denominator. It is constant across candidate sources , though it depends on the given query. We can now state
That is, only source-dependent terms influence their relative posterior probabilities. Equation (10) shows that the Gaussian log likelihood depends on both the query–key dot product and a key-norm penalty. If all candidate keys have equal norms, the penalty is constant across sources, so minimizing Euclidean distance is equivalent to maximizing the dot product. With unequal key norms, proximity and dot-product rankings need not agree.
Write each prior as . Applying this identity in both the numerator and denominator of Equation (11), and cancelling the common factor , expresses the posterior as a softmax with scores
The posterior therefore becomes
This is a general Bayesian form of attention under the Gaussian model. Equation (13) contains three source-dependent contributions: query–key compatibility, a key-norm penalty from the Gaussian likelihood, and the log prior. For uniform priors and unequal key norms, the penalty remains, so the posterior generally differs from ordinary dot-product attention. The following subsection shows how equal key norms with uniform priors, or a norm-dependent prior for unequal key norms, recover standard scaled dot-product attention.
Recovering standard scaled dot-product attention
We first consider a simple special case. Assume that the prior probabilities are uniform, all candidate keys have equal Euclidean norm, and the variance parameter satisfies
Because the priors are uniform, is constant across . Because the key norms are equal, the term is also constant across . And since both terms disappear under softmax normalization, Equation (14) therefore reduces to
But the right-hand side is precisely the standard attention weight .
An exact correspondence can also be constructed without equal key norms. For any finite, nonempty accessible source set and finite key vectors, choose the conditional source prior
This is a valid prior over accessible sources conditional on the keys: it is positive, sums to one, and does not depend on the observed query. Let
Substituting the logarithm of into Equation (13) gives
The key-norm terms cancel, and the remaining term is constant across candidate sources. Therefore,
With Equation (15), this is again exactly Equation (16), now for arbitrary key norms. When the keys have equal norms, the constructed prior becomes uniform, , recovering the earlier special case.
We can now state the correspondence for arbitrary key norms, with the uniform-prior, equal-norm construction included as a special case.
Proposition 1. Bayesian interpretation of scaled dot-product attention Consider the Gaussian latent-source model of Equation (7) on a finite, nonempty accessible source set , with finite key vectors and . Suppose the source prior satisfies
where is independent of . Equivalently, choose
Then the standard scaled dot-product attention weights are exactly the posterior probabilities of the latent source variable:
Value aggregation as a Bayesian posterior mean
We now combine Proposition 1 with the conditional-mean assumptions of Section 6.3 to interpret value aggregation as a Bayesian posterior mean.
What is being averaged. Each value vector represents a conditional payload mean:
The information supplied by source need not always equal ; the payload may vary while retaining that average. Under Proposition 1 and the conditioning assumption in Equation (5), . The law of total expectation first averages conditional payload means over the possible sources:
Hence
Attention therefore combines the source-specific means according to how probable each source is after observing the query.
Posterior mean, MAP estimation, and EM. Our analysis emphasizes posterior-mean estimation, complementing Gabbur et al.’s treatment of Maximum A Posteriori (MAP) inference and Expectation Maximization (EM) based adaptation [7]. A posterior mean averages possible payloads, whereas MAP identifies a most probable value; EM is an estimation algorithm rather than an alternative posterior summary. Our focus is on when the resulting mean preserves information needed for prediction. The conditional-mean assumption is sufficient for this interpretation; the Gaussian payload model below provides one concrete realization.
A Gaussian realization. Here we specify a concrete Gaussian payload model for our latent-source analysis, drawing on the probabilistic-attention perspective of Gabbur et al. [7]. This serves two purposes. First, it provides a model with the conditional payload means required for posterior-mean aggregation. Second, it ensures the finite conditional second moment needed for the squared-error optimality argument in the subsequent section.
The Gaussian query distribution in Equation (7), centered at , supplies the likelihood used to infer the source. A second Gaussian distribution, centered at , models the payload associated with that source:
Here . This distribution gives , but observing the query could change that mean. For example, a source may have mean payload 5, while the query reveals whether the current payload is above or below 5. To rule out such additional information in this realization, assume conditional independence:
Together, these assumptions give
The query can therefore change our probabilities over sources without changing the payload distribution once the source, keys, and values are known. This conditional independence is sufficient but stronger than necessary: the posterior-mean identity requires only that the conditional mean remain , as in Equation (19). Other aspects of the payload distribution could depend on the query without invalidating that identity. Thus, the query likelihood supports source inference, while the payload distribution specifies the information to be estimated.
This Gaussian realization also ensures the finite conditional second moment needed for the squared-error optimality argument in § 6.8. Here, is the expected squared magnitude of the payload given the query, keys, and values.
More generally, a Gaussian distribution for the payload is sufficient but not necessary; the posterior-mean identity requires only the conditional-mean and conditioning assumptions established in § 6.3.
Corollary 1. Attention as a Bayesian posterior mean
Consider the Gaussian latent-source model defined by Equations (7), (17), and (18), on a finite, nonempty accessible source set, with finite keys and values. Suppose and the source prior is the norm-dependent prior specified in Proposition 1. Treat the values as fixed conditional payload parameters, so that the source posterior is unchanged by additionally conditioning on , as in Equation (5). No equal-key-norm assumption is required; uniform priors with equal key norms are a special case.
Then scaled dot-product attention computes the posterior conditional expectation of the target contextual information vector:
This follows directly from Proposition 1 and the conditional-expectation calculation in § 6.3, under the payload and conditioning assumptions stated above.
Mean-estimation optimality and limits for prediction
Let be any estimator of based on the available evidence. Define the conditional risk; that is, the expected squared estimation error given the query, keys, and values, by
Given this query, these keys, and these values, how much squared error should we expect if we estimate the payload by ?
Let
Using
and expanding, we obtain
Because
We have
The risk is minimized when
§ 6.3 establishes that the attention output equals the conditional mean; Corollary 1 gives its posterior-mean interpretation in the generative case. Therefore, the optimal squared-error estimate is
Thus, under our probabilistic model, the attention output is not merely a weighted vector average. It is the optimal conditional-mean estimator of the modeled payload under squared-error loss; under the generative assumptions, it is the corresponding Bayes-optimal estimator.
From payload estimation to next-token prediction. This optimality concerns estimation of the modeled payload, not automatically prediction of the next token. If is a contextual information vector, the result establishes the best squared-error estimate of that vector given the query, keys, and values. It does not establish that its mean preserves all information needed for next-token prediction. Its predictive relevance therefore depends on what the payload represents, what predictive distinctions its mean preserves, and how subsequent computations use that mean. A posterior mean can nevertheless preserve a complete predictive distribution when the payload and source probabilities have the appropriate interpretation. § 7.3 gives an illustrative construction using source-conditional next-token distributions.
Predicting from an average is not the same as averaging predictions. A further distinction, emphasized by Deng et al. [5], concerns the computation after attention. Let be a downstream prediction function, let denote the conditioning context, and let follow the conditional source probabilities. In general,
The left-hand side applies the prediction function to the mean representation. This is the order used by ordinary Transformer attention: first average value vectors, then process the aggregated representations through subsequent computations to obtain outcome probabilities. Thus denotes a prediction from an average representation, not an average of source-specific outcome probabilities.
Bayesian predictive averaging instead combines conditional outcome distributions using posterior hypothesis probabilities. For a categorical source ,
This can be described as “apply first, then average,” provided gives the source-conditional outcome distribution:
Under this assumption, and with the corresponding posterior source weights from the same model, the predictive distribution is
Each source is first assigned a predictive distribution, and these distributions are then averaged using posterior weights. The quantities being averaged are probabilities of the same outcomes under different source hypotheses. This distinguishes the operation from the Transformer order of averaging value vectors before applying the downstream prediction function.
The computations coincide in the special construction where each value vector already encodes the conditional next-token distribution and the attention weights are its source posterior probabilities. Then itself is the full predictive distribution and can be the identity.
For a simple numerical example, take two equally probable scalar values,
and the nonlinear transformation . Averaging first gives
Applying the transformation first instead gives
Second-moment information matters here specifically because : averaging the transformed values gives , the conditional second raw moment, whereas transforming the mean gives . Their difference is the conditional variance:
In this example the mean is 0, the second moment is 1, and the variance is 1. The mean alone does not determine the second moment needed to reproduce the average of squared values. For other nonlinear functions, the average prediction may depend on other features of the distribution beyond its mean.
Why concatenating heads does not automatically resolve the distinction. Each attention head computes an output for every query position. At a fixed position , the outputs of the different heads are concatenated. Writing each head output as a column vector, the combined representation before output projection is
with projected output under the matrix convention of § 4.5. The full Transformer subsequently applies further computations, including nonlinear transformations.
The probabilistic result for each head is conditional: . To interpret all concatenated outputs as one joint posterior mean, a compatible joint model and common conditioning information are needed. If such a model satisfies for every head, then stacking the payloads into gives by linearity.
Even under this common-conditioning assumption, a nonlinear downstream prediction function , including the output projection and subsequent computations as appropriate, need not satisfy
The first equality follows from the mean representation; the second is not guaranteed. Concatenation preserves the individual head outputs, and the output projection is linear, but neither operation makes later nonlinear prediction make predicting from the averaged representations equivalent to averaging predictions from the individual representations. Additional heads can retain complementary information, yet no architectural guarantee ensures that their means preserve every distinction needed to reproduce a predictive mixture.
This is not to say that a Transformer should perform source-specific predictive averaging, or that its actual predictions are incorrect. This observation establishes a limit on the conclusion drawn from the posterior-mean identity: correct mean estimation alone does not prove Bayesian predictive marginalization or next-token optimality. Whether the combined representation contains the information needed for the prediction task is the predictive-sufficiency question developed in § 7.
Stability under approximate source weighting
We now quantify how errors in source probabilities affect the conditional or posterior mean, with the value vectors held fixed. Fix the query, keys, and value vectors in the generative latent-source model of Sections 6.4–6.7. Let be the true posterior distribution over accessible sources and an approximation to it. We examine how replacing by , while keeping the value vectors unchanged, affects the aggregated output.
Let the true posterior source probabilities be
and let their attention-based approximations be
Suppose the value vectors satisfy
The true posterior mean is
The approximate attention output is
We can bound the resulting approximation error as follows.
Proposition 2. Stability of attention-based posterior expectations
Under Equation (20),
Here, total variation distance measures the largest absolute difference between the probabilities that the two distributions assign to the same event. The proof first bounds the representation error using total variation; Pinsker’s inequality then converts this into a bound using KL divergence.
Proof
Subtract the two representations:
Apply the triangle inequality:
Using ,
Using the standard identity for total variation distance [9],
we obtain
This proves the proposition. □
Using natural logarithms, Kullback–Leibler divergence is defined by
It computes the expected additional log loss from using the approximate source probabilities when the true source probabilities are . The divergence is zero when the distributions agree and positive otherwise. If for a source with , the divergence is infinite.
Pinsker’s inequality [4], expressed using natural logarithms, gives
Combining this with Proposition 2 yields
This establishes a direct connection between the quality of posterior source approximation and the accuracy of the resulting attention representation. It connects errors in source inference to errors in the attention output. In plain terms, a small KL divergence between the true and approximate source posteriors guarantees a small error in their weighted value means, provided the same value vectors are used and their norms are bounded by . This is an upper bound, not an exact error estimate.
During pretraining, gradient-based optimization changes the projection matrices and other parameters to reduce next-token loss. During ordinary inference, these parameters remain fixed, while contextual representations and attention weights vary with the input. This input dependence permits different source contributions across contexts, but does not by itself establish that the weights accurately represent posterior probabilities over contextual sources or that the aggregated values preserve all predictive information.
Predictive Sufficiency and Information Compression
Section 6 establishes conditions under which attention computes a posterior mean of a contextual payload. This answers an estimation question: what vector should represent the uncertain information supplied by the candidate sources? It does not yet answer the prediction question: does that vector contain everything needed to predict the next token?
The distinction matters because averaging combines several possibilities into one vector. That vector can be exactly the right estimate of the modeled payload while omitting distinctions relevant to another task. Conversely, an average can retain an entire predictive distribution when its components encode the appropriate probabilities. The issue is therefore not whether averaging is inherently adequate or inadequate, but what is averaged and what must subsequently be predicted.
This section develops that distinction in three steps. First, we introduce predictive sufficiency and illustrate how a short summary can preserve all information needed for prediction. Second, we examine when attention produces such a summary and separate representation information loss from prediction-head error. Third, we connect this analysis to information compression and algorithmic prediction bounds, identifying the additional approximation assumption needed for the latter to bound representation loss.
Preserving information needed for prediction is an established concern in the information bottleneck literature [14] and the information-sufficiency framework of Silva et al. [11]. Related work examines attention identifiability [2] and the distinction between representation averaging and predictive marginalization [5]. Our contribution is to apply these perspectives to the posterior-mean interpretation of attention: when does an attention-weighted mean preserve the information needed for next-token prediction, and when can averaging discard relevant distinctions?
Sufficient statistics
In statistics, a statistic is a function of the observed data:
The classical concept of statistical sufficiency, associated with R. A. Fisher [6], concerns retaining the information in observations relevant to an unknown parameter. Under a specified statistical model, is sufficient for a parameter if the conditional distribution of given does not depend on . Once the statistic is known, the remaining details of the observations provide no additional information about that parameter.
A statistic can therefore be viewed as a summary of the observations. Classical sufficiency asks whether this summary preserves everything relevant to inference about a parameter. Predictive sufficiency asks a related but different question: does the summary retain everything needed to predict a specified target? Here, we apply it to attention-based representations for next-token prediction.
A representation
is predictively sufficient when
The equality holds for every vocabulary token in every context that has positive probability under the data-generating distribution. Once the representation is known, access to the full context provides no further predictive information. The summary need not reconstruct the original input sequence or retain every fact in it; it must retain the distinctions that affect the next-token distribution. Thus, the distinction is the purpose of the summary. Our contribution is to apply predictive sufficiency to attention-based representations and ask whether posterior-mean aggregation preserves the distinctions needed for next-token prediction.
A useful way to recognize failure is to consider two different input sequences mapped to the same representation. Any prediction head using only that representation must give them the same prediction. If their true next-token distributions differ, the representation cannot be sufficient for both. In probabilistic terms, predictive sufficiency says that the next token and full context are conditionally independent given the summary.
An example: Bayesian inference without storing the entire sequence
Consider a sequence over the alphabet . One of two hypotheses generates the entire sequence, but we do not know which one was chosen. Before observing any symbols, the hypotheses have equal prior probabilities:
Suppose that their conditional symbol probabilities are
An intuitive analogy is to choose one of two biased coins at random and repeatedly toss that same coin. The first favors , while the second favors .
The observations are independent conditional on the chosen hypothesis: if we knew the generating rule, earlier outcomes would not change the probability of the next symbol. Thus,
The observed sequence is four times as likely under . Bayes’ rule, with equal priors, gives
The next-symbol prediction averages the two rules using these posterior probabilities:
Although observations are independent when the hypothesis is known, they are not independent when it is unknown. For example, before observing any symbols, our predictive probability of , averaged over the two equally likely hypotheses, is , but observing one raises the posterior probability of to and the probability of another to . Neither generating rule assigns probability : one assigns , the other . The value expresses our uncertainty about which rule was selected. The observation changes our knowledge of the fixed generating rule, rather than changing that rule.
We now show why the complete history is unnecessary for these calculations. Let
With equal hypothesis priors, the posterior odds are
Taking logarithms gives
Thus, the complete posterior can be recovered from the single number
Writing , the posterior probability of is . Consequently,
For the sequence , , recovering the next-symbol probability 0.68 calculated above. Every history with that same count difference gives the same prediction in this model, regardless of its order. The complete sequence and the series of earlier posteriors are unnecessary for this prediction. Thus, is a predictively sufficient summary for the next symbol under this model: it needs not preserve the whole context, only what affects the predictive distribution.
From attention to predictive summaries
With learned parameters fixed, write the Transformer’s representation and predictor as
where includes attention layers and outputs a vocabulary distribution. Predictive sufficiency concerns what the representation preserves; prediction accuracy also depends on how the trained head uses it. For the combined representation and head, an accuracy requirement is
where is the true next-token distribution and a specified tolerance. Equation (21) controls both components; the next subsection separates excess log loss into contributions from information lost by the representation and error introduced by the prediction head.
Example: When the posterior mean gives the full next-token distribution. Corollary 1 identifies attention as the posterior mean of a general contextual payload, without establishing predictive sufficiency. Here we add a specific assumption: values encode source-conditional next-token distributions in a correctly specified model.
Let be the context, a categorical latent source with finite source set , and the finite vocabulary. Suppose
The component corresponds to token ; the full vector has nonnegative components summing to one. The law of total probability gives
Under these additional assumptions, the posterior-weighted mean contains the full next-token distribution and is predictively sufficient; an identity prediction head suffices.
For example, two sources with values
and posterior weights 0.75 and 0.25 produce
All three token probabilities are retained.
To connect this construction to conditional-mean estimation, let be the random one-hot indicator of the next token: if token occurs and 0 otherwise. Unlike , is the collection of value vectors, given for a fixed context and fixed parameters. A realization of identifies one outcome; each value vector describes probabilities over outcomes under a source hypothesis. Consequently,
Each component’s mean equals its token’s probability because its indicator is 1 exactly when that token occurs. Thus the example specializes the earlier general payload to a prediction-specific payload .
The example also replaces conditioning on , , with conditioning on the full context . Applying it to ordinary attention would require the contextual token representations to retain enough information, and the learned projections producing , , and to use that information correctly, so that the attention weights and value vectors encode the source probabilities and conditional next-token distributions assumed in the example.
A decomposition of excess predictive log loss
Fix a data-generating distribution and a deterministic representation , with learned parameters held fixed. Define
These are, respectively, the ideal full-context predictor, the ideal representation-based predictor, and the trained head’s prediction. The first two minimize expected log loss given their available information. The head receives only .
Using a predictive distribution incurs log loss when token occurs. If the true conditional distribution is , the expected additional log loss from using rather than is . Throughout this subsection, we use natural logarithms.
Two levels of averaging. For a fixed context , let and be its true and predicted next-token distributions. KL divergence averages over next tokens; the outer expectation then averages over contexts:
The following decomposition, presented by Silva et al. [11], separates the two sources of excess loss:
Here, we apply it with the full context as input, the next token as target, and the attention-based representation as summary.
Conditional mutual information measures how much the full context still helps predict the next token once the summary is known. In this setting,
It is the expected additional log loss from using the ideal summary-based predictor instead of the ideal full-context predictor, averaged over contexts.
The first term in Equation (22) is representation information loss: the uncertainty that access to the full context would remove after the summary is known. It vanishes exactly when the summary is predictively sufficient. The second is prediction-head error: the head’s discrepancy from the best predictor available from that summary. A sufficient representation can still have a poor head, while a perfect head cannot recover information absent from its input.
Example: separating the two costs. Suppose two equally likely contexts have next-token distributions and , but map to the same summary. Its ideal predictor must average the two distributions:
Representation loss averages the divergence from each full-context distribution to this summary-based predictor:
For the first context,
For the second context, the two contributions appear in the opposite order:
The divergences are equal because the contexts exchange the token probabilities while the summary-based predictor assigns both tokens the same probability. Their equally weighted average is therefore also approximately 0.368 nats. This is the additional expected log loss caused by losing the contextual distinction, even with an ideal prediction head.
If the trained head instead outputs , it adds
for a total excess loss of approximately 0.388 nats. Improving the head removes the second cost; preserving the distinction between contexts is needed to remove the first.
Sensitivity of predictions to source-weight errors. The loss decomposition concerns predictive information loss and head error. The following consequence of Proposition 2 instead bounds how a fixed head’s output changes when its input is formed with approximate source weights.
Corollary 2. Stability of predictions from approximate means. Fix the query, keys, and value vectors, with . Let be the exact source-probability vector and an approximation, where
The subscript distinguishes source probabilities from output-token probabilities; identifies one component. Under the exact Bayesian correspondence, attention weights satisfy ; approximate attention weights play the role of .
Suppose the fixed prediction head is -Lipschitz; that is, there exists a finite constant such that, for all input representations and in the domain under consideration,
This bounds its sensitivity: an input change cannot be amplified by more than in the output. For example, turns an input difference of 0.01 into an output difference of at most 0.02. Writing and , we obtain
The result traces source-weight error through the representation to output perturbation, complementing the loss decomposition. For a Transformer, these results distinguish three requirements: the representation supplied to the prediction head must retain the relevant contextual information, the head must use it accurately, and errors in attention weights should not cause large output changes. The stability bound addresses the third requirement under bounded-value and Lipschitz assumptions.
The information bottleneck connection {#sec:7.5}
The information bottleneck principle of Tishby et al. [14] asks how much of an input can be discarded while retaining information useful for prediction. Predictive sufficiency describes the ideal preservation condition: once the summary is known, seeing the full context would not improve the next-token distribution. Mutual information measures how much knowing one random variable helps predict another. For example, measures how informative the summary is about the next token. It is symmetric, and is zero exactly when the variables are independent. For , an idealized bottleneck objective is
The term “bottleneck” describes the summary as a restricted passage through which context information must reach the predictor:
The predictor receives the context only through . The objective encourages this passage to retain less context information while preserving information useful for the next token. The minimization in Equation (23) chooses a representation function that balances compression against predictive usefulness. The first term, , measures how much knowing the summary tells us about the original context . If every context produces the same summary, it reveals nothing about which context occurred and this mutual information
is zero. If the summary uniquely identifies the context, it retains all its information; otherwise, contexts sharing a summary are no longer distinguishable from that summary alone. For example, the count summary in Section 7.2 maps , , and to the same value, discarding their order. Minimizing this term encourages removing such distinctions when they are unnecessary for prediction. The second term, , measures how much knowing the summary helps predict the next token compared with not knowing the summary. Without it, the ideal predictor uses the overall probabilities ; with it, the predictor uses . The expected improvement is
This is the expected reduction in log loss obtained by knowing the summary. Because this term is subtracted in Equation (23), minimization rewards preserving next-token information. The parameter sets the relative importance of the two terms. A small favors compression, potentially sacrificing predictive information; a large places more emphasis on next-token information, potentially retaining more of the context.
We recall the chain rule for mutual information: for random variables , , ,
The information supplied by and together about equals the information supplied by , plus the additional information supplied by once is known. Reversing the order gives
The total is unchanged, although its division between the two terms may differ.
Applied to our representation, this rule separates the full context’s predictive information into information retained by the summary and information lost when using that summary. Because is determined by the context, adding it to the full context supplies no new information:
The chain rule expresses the same quantity by first revealing the summary and then revealing the full context:
Combining these identities gives
The last term asks: after seeing the summary, how much more could we learn about the next token by seeing the full context? Any additional predictive information available from the context was lost when the context was replaced by the summary. As § 7.4 establishes,
Thus, representation loss is the expected additional log loss incurred by the best summary-based predictor compared with the best full-context predictor. This is the same representation-loss term that appears in Equation (22). Section 7.4 decomposes excess log loss into representation loss and prediction-head error; here, the chain rule decomposes full-context predictive information into retained information and representation loss. No head-error term appears in this information decomposition because it concerns the representation itself, independently of the trained head. The common term connects the two perspectives: predictive information discarded by the representation becomes unavoidable additional expected log loss, even for the best possible head. With the data distribution fixed, retaining more next-token information reduces this loss. It is zero exactly when the summary is predictively sufficient, so that . The bottleneck objective balances compression against this preservation requirement.
In § 7.2, the count difference replaces the entire sequence without changing the next-symbol distribution. This illustrates compression that remains predictively sufficient under the specified generating model. For a Transformer, the corresponding question is whether its attention-based representation discards unnecessary details while retaining what determines the next-token distribution.
Algorithmic future-loss bounds and representation loss
Solomonoff induction and its associated future-loss bounds offer a conditional route to bounding the next-token information lost by an attention representation. We specialize the continuation bound of Chernov et al. [3] to a single next token (), combine it with an additional predictor-approximation assumption, and apply the decomposition in § 7.4.
Fix a context length . Let the sequence follow a computable probability measure on a finite alphabet , and let be a deterministic attention-based representation with learned parameters fixed. A normalized predictor assigns probabilities to the next token , using the context only through this representation. All logarithms and information quantities in this subsection use base 2.
Here, uppercase denotes the random token at position , while lowercase denotes a particular observed value. Thus is the random context and is an observed context. The bound involving below applies to a fixed observed context; subsequently averages over possible contexts according to their probabilities under .
The full-context result for one token. For an observed context with , Theorem 1 of Chernov et al. [3], applied to a one-token continuation , gives
whenever . Here describes a shortest self-delimiting procedure computing given , describes the context length, and is a reference-machine constant independent of , , . The Solomonoff next-token weight is . Averaging over the next token bounds the ideal full-context predictor’s expected additional log loss by .
The additional approximation requirement. Suppose a nonnegative penalty satisfies
for every context of positive -probability and every token with . This limits the representation-based predictor’s additional log loss relative to , uniformly over those tokens. For example, requires at least half the reference weight. The penalty concerns both the representation and its head, not representation loss alone. Its smallest admissible nonnegative value for fixed is
with an infinite ratio when the denominator is zero.
From next-token loss to representation loss. The full-context result for one token and the additional approximation requirement above give
Splitting the true-to-predicted log ratio at combines these bounds:
Next, we average over possible next tokens by multiplying by and summing:
The right-hand side is unchanged because it does not depend on the next token and the averaging weights sum to one. Then, we average over contexts generated by , with :
This bounds the representation-based predictor’s total expected excess log loss.
Finally, we apply § 7.4’s decomposition, now with base-2 logarithms:
The first term is representation loss; the second is prediction-head error. Since the head-error term is nonnegative, representation loss alone cannot exceed their sum. Hence,
A prediction head cannot recover information absent from its input. If two contexts require different next-token distributions but produce the same summary, a predictor using only that summary cannot distinguish them and must use the same prediction for both. This creates unavoidable additional expected log loss, even for the best possible head. Since representation loss is a nonnegative component of total expected excess log loss, a small total implies small representation loss.
Here, the approximation assumption yields an upper bound of on that total. The term bounds the reference predictor’s additional loss, while bounds the summary-based predictor’s further loss relative to that reference. The calculation provides a route to a guarantee only when the combined bound is sufficiently small; establishing such control for a trained Transformer remains an additional challenge.
Implications for Transformer Contextual Prediction
We can now return to the motivating question: Why might attention be so effective for contextual prediction?
Our analysis suggests several possible contributions of attention to contextual prediction.
Attention evaluates relationships, not only token identities. A fixed embedding represents a token through learned numerical features. Attention makes the contribution of one token depend on its relationship to another token. The same word can therefore contribute differently to different predictions. This is important because language is relational. The meaning and predictive relevance of a token often depend on grammatical roles, references, surrounding words, and broader semantic structure. A mechanism capable of dynamically evaluating relationships is naturally suited to such tasks.
Attention implements soft selection. Attention does not generally require selecting exactly one source. It forms a weighted combination of candidates. Under the generative latent-source assumptions, this is posterior-weighted averaging of conditional payload means. Soft aggregation may be useful when several interpretations remain plausible or when information is distributed across multiple positions.
Attention supports conditional information aggregation. The Value vector contains information associated with a candidate source. The Query–Key operation determines the relative contribution of that information to a given query. Thus, attention separates two computational questions:
Which contextual information should contribute?
What information should be contributed?
In our probabilistic model, these correspond to posterior source probabilities and conditional payload expectations. This separation provides a mechanism for input-dependent information aggregation.
Multi-head attention supports simultaneous relationships. Different attention heads can operate in different learned representation spaces. This enables several contextual relationships to be evaluated concurrently. Their outputs can then be combined and transformed. This permits complementary contextual computations.
Depth reorganizes information for prediction. With model parameters fixed, suppose one layer transforms into . Here, includes the representations at all token positions, and the layer receives no additional input beyond this state and fixed architectural quantities. Since the later representation is computed from the earlier one, it cannot contain information about the next token that was absent from the entire earlier representation. Formally, the data-processing inequality [4] gives
Later layers can nevertheless combine and reorganize existing information so that the available prediction head can use it more effectively. Attention may bring information from several positions into the representation used for prediction, and subsequent transformations can make relevant distinctions easier to extract. Information at an individual position may therefore increase even though its total amount across the complete representation cannot. Depth can improve the accessibility of predictive information without increasing its total amount.
Limitations and Open Questions
The main limitation of this analysis is the gap between computations that attention can implement under a specified probabilistic model and those acquired by a trained Transformer. Bridging this gap requires theoretical analysis and empirical evidence about the learned representations; their roles cannot be inferred uniquely from numerical weights or predictive behavior alone. The categorical-source and Gaussian constructions provide tractable models, but their assumptions need not describe trained heads. Although a source’s value may already combine information from several positions, a single source variable does not necessarily capture all relationships involved in prediction. Even when attention computes an exact posterior mean, this does not establish predictive sufficiency or accurate use of the representation by the prediction head. Likewise, additional layers can reorganize information without guaranteeing improvement or automatically implementing further Bayesian updates. The next task is therefore to identify assumptions about the architecture, data distribution, and training procedure under which useful representations and accurate heads can be learned from finite samples. A complete account must connect the data distribution and learning procedure to the information retained by the representation and the accuracy of its prediction head. Any resulting guarantee should specify the attention architecture, data-generating model, training procedure, and reference predictor. The algorithmic prediction connection additionally requires a useful bound on the approximation penalty, which remains open for trained attention representations. The stability bounds in § 6.9 and § 7.4 control perturbations but do not establish these learning or predictive guarantees. Establishing conditions that connect information preservation, prediction accuracy, learnability, and efficiency remains the central research challenge.
Conclusion
This paper connects existing probabilistic interpretations of Transformer attention with predictive sufficiency and representation loss. Under explicit assumptions, attention’s weighted value aggregation can be interpreted as a conditional expectation and, in a generative model, as a Bayesian posterior mean. Building on Gabbur et al.’s framework, the Gaussian construction recovers scaled dot-product attention for arbitrary key norms. The central implication is that optimal estimation of a contextual payload does not alone establish optimal next-token prediction: the representation must preserve the relevant information, and the prediction head must use it correctly. An established excess-log-loss decomposition makes this distinction precise by separating representation information loss from prediction-head error, while stability bounds control the effects of source-weight errors under bounded-value and Lipschitz assumptions. The information bottleneck perspective relates compression to predictive preservation, and the connection to Solomonoff prediction identifies an additional approximation requirement. Together, these analyses help identify the assumptions under which probabilistic interpretations can support useful guarantees for Transformer attention. Determining which conditions hold in trained models, and how architecture and training might make them hold more reliably, could guide the development of AI systems that preserve and use predictive information more effectively.
References
References
- [1]Brown, T. B., et al. (2020). Language Models Are Few-Shot Learners. arXiv:2005.14165 [cs.CL].arxiv.org/abs/2005.14165
- [2]Brunner, G., Liu, Y., Pascual, D., Richter, O., Ciaramita, M., and Wattenhofer, R. (2020). On Identifiability in Transformers. in Proceedings of International Conference on Learning Representations.
- [3]Chernov, A., Hutter, M., and Schmidhuber, J. (2007). Algorithmic Complexity Bounds on Future Prediction Errors. arXiv:cs/0701120v1 [cs.LG].DOI
- [4]Cover, T. M., and Thomas, J. A. (2006). Elements of Information Theory. 2nd ed. Wiley-Interscience.
- [5]Deng, Y., Kim, Y., Chiu, J., Guo, D., and Rush, A. M. (2018). Latent Alignment and Variational Attention. Advances in Neural Information Processing Systems 31.arxiv.org/abs/1807.03756
- [6]Fisher, R. A. (1922). On the Mathematical Foundations of Theoretical Statistics. Philosophical Transactions of the Royal Society of London. Series A, 222, 309–368.
- [7]Gabbur, P., Bilkhu, M., and Movellan, J. R. (2021). Probabilistic Attention for Interactive Segmentation. Advances in Neural Information Processing Systems 34.arxiv.org/abs/2106.15338
- [8]Hutter, M. (2005). Universal Artificial Intelligence: Sequential Decisions Based on Algorithmic Probability. Springer.
- [9]Levin, D. A., and Peres, Y., with contributions by Wilmer, E. L. (2017). Markov Chains and Mixing Times. 2nd ed. American Mathematical Society.
- [10]Li, M., and Vitányi, P. (1993) An Introduction to Kolmogorov Complexity and Its Applications. Springer-Verlag.
- [11]Silva, J. F., Faraggi, V., Ramirez, C., Egana, A., and Pavez, E. (2024). Understanding Encoder-Decoder Structures in Machine Learning Using Information Measures. arXiv:2405.20452 [cs.LG].arxiv.org/abs/2405.20452
- [12]Singh, R., and Buckley, C. L. (2023). Attention: Marginal Probability is All You Need?. arXiv:2304.04556 [cs.LG].arxiv.org/abs/2304.04556
- [13]Solomonoff, R. J. (1964). A Formal Theory of Inductive Inference. Information and Control, Parts I and II.
- [14]Tishby, N., Pereira, F. C., and Bialek, W. (1999). The Information Bottleneck Method. arXiv:physics/0004057 [physics.data-an].
- [15]Vaswani, A., et al. (2017). Attention Is All You Need. arXiv:1706.03762 [cs.CL].arxiv.org/abs/1706.03762
- [16]Zhang, Y., Zhang, F., Yang, Z., and Wang, Z. (2025). 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, PMLR 258:1684-1692.