betaFeedback

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

x1,x2,…,xtx_1, x_2, \ldots, x_t

denote a sequence of tokens from a vocabulary X\mathcal{X}. The objective is to estimate

P(xt+1∣x1,…,xt).P(x_{t+1} \mid x_1, \ldots, x_t).

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:

Attention⁡(Q,K,V)=softmax⁡(QKTdk)V\operatorname{Attention}(Q,K,V)=\operatorname{softmax}\left(\frac{QK^{\mathsf{T}}}{\sqrt{d_k}}\right)V

Here, QQ and KK store query and key vectors as rows, so the (i,j)(i,j) entry of QKTQK^{\mathsf{T}} is the dot product qiTkjq_i^{\mathsf{T}}k_j, comparing query ii with key jj. The quantity dkd_k is the dimension of each query and key vector; dividing by dk\sqrt{d_k} helps keep these scores on a consistent numerical scale as dkd_k 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.

  1. Under what conditions can query–key compatibility be interpreted as evidence for a contextual hypothesis?

  1. Under what conditions do attention weights correspond to Bayesian posterior probabilities over latent variables?

  1. When can the weighted combination of value vectors be identified with a posterior expectation?

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

2, 4, 6, 8.2,\ 4,\ 6,\ 8.

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 HH represent a hypothesis and DD the observed data. Bayes’ rule states

P(H∣D)=P(D∣H)P(H)P(D).P(H \mid D) = \frac{P(D \mid H)P(H)}{P(D)}.

The components have the following interpretations:

  • P(H)P(H) is the prior probability of the hypothesis.

  • P(D∣H)P(D \mid H) is the likelihood of the observations under the hypothesis.

  • P(D)P(D) is the marginal probability of the observations.

  • P(H∣D)P(H \mid D) is the posterior probability.

For a finite hypothesis class H\mathcal{H},

P(D)=∑h∈HP(D∣h)P(h).P(D) = \sum_{h \in\mathcal{H}} P(D \mid h)P(h).

The posterior is therefore determined jointly by prior plausibility and explanatory agreement with the observations.

Sequential Bayesian updating

Suppose observations arrive sequentially:

x1,x2,…,xt.x_1, x_2, \ldots, x_t.

Write x<t=(x1,…,xt−1)x_{<t} = (x_1, \ldots, x_{t-1}) for the observations preceding position tt, and x1:t=(x1,…,xt)x_{1:t} = (x_1, \ldots, x_t) for the observations up to and including position tt. After observing xtx_t, the posterior becomes

Pt(h)=Pt−1(h)P(xt∣h,x<t)∑h′Pt−1(h′)P(xt∣h′,x<t).P_t(h) = \frac{P_{t-1}(h)P(x_t \mid h, x_{<t})}{\sum_{h'} P_{t-1}(h')P(x_t \mid h', x_{<t})}.

Every observation modifies the probability assigned to competing hypotheses, and the updated posterior becomes the prior for the next observation. For the complete sequence,

Pt(h)=P(h)P(x1:t∣h)P(x1:t).P_t(h) = \frac{P(h)P(x_{1:t} \mid h)}{P(x_{1:t})}.

Using the probability chain rule,

P(x1:t∣h)=∏i=1tP(xi∣h,x<i).P(x_{1:t} \mid h) = \prod_{i=1}^{t} P(x_i \mid h, x_{<i}).

Consequently,

Pt(h)=P(h)∏i=1tP(xi∣h,x<i)P(x1:t).P_t(h) = \frac{P(h)\prod_{i=1}^{t} P(x_i \mid h, x_{<i})}{P(x_{1:t})}.

s Taking logarithms yields

log⁡Pt(h)=log⁡P(h)+∑i=1tlog⁡P(xi∣h,x<i)−log⁡P(x1:t).(1)\log P_t(h) = \log P(h) + \sum_{i=1}^{t} \log P(x_i \mid h, x_{<i}) - \log P(x_{1:t}). \tag*{(1)}

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:

P(xt+1∣x1:t)=∑h∈HPt(h)P(xt+1∣h,x1:t).P(x_{t+1} \mid x_{1:t}) = \sum_{h \in\mathcal{H}} P_t(h)P(x_{t+1} \mid h, x_{1:t}).

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:

  1. Bayesian conditioning updates the probabilities of competing hypotheses.

  2. 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 UpfU_{\mathrm{pf}} 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 xx, define

K(x)=min⁡p:Upf(p)=x∣p∣.K(x) = \min_{p:U_{\mathrm{pf}}(p)=x} |p|.

Here, Upf(p)=xU_{\mathrm{pf}}(p) = x means that the machine outputs exactly xx and halts, and ∣p∣|p| is the program length in bits.

Regular strings can have short descriptions. For example, nn repetitions of 01 can be described by a repetition procedure and the number nn. 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 K(n)K(n) is the complexity of a standard binary encoding of the integer nn, while K(μ)K(\mu) is the length of a shortest self-delimiting description of a procedure computing the probability measure μ\mu. Conditional complexity K(μ∣x)K(\mu\mid x) measures the shortest such description when xx is supplied as additional input. A procedure computing μ\mu 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 MM. We use separate symbols to distinguish the two constructions.

The universal semimeasure

Let UmonU_{\mathrm{mon}} 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 x⪯Umon(p)x \preceq U_{\mathrm{mon}}(p) to mean that the machine produces an output beginning with xx after reading no more than the input bits in the finite string pp. For a fixed observed string xx, define the set of minimal sufficient input prefixes by

Px={p∈{0,1}∗  |  x⪯Umon(p), and x⋠Umon(q) for every proper prefix q of p}.P_x = \left\{ p \in\{0,1\}^{*} \;\middle|\; x \preceq U_{\mathrm{mon}}(p),\ \text{and } x \npreceq U_{\mathrm{mon}}(q)\ \text{for every proper prefix }q\text{ of }p \right\}.

Here, minimal means that no shorter input prefix of the same string already suffices; it does not mean shortest among all descriptions of xx.

For each fixed xx, the set PxP_x 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 xx, 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 pp is 2−∣p∣2^{-|p|}. Because PxP_x is prefix-free, the corresponding input events are disjoint, so their probabilities can be added without double-counting. Solomonoff’s universal semimeasure is

M(x)=∑p∈Px2−∣p∣.M(x) = \sum_{p \in P_x} 2^{-|p|}.

Thus, M(x)M(x) is the probability that the output of UmonU_{\mathrm{mon}} begins with xx 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 xx does not require producing any further output. After producing xx, the machine may halt, run indefinitely without further output, or continue producing symbols. For binary outputs this gives

M(x0)+M(x1)≤M(x).M(x0) + M(x1) \le M(x).

The difference is the probability of input streams that produce xx but never produce a subsequent output bit. This possible loss of continuation mass makes MM 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 MM is a semimeasure, so the weights assigned to possible next symbols may sum to less than one. Let ExE_x be the event that its output begins with xx, and let ExyE_{xy} be the event that it begins with the concatenation xyxy. Since Exy⊆ExE_{xy} \subseteq E_x (any output beginning with xyxy necessarily begins with xx),

P(Exy∣Ex)=P(Exy)P(Ex)=M(xy)M(x),P(E_{xy}\mid E_x)=\frac{P(E_{xy})}{P(E_x)}=\frac{M(xy)}{M(x)},

provided M(x)>0M(x) > 0. Here, probabilities refer to independent, uniformly random input bits supplied to the machine. Thus, given an observed prefix xx, we define the conditional continuation weight of a finite string yy by

M(y∣x)=M(xy)M(x).M(y \mid x) = \frac{M(xy)}{M(x)}.

For the next binary symbol,

M(0∣x)+M(1∣x)≤1.M(0 \mid x) + M(1 \mid x) \le1.

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 M(x)M(x) is incomputable, a limitation closely related to the undecidability of the halting problem. Computing M(x)M(x) requires summing the weights of all minimal input prefixes that cause a universal monotone Turing machine to produce an output beginning with xx. 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 M(x)M(x) from below by progressively discovering contributions, obtaining increasingly accurate lower bounds. Thus, M(x)M(x) is lower semicomputable, but not computable. Still, M(x)M(x) has strong theoretical prediction properties. In particular, for any computable probability measure μ\mu, there is a constant cμ>0c_\mu> 0, independent of xx, such that

M(x)≥cμμ(x).(2)M(x) \ge c_\mu\mu(x). \tag*{(2)}

This property is called universal dominance. It says that, for every computable probability measure μ\mu, the universal semimeasure MM assigns each finite string xx at least a fixed positive fraction of its probability under μ\mu. 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 nn observations by

Ln=∑t=1nlog⁡2μ(Xt∣X<t)M(Xt∣X<t).L_n = \sum_{t=1}^{n} \log_2 \frac{\mu(X_t \mid X_{<t})}{M(X_t \mid X_{<t})}.

Here, XtX_t is the random symbol at position tt, and X<t=(X1,…,Xt−1)X_{<t} = (X_1, \ldots, X_{t-1}) is the preceding random sequence. Lowercase xtx_t denotes a particular observed value of XtX_t. In language modeling, these symbols correspond to tokens from the model’s vocabulary. We use the convention M(ϵ)=1M(\epsilon) = 1 for the empty string ϵ\epsilon. The quantity LnL_n compares the cumulative log loss of the semimeasure-based predictor with that of a predictor that already knows the true generating distribution μ\mu. At step tt, subtracting the true predictor’s loss from Solomonoff’s loss gives

−log⁡2M(Xt∣X<t)−[−log⁡2μ(Xt∣X<t)]=log⁡2μ(Xt∣X<t)M(Xt∣X<t).\begin{aligned} -\log_2 M(X_t \mid X_{<t}) - \left[-\log_2 \mu(X_t \mid X_{<t})\right] \\ &= \log_2 \frac{\mu(X_t \mid X_{<t})}{M(X_t \mid X_{<t})}. \end{aligned}

Summing these differences over the observations gives LnL_n. Since a sum of logarithms is the logarithm of a product,

Ln=log⁡2∏t=1nμ(Xt∣X<t)∏t=1nM(Xt∣X<t).L_n = \log_2 \frac{\prod_{t=1}^{n} \mu(X_t \mid X_{<t})}{\prod_{t=1}^{n} M(X_t \mid X_{<t})}.

The probability chain rule gives ∏t=1nμ(Xt∣X<t)=μ(X1:n)\prod_{t=1}^{n}\mu(X_t \mid X_{<t})=\mu(X_{1:n}). For MM, the definition of its conditional continuation weights gives:

∏t=1nM(Xt∣X<t)=∏t=1nM(X1:t)M(X<t)=M(X1:n)M(ϵ)=M(X1:n).\prod_{t=1}^{n} M(X_t \mid X_{<t})=\prod_{t=1}^{n}\frac{M(X_{1:t})}{M(X_{<t})}=\frac{M(X_{1:n})}{M(\epsilon)}=M(X_{1:n}).

Therefore,

Ln=log⁡2μ(X1:n)M(X1:n)=−log⁡2M(X1:n)+log⁡2μ(X1:n).L_n=\log_2\frac{\mu(X_{1:n})}{M(X_{1:n})}=-\log_2 M(X_{1:n})+\log_2\mu(X_{1:n}).

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 μ\mu. Applying −log⁡2-\log_2 to Equation (2) reverses the inequality:

⟹−log⁡2M(x1:n)≤−log⁡2μ(x1:n)−log⁡2cμ.\Longrightarrow\quad-\log_2 M(x_{1:n})\leq-\log_2\mu(x_{1:n})-\log_2 c_\mu.

Subtracting the true predictor’s sequence loss, −log⁡2μ(x1:n)-\log_2\mu(x_{1:n}), from both sides and using the definition of LnL_n gives

Ln≤−log⁡2cμ.L_n\leq-\log_2 c_\mu.

Because this holds for every sequence of positive probability under μ\mu, it also holds after averaging over sequences generated by μ\mu:

Eμ[Ln]≤−log⁡2cμ.\mathbb{E}_\mu[L_n]\leq-\log_2 c_\mu.

Since this upper bound is independent of nn, the expected excess log loss per symbol tends to zero as the number of observations grows:

0≤Eμ[Ln]n≤−log⁡2cμn→n→∞0.0\leq\frac{\mathbb{E}_\mu[L_n]}{n}\leq\frac{-\log_2 c_\mu}{n}\xrightarrow[n\to\infty]{}0.

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:

Observed sequence⟶Next-symbol prediction.\text{Observed sequence}\longrightarrow\text{Next-symbol prediction}.

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

x1,x2,…,xt.x_1, x_2, \ldots, x_t.

Each token is mapped to a learned embedding in a dd-dimensional space. Let the embedding of token xix_i be denoted by

ei=E(xi)∈Rd.e_i = E(x_i) \in\mathbb{R}^d.

Positional information is also incorporated. In an additive positional-embedding formulation, the position ii is represented by a vector

pi∈Rd,p_i \in\mathbb{R}^d,

which is computed using a fixed encoding. The initial input representation is then

hi(0)=ei+pi.h_i^{(0)} = e_i + p_i.

Here, ii identifies the token’s position, eie_i is its token embedding, and pip_i represents its position. The superscript (0)(0) labels the initial representation, before any Transformer layers have processed it. More generally, hi(ℓ)h_i^{(\ell)} denotes the representation at position ii after ℓ\ell Transformer layers.

Query, Key, and Value

For each token representation hih_i, the attention mechanism constructs three vectors through learned linear projections: the query qiq_i, the key kik_i, and the value viv_i:

qi=WQhi,q_i = W_Q h_i,
ki=WKhi,k_i = W_K h_i,
vi=WVhi.v_i = W_V h_i.

The projection matrices WQW_Q, WKW_K, and WVW_V are learned during training. The input representation has dimension dd, whereas the queries and keys have dimension dkd_k, and the values have dimension dvd_v:

hi∈Rd,qi,ki∈Rdk,vi∈Rdv.h_i \in\mathbb{R}^d,\qquad q_i, k_i \in\mathbb{R}^{d_k},\qquad v_i \in\mathbb{R}^{d_v}.

Using a column-vector convention, we have

WQ,WK∈Rdk×d,WV∈Rdv×d.W_Q, W_K \in\mathbb{R}^{d_k \times d},\qquad W_V \in\mathbb{R}^{d_v \times d}.

The subscript kk 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 dk<dd_k < d, these query and key projections perform dimensionality reduction: they learn to combine the input components into fewer output components. For a sequence of length tt, computing all query–key dot products costs on the order of t2dkt^{2}d_k, rather than t2dt^{2}d for full-dimensional queries and keys. The score matrix still has t2t^{2} entries in full attention, so this reduction does not remove the quadratic dependence on sequence length. The sequence length tt is bounded by the Transformer’s context-window capacity.

In multi-head attention, dkd_k and dvd_v describe the query/key and value dimensions, respectively, within each head. A common choice with mm heads is dk=dv=d/md_k=d_v=d/m. For example, the 175-billion-parameter GPT-3 model [1] has an embedding dimension of d=12,288d=12{,}288 and m=96m=96 attention heads per layer, giving dk=dv=128d_k=d_v=128: 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 qiq_i, kjk_j, and vjv_j serve distinct computational roles. For a query position ii and an accessible source position jj, the query qiq_i represents the information sought at position ii. The key kjk_j is compared with qiq_i to determine the source’s attention weight relative to other accessible sources. The value vjv_j 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 ii and candidate source position jj, the compatibility score is

sij=qiTkjdk.s_{ij}=\frac{q_i^{\mathsf{T}}k_j}{\sqrt{d_k}}.

The dot product adds together dkd_k products of query and key components:

qiTkj=∑r=1dkqirkjr.q_i^{\mathsf{T}}k_j=\sum_{r=1}^{d_k}q_{ir}k_{jr}.

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 dkd_k, so its standard deviation is dk\sqrt{d_k}. Dividing by dk\sqrt{d_k} 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:

αij=exp⁡(sij)∑r∈Aiexp⁡(sir).\alpha_{ij}=\frac{\exp(s_{ij})}{\sum_{r\in\mathcal{A}_i}\exp(s_{ir})}.

where Ai\mathcal{A}_i is the set of positions accessible to the query at position ii; that is, the positions that token ii is allowed to attend to. In causal self-attention, Ai\mathcal{A}_i includes all earlier positions and position ii itself:

Ai={1,…,i}.\mathcal{A}_i=\{1,\ldots,i\}.

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:

αij≥0,∑j∈Aiαij=1.\alpha_{ij}\ge0,\qquad\sum_{j\in\mathcal{A}_i}\alpha_{ij}=1.

Value aggregation

For each query position ii, attention produces an output vector ziz_i by taking a weighted average of the value vectors at accessible source positions:

zi=∑j∈Aiαijvj.(3)z_i = \sum_{j \in A_i} \alpha_{ij} v_j. \tag*{(3)}

Here, vjv_j supplies the information associated with source position jj. The attention weight αij\alpha_{ij} determines how much that source contributes for query position ii. By contrast, ziz_i 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,

Z=Attention⁡(Q,K,V)=softmax⁡(QKTdk+Mmask)V.(4)Z = \operatorname{Attention}(Q,K,V) = \operatorname{softmax}\left(\frac{QK^{\mathsf{T}}}{\sqrt{d_k}} + M_{\mathrm{mask}}\right)V. \tag*{(4)}

The ii-th row of ZZ is ziTz_i^{\mathsf{T}}. Each row of QQ, KK, and VV contains the corresponding query, key, or value vector, respectively, and softmax is applied separately to each row of the score matrix. The additive mask MmaskM_{\mathrm{mask}} specifies which source positions are allowed for each query.

A causal mask implements causal self-attention by setting

(Mmask)ij={0,j≤i,−∞,j>i.(M_{\mathrm{mask}})_{ij} = \begin{cases} 0, & j \le i,\\ -\infty, & j > i. \end{cases}

Adding zero leaves an allowed score unchanged. Adding −∞-\infty to a future-position score makes its softmax weight zero. Consequently, αij=0\alpha_{ij} = 0 whenever j>ij > i, and Equation (4) reproduces the restricted sum in Equation (3).

Multi-head attention

Let H∈Rt×dH \in\mathbb{R}^{t \times d} contain the token representations as rows. Each of mm attention heads uses its own learned projections:

Q(r)=H(WQ(r))T,K(r)=H(WK(r))T,V(r)=H(WV(r))T.\begin{aligned} Q^{(r)} &= H(W_Q^{(r)})^{\mathsf{T}}, \qquad K^{(r)} = H(W_K^{(r)})^{\mathsf{T}}, \qquad V^{(r)} = H(W_V^{(r)})^{\mathsf{T}}. \end{aligned}

The transposes reconcile this row representation with the column-vector convention in § 4.2. Each head applies the attention operation and mask defined above:

Z(r)=Attention⁡(Q(r),K(r),V(r)).Z^{(r)} = \operatorname{Attention}(Q^{(r)}, K^{(r)}, V^{(r)}).

The outputs are concatenated and projected back to the model dimension:

MHA⁡(H)=Concat⁡(Z(1),…,Z(m))WO.\operatorname{MHA}(H) = \operatorname{Concat}(Z^{(1)}, \ldots, Z^{(m)})W_O.

Each head returns one dvd_v-dimensional output per token:

Z(r)∈Rt×dv.Z^{(r)} \in\mathbb{R}^{t \times d_v}.

Concatenation places the heads’ outputs side by side for each token, preserving the number of rows:

Concat⁡(Z(1),…,Z(m))∈Rt×(mdv).\operatorname{Concat}(Z^{(1)}, \ldots, Z^{(m)}) \in\mathbb{R}^{t \times(m d_v)}.

The learned output projection has dimensions

WO∈R(mdv)×d.W_O \in\mathbb{R}^{(m d_v) \times d}.

Therefore,

MHA⁡(H)⏟t×d=Concat⁡(Z(1),…,Z(m))⏟t×(mdv)WO⏟(mdv)×d.\underbrace{\operatorname{MHA}(H)}_{t \times d} = \underbrace{\operatorname{Concat}\left(Z^{(1)},\ldots,Z^{(m)}\right)}_{t \times(m d_v)} \underbrace{W_O}_{(m d_v) \times d}.

Multiplication by WOW_O mixes the heads’ contributions and returns each token’s representation to dimension dd.

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:

P(y∣D)=∑hP(h∣D)P(y∣h,D).P(y \mid D) = \sum_h P(h \mid D)P(y \mid h,D).

Now consider attention:

zi=∑jαijvj.z_i = \sum_j \alpha_{ij}v_j.

Both expressions combine candidate contributions using normalized weights. The resemblance suggests the following correspondence:

Bayesian inferenceTransformer attention
Candidate hypothesis hhCandidate contextual information source jj
Observed evidence DDObserved query at position ii
Posterior weight P(h∣D)P(h \mid D)Attention weight αij\alpha_{ij}
Conditional contributionValue vector vjv_j
Posterior averagingWeighted 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 CC denote the observed context and suppose H1,H2H_1, H_2 are exhaustive alternatives with w=P(H1∣C)w = P(H_1 \mid C). Bayesian model averaging gives

P(y∣C)=wP(y∣H1,C)+(1−w)P(y∣H2,C)=P(y∣H2,C)+w[P(y∣H1,C)−P(y∣H2,C)].P(y \mid C) = wP(y \mid H_1,C) + (1-w)P(y \mid H_2,C) = P(y \mid H_2,C) + w[P(y \mid H_1,C) - P(y \mid H_2,C)].

Holding the conditional predictions fixed, a change Δw\Delta w therefore changes the predicted probability by

ΔP(y∣C)=Δw[P(y∣H1,C)−P(y∣H2,C)].\Delta P(y \mid C) = \Delta w[P(y \mid H_1,C) - P(y \mid H_2,C)].

Thus, sensitivity to the posterior weight depends on the difference between the hypotheses’ conditional predictions. For example, if w=0.95w = 0.95 and the two likelihoods are 0.70 and 0.69, the mixture assigns it probability 0.95(0.70)+0.05(0.69)=0.69950.95(0.70) + 0.05(0.69) = 0.6995. The strong support for H1H_1 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 w=0.95w = 0.95, but suppose that a particular next token aa has conditional probabilities

P(a∣H1,C)=0,P(a∣H2,C)=0.8.P(a \mid H_1,C) = 0,\qquad P(a \mid H_2,C) = 0.8.

The predictive mixture assigns that token probability

P(a∣C)=0.95(0)+0.05(0.8)=0.04.P(a \mid C) = 0.95(0) + 0.05(0.8) = 0.04.

This shows that although H2H_2 is relatively unlikely, it supplies the entire 4% probability assigned to aa. Retaining only H1H_1 would rule out this token. However, because a conditional probability cannot exceed one, its contribution is bounded by its posterior weight:

P(H2∣C)P(a∣H2,C)≤P(H2∣C)=0.05.P(H_2 \mid C)P(a \mid H_2,C) \le P(H_2 \mid C) = 0.05.

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:

zi=∑j∈Aiαijvj.z_i = \sum_{j \in A_i} \alpha_{ij}v_j.

A weight αij\alpha_{ij} determines how much source jj contributes, while its value vector vjv_j determines what it contributes. Holding the values and other weights fixed, shifting an amount δ\delta of weight from source 2 to source 1 changes the output by

Δzi=δ(v1−v2),\Delta z_i = \delta(v_1-v_2),

If v1=v2v_1 = v_2, 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 JiJ_i, which identifies a candidate contextual information source. The direct conditional model defines its probabilities using attention weights, P(Ji=j∣qi,K)=αijP(J_i = j \mid q_i, K) = \alpha_{ij}. 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

R∈{sample,refrigerator}R \in\{\text{sample}, \text{refrigerator}\}

and ask for P(R=r∣sentence)P(R = r \mid\text{sentence}), 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 ii, let Ai\mathcal{A}_i be the finite, nonempty set of accessible contextual source positions. Introduce a categorical latent variable

Ji∈Ai.J_i \in\mathcal{A}_i.

The event Ji=jJ_i = j identifies position jj as the information source in the latent-variable model. Each possible source therefore defines a candidate hypothesis:

Hij={Ji=j}.H_{ij} = \{J_i = j\}.

A conditional categorical model. For finite query–key scores sijs_{ij}, let

P(Ji=j∣qi,K)=αij=exp⁡(qiTkj/dk)∑r∈Aiexp⁡(qiTkr/dk).P(J_i = j \mid q_i, K) = \alpha_{ij} = \frac{\exp(q_i^{\mathsf{T}} k_j / \sqrt{d_k})}{\sum_{r \in A_i} \exp(q_i^{\mathsf{T}} k_r / \sqrt{d_k})}.

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 JiJ_i for those inputs without modeling their probability of occurrence.

Value aggregation as a conditional expectation

At the first Transformer layer, let

vj(0)=WV(0)hj(0).v_j^{(0)} = W_V^{(0)} h_j^{(0)}.

This vector represents a learned projection of the information available at position jj. 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 jj, while the attention weight αij\alpha_{ij} determines how strongly that vector contributes to the attention output for query position ii:

zi=∑j∈Aiαijvj.z_i = \sum_{j \in A_i} \alpha_{ij} v_j.

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,

vj(ℓ)=WV(ℓ)hj(ℓ−1),v_j^{(\ell)} = W_V^{(\ell)} h_j^{(\ell-1)},

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 V=(v1,…,vt)V = (v_1, \ldots, v_t) 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 WVW_V and the representations it acts on change.

Define the random payload by

Vi=vJi.V_i = v_{J_i}.

Although the possible value vectors are fixed, ViV_i is random because the source index JiJ_i is uncertain in the model. Once the source Ji=jJ_i = j is known, however, the payload is fully determined: it equals vjv_j. 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 Vi=vJiV_i = v_{J_i}, 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 Yi∈RdvY_i \in\mathbb{R}^{d_v} be a random payload satisfying

E[Yi∣Ji=j,qi,K,V]=vj.\mathbb{E}[Y_i \mid J_i = j, q_i, K, V] = v_j.

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

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

E[Yi∣qi,K,V]=∑j∈AiP(Ji=j∣qi,K,V)⋅E[Yi∣Ji=j,qi,K,V].\mathbb{E}[Y_i \mid q_i, K, V] = \sum_{j \in A_i} P(J_i = j \mid q_i, K, V) \cdot\mathbb{E}[Y_i \mid J_i = j, q_i, K, V].

Specifically, we assume

P(Ji=j∣qi,K,V)=P(Ji=j∣qi,K).(5)P(J_i = j \mid q_i, K, V) = P(J_i = j \mid q_i, K). \tag*{(5)}

By the direct specification in § 6.2,

P(Ji=j∣qi,K)=αij.P(J_i = j \mid q_i, K) = \alpha_{ij}.

By the conditional-mean assumption above,

E[Yi∣Ji=j,qi,K,V]=vj.\mathbb{E}[Y_i \mid J_i = j, q_i, K, V] = v_j.

Therefore,

E[Yi∣qi,K,V]=∑j∈Aiαijvj.\mathbb{E}[Y_i \mid q_i, K, V] = \sum_{j \in A_i} \alpha_{ij} v_j.

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,

E[Yi∣qi,K,V]=zi.\mathbb{E}[Y_i \mid q_i, K, V] = z_i.

The source-determined payload as a special case. For Vi=vJiV_i = v_{J_i}, which is random but fully determined once the source and value vectors are given, the same argument gives

E[Vi∣qi,K,V]=∑j∈Aiαijvj=zi.\mathbb{E}[V_i \mid q_i, K, V] = \sum_{j \in A_i} \alpha_{ij} v_j = z_i.

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 KK:

P(Ji=j∣K)=πij.P(J_i = j \mid K) = \pi_{ij}.

The prior satisfies

πij≥0,∑j∈Aiπij=1.\pi_{ij} \ge0,\qquad\sum_{j\in\mathcal{A}_i}\pi_{ij}=1.

A simple initial choice is a uniform prior:

πij=1∣Ai∣.\pi_{ij}=\frac{1}{|\mathcal{A}_i|}.

Other choices can encode source preferences or depend on the keys.

For the observed query qiq_i, specify a conditional density

p(qi∣Ji=j,K).p(q_i\mid J_i=j,K).

Evaluated at that query, it gives the likelihood of each source hypothesis. We use lowercase pp for densities of continuous query distributions and uppercase PP for probabilities of categorical source events. Bayes’ rule gives

P(Ji=j∣qi,K)=p(qi∣Ji=j,K)πij∑r∈Aip(qi∣Ji=r,K)πir.(6)P(J_i=j\mid q_i,K)=\frac{p(q_i\mid J_i=j,K)\pi_{ij}}{\sum_{r\in\mathcal{A}_i}p(q_i\mid J_i=r,K)\pi_{ir}}. \tag*{(6)}

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 ℓij=p(qi∣Ji=j,K)\ell_{ij}=p(q_i\mid J_i=j,K). Rewriting Equation (6) yields

P(Ji=j∣qi,K)=πijℓij∑r∈Aiπirℓir=exp⁡(log⁡πij+log⁡ℓij)∑r∈Aiexp⁡(log⁡πir+log⁡ℓir)=softmax⁡j∈Ai(log⁡πij+log⁡ℓij).\begin{aligned} P(J_i=j\mid q_i,K)&=\frac{\pi_{ij}\ell_{ij}}{\sum_{r\in\mathcal{A}_i}\pi_{ir}\ell_{ir}}\\ &=\frac{\exp(\log\pi_{ij}+\log\ell_{ij})}{\sum_{r\in\mathcal{A}_i}\exp(\log\pi_{ir}+\log\ell_{ir})}\\ &=\operatorname{softmax}_{j\in\mathcal{A}_i}\left(\log\pi_{ij}+\log\ell_{ij}\right). \end{aligned}

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 Rdk\mathbb{R}^{d_k}. Conditional on the latent source variable Ji=jJ_i=j, suppose the query is generated by

qi∣Ji=j,K∼N(kj,σ2I).(7)q_i\mid J_i=j,K\sim\mathcal{N}(k_j,\sigma^2 I). \tag*{(7)}

The key vector kjk_j therefore acts as the mean of the query distribution under hypothesis HijH_{ij}. The covariance is isotropic, Σ=σ2I\Sigma=\sigma^2 I, with the same variance parameter σ2\sigma^2 for every candidate source. The conditional density is

p(qi∣Ji=j,K)=1(2πσ2)dk/2exp⁡(−∥qi−kj∥22σ2).(8)p(q_i\mid J_i=j,K)=\frac{1}{(2\pi\sigma^2)^{d_k/2}}\exp\left(-\frac{\lVert q_i-k_j\rVert^2}{2\sigma^2}\right). \tag*{(8)}

Consequently, a source whose key is closer to the observed query in Euclidean distance (a smaller ∥qi−kj∥\lVert q_i-k_j\rVert) assigns that query a higher likelihood. Combining this likelihood with the source’s prior probability, using Bayes’ rule, gives

P(Ji=j∣qi,K)∝p(qi∣Ji=j,K) πij.P(J_i=j\mid q_i,K)\propto p(q_i\mid J_i=j,K)\,\pi_{ij}.

If the priors πij\pi_{ij} 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

P(Ji=1∣qi,K)=0.40.4+0.2=23,P(Ji=2∣qi,K)=13.P(J_i=1\mid q_i,K)=\frac{0.4}{0.4+0.2}=\frac{2}{3},\qquad P(J_i=2\mid q_i,K)=\frac{1}{3}.

Source 1 receives greater posterior support. But if the prior probabilities are 0.1 and 0.9, the prior-weighted likelihoods become

0.4(0.1)=0.04,0.2(0.9)=0.18.0.4(0.1)=0.04,\qquad0.2(0.9)=0.18.

After normalization, the posterior probabilities are approximately

P(Ji=1∣qi,K)=0.182,P(Ji=2∣qi,K)=0.818.P(J_i=1\mid q_i,K)=0.182,\qquad P(J_i=2\mid q_i,K)=0.818.

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

log⁡p(qi∣Ji=j,K)=−dk2log⁡(2πσ2)−∥qi−kj∥22σ2(9)\log p(q_i\mid J_i=j,K)=-\frac{d_k}{2}\log(2\pi\sigma^2)-\frac{\lVert q_i-k_j\rVert^2}{2\sigma^2} \tag*{(9)}

To make the connection to the query–key dot product explicit, expand the squared distance:

∥qi−kj∥2=∥qi∥2+∥kj∥2−2qi⊤kj.\lVert q_i-k_j\rVert^2=\lVert q_i\rVert^2+\lVert k_j\rVert^2-2q_i^\top k_j.

Substituting into Equation (9) gives

log⁡p(qi∣Ji=j,K)=−∥qi∥22σ2+qi⊤kjσ2−∥kj∥22σ2+C,\log p(q_i\mid J_i=j,K)=-\frac{\lVert q_i\rVert^2}{2\sigma^2}+\frac{q_i^\top k_j}{\sigma^2}-\frac{\lVert k_j\rVert^2}{2\sigma^2}+C,

where C=−dk2log⁡(2πσ2)C=-\frac{d_k}{2}\log(2\pi\sigma^2) is independent of the source jj. For a fixed query, the term involving ∥qi∥2\lVert q_i\rVert^2 is also independent of jj. Combining these terms into cic_i, we obtain

log⁡p(qi∣Ji=j,K)=qi⊤kjσ2−∥kj∥22σ2+ci.(10)\log p(q_i\mid J_i=j,K)=\frac{q_i^\top k_j}{\sigma^2}-\frac{\lVert k_j\rVert^2}{2\sigma^2}+c_i. \tag*{(10)}

The term cic_i depends on the query qiq_i, but does not depend on the candidate source jj. It therefore contributes the same multiplicative factor ecie^{c_i} to every source’s likelihood. The likelihood is

p(qi∣Ji=j,K)=eciexp⁡(qi⊤kjσ2−∥kj∥22σ2).p(q_i\mid J_i=j,K)=e^{c_i}\exp\left(\frac{q_i^\top k_j}{\sigma^2}-\frac{\lVert k_j\rVert^2}{2\sigma^2}\right).

Computing the normalized posterior, using Bayes’ rule, gives

P(Ji=j∣qi,K)=πijeciexp⁡(qiTkjσ2−∥kj∥22σ2)eci∑r∈Aiπirexp⁡(qiTkrσ2−∥kr∥22σ2).(11)P(J_i = j \mid q_i, K) = \frac{\pi_{ij} e^{c_i} \exp\left(\frac{q_i^{\mathsf{T}} k_j}{\sigma^2} - \frac{\lVert k_j\rVert^2}{2\sigma^2}\right)}{e^{c_i} \sum_{r\in A_i} \pi_{ir} \exp\left(\frac{q_i^{\mathsf{T}} k_r}{\sigma^2} - \frac{\lVert k_r\rVert^2}{2\sigma^2}\right)}. \tag*{(11)}

The common factor ecie^{c_i} cancels out, and since the denominator is independent of jj, we can write:

P(Ji=j∣qi,K)=c×πijexp⁡(qiTkjσ2−∥kj∥22σ2),P(J_i = j \mid q_i, K) = c \times\pi_{ij} \exp\left(\frac{q_i^{\mathsf{T}} k_j}{\sigma^2} - \frac{\lVert k_j\rVert^2}{2\sigma^2}\right),

where cc is the reciprocal of the remaining normalization denominator. It is constant across candidate sources jj, though it depends on the given query. We can now state

P(Ji=j∣qi,K)∝πijexp⁡(qiTkjσ2−∥kj∥22σ2).(12)P(J_i = j \mid q_i, K) \propto\pi_{ij} \exp\left(\frac{q_i^{\mathsf{T}} k_j}{\sigma^2} - \frac{\lVert k_j\rVert^2}{2\sigma^2}\right). \tag*{(12)}

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 πir=exp⁡(log⁡πir)\pi_{ir} = \exp(\log\pi_{ir}). Applying this identity in both the numerator and denominator of Equation (11), and cancelling the common factor ecie^{c_i}, expresses the posterior as a softmax with scores

bij=qiTkjσ2−∥kj∥22σ2+log⁡πij.(13)b_{ij} = \frac{q_i^{\mathsf{T}} k_j}{\sigma^2} - \frac{\lVert k_j\rVert^2}{2\sigma^2} + \log\pi_{ij}. \tag*{(13)}

The posterior therefore becomes

P(Ji=j∣qi,K)=softmax⁡j∈Ai(bij).(14)P(J_i = j \mid q_i, K) = \operatorname{softmax}_{j\in A_i}(b_{ij}). \tag*{(14)}

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 πij\pi_{ij} are uniform, all candidate keys have equal Euclidean norm, and the variance parameter satisfies

σ2=dk.(15)\sigma^2 = \sqrt{d_k}. \tag*{(15)}

Because the priors are uniform, log⁡πij\log\pi_{ij} is constant across jj. Because the key norms are equal, the term −∥kj∥22σ2-\frac{\lVert k_j\rVert^2}{2\sigma^2} is also constant across jj. And since both terms disappear under softmax normalization, Equation (14) therefore reduces to

P(Ji=j∣qi,K)=exp⁡(qiTkj/dk)∑r∈Aiexp⁡(qiTkr/dk).(16)P(J_i = j \mid q_i, K) = \frac{\exp\left(q_i^{\mathsf{T}} k_j / \sqrt{d_k}\right)}{\sum_{r\in A_i} \exp\left(q_i^{\mathsf{T}} k_r / \sqrt{d_k}\right)}. \tag*{(16)}

But the right-hand side is precisely the standard attention weight αij\alpha_{ij}.

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

πij=P(Ji=j∣K)=exp⁡(∥kj∥2/(2σ2))∑r∈Aiexp⁡(∥kr∥2/(2σ2)).\pi_{ij}=P(J_i=j\mid K)=\frac{\exp(\lVert k_j\rVert^2/(2\sigma^2))}{\sum_{r\in A_i}\exp(\lVert k_r\rVert^2/(2\sigma^2))}.

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

Ci(K)=∑r∈Aiexp⁡(∥kr∥2/(2σ2)).C_i(K)=\sum_{r\in A_i}\exp(\lVert k_r\rVert^2/(2\sigma^2)).

Substituting the logarithm of πij\pi_{ij} into Equation (13) gives

bij=qiTkjσ2−∥kj∥22σ2+∥kj∥22σ2−log⁡Ci(K)=qiTkjσ2−log⁡Ci(K).\begin{aligned} b_{ij}&=\frac{q_i^\mathsf{T}k_j}{\sigma^2}-\frac{\lVert k_j\rVert^2}{2\sigma^2}+\frac{\lVert k_j\rVert^2}{2\sigma^2}-\log C_i(K)\\ &=\frac{q_i^\mathsf{T}k_j}{\sigma^2}-\log C_i(K). \end{aligned}

The key-norm terms cancel, and the remaining term −log⁡Ci(K)-\log C_i(K) is constant across candidate sources. Therefore,

P(Ji=j∣qi,K)=softmax⁡j∈Ai(qiTkjσ2).P(J_i=j\mid q_i,K)=\operatorname{softmax}_{j\in A_i}\left(\frac{q_i^\mathsf{T}k_j}{\sigma^2}\right).

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, πij=1/∣Ai∣\pi_{ij}=1/\lvert A_i\rvert, 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 AiA_i, with finite key vectors and σ2=dk\sigma^2=\sqrt{d_k}. Suppose the source prior satisfies

log⁡πij−∥kj∥22σ2=ci(K)for all j∈Ai,\log\pi_{ij}-\frac{\lVert k_j\rVert^2}{2\sigma^2}=c_i(K)\qquad\text{for all }j\in A_i,

where ci(K)c_i(K) is independent of jj. Equivalently, choose

πij=exp⁡(∥kj∥2/(2σ2))∑r∈Aiexp⁡(∥kr∥2/(2σ2)).\pi_{ij}=\frac{\exp(\lVert k_j\rVert^2/(2\sigma^2))}{\sum_{r\in A_i}\exp(\lVert k_r\rVert^2/(2\sigma^2))}.

Then the standard scaled dot-product attention weights are exactly the posterior probabilities of the latent source variable:

P(Ji=j∣qi,K)=αij.P(J_i=j\mid q_i,K)=\alpha_{ij}.

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:

vj=E[Yi∣Ji=j,qi,K,V].v_j = \mathbb{E}[Y_i \mid J_i = j, q_i, K, V].

The information supplied by source jj need not always equal vjv_j; the payload may vary while retaining that average. Under Proposition 1 and the conditioning assumption in Equation (5), P(Ji=j∣qi,K,V)=αijP(J_i = j \mid q_i, K, V) = \alpha_{ij}. The law of total expectation first averages conditional payload means over the possible sources:

E[Yi∣qi,K,V]=∑j∈AiP(Ji=j∣qi,K,V)E[Yi∣Ji=j,qi,K,V]=∑j∈Aiαijvj=zi.\begin{aligned} \mathbb{E}[Y_i \mid q_i, K, V] &= \sum_{j \in\mathcal{A}_i} P(J_i = j \mid q_i, K, V)\mathbb{E}[Y_i \mid J_i = j, q_i, K, V] \\ &= \sum_{j \in\mathcal{A}_i} \alpha_{ij}v_j \\ &= z_i. \end{aligned}

Hence

∑j∈Aiαijvj⏟attention output=E[Yi∣qi,K,V]⏟posterior mean.\underbrace{\sum_{j \in\mathcal{A}_i} \alpha_{ij}v_j}_{\text{attention output}} = \underbrace{\mathbb{E}[Y_i \mid q_i, K, V]}_{\text{posterior mean}}.

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 kjk_j, supplies the likelihood used to infer the source. A second Gaussian distribution, centered at vjv_j, models the payload associated with that source:

Yi∣Ji=j,K,V∼N(vj,τ2I).(17)Y_i \mid J_i = j, K, V \sim\mathcal{N}(v_j, \tau^2 I). \tag*{(17)}

Here V=(v1,…,vt)V = (v_1, \ldots, v_t). This distribution gives E[Yi∣Ji=j,K,V]=vj\mathbb{E}[Y_i \mid J_i = j, K, V] = v_j, 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:

Yi⊥qi∣Ji,K,V.(18)Y_i \perp q_i \mid J_i, K, V. \tag*{(18)}

Together, these assumptions give

E[Yi∣Ji=j,qi,K,V]=vj.(19)\mathbb{E}[Y_i \mid J_i = j, q_i, K, V] = v_j. \tag*{(19)}

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 vjv_j, 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, E[∣Yi∣2∣qi,K,V]\mathbb{E}[|Y_i|^2 \mid q_i, K, V] 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 σ2=dk\sigma^2 = \sqrt{d_k} 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 VV, 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:

Attention⁡(qi,K,V)=E[Yi∣qi,K,V].\operatorname{Attention}(q_i, K, V) = \mathbb{E}[Y_i \mid q_i, K, V].

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 a∈Rdva \in\mathbb{R}^{d_v} be any estimator of YiY_i based on the available evidence. Define the conditional risk; that is, the expected squared estimation error given the query, keys, and values, by

R(a)=E[∥Yi−a∥2∣qi,K,V].\mathcal{R}(a) = \mathbb{E}[\lVert Y_i - a \rVert^2 \mid q_i, K, V].

Given this query, these keys, and these values, how much squared error should we expect if we estimate the payload by aa?

Let

mi=E[Yi∣qi,K,V].m_i = \mathbb{E}[Y_i \mid q_i, K, V].

Using

Yi−a=(Yi−mi)+(mi−a)Y_i - a = (Y_i - m_i) + (m_i - a)

and expanding, we obtain

R(a)=E[∥Yi−mi∥2∣qi,K,V]+∥mi−a∥2+2E[(Yi−mi)⊤(mi−a)∣qi,K,V].\begin{aligned} \mathcal{R}(a) ={}& \mathbb{E}[\lVert Y_i - m_i \rVert^2 \mid q_i, K, V] \\ &+ \lVert m_i - a \rVert^2 \\ &+ 2\mathbb{E}[(Y_i - m_i)^\top(m_i - a) \mid q_i, K, V]. \end{aligned}

Because

E[Yi−mi∣qi,K,V]=0,\mathbb{E}[Y_i - m_i \mid q_i, K, V] = 0,

We have

R(a)=R(mi)+∥mi−a∥2.\mathcal{R}(a)=\mathcal{R}(m_i)+\lVert m_i-a\rVert^2.

The risk is minimized when

a=mi.a=m_i.

§ 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

a∗=zi.a^*=z_i.

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 YiY_i 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 GG be a downstream prediction function, let CC denote the conditioning context, and let JJ follow the conditional source probabilities. In general,

G(E[vJ∣C])≠E[G(vJ)∣C].G(\mathbb{E}[v_J \mid C]) \ne\mathbb{E}[G(v_J) \mid C].

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 G(zi)G(z_i) 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 JJ,

P(Xt+1=a∣C)=∑jP(J=j∣C)P(Xt+1=a∣J=j,C).P(X_{t+1}=a \mid C)=\sum_j P(J=j \mid C)P(X_{t+1}=a \mid J=j,C).

This can be described as “apply GG first, then average,” provided G(vj)G(v_j) gives the source-conditional outcome distribution:

[G(vj)]a=P(Xt+1=a∣J=j,C)for every token a.[G(v_j)]_a=P(X_{t+1}=a \mid J=j,C) \quad\text{for every token }a.

Under this assumption, and with the corresponding posterior source weights from the same model, the predictive distribution is

∑jP(J=j∣C)G(vj)=E[G(vJ)∣C].\sum_j P(J=j \mid C)G(v_j)=\mathbb{E}[G(v_J) \mid C].

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 ziz_i itself is the full predictive distribution and GG can be the identity.

For a simple numerical example, take two equally probable scalar values,

v1=−1,v2=1,v_1=-1,\qquad v_2=1,

and the nonlinear transformation G(v)=v2G(v)=v^2. Averaging first gives

E[vJ∣C]=12(−1)+12(1)=0,G(E[vJ∣C])=0.\mathbb{E}[v_J \mid C]=\frac{1}{2}(-1)+\frac{1}{2}(1)=0,\qquad G(\mathbb{E}[v_J \mid C])=0.

Applying the transformation first instead gives

E[G(vJ)∣C]=12(−1)2+12(1)2=1.\mathbb{E}[G(v_J)\mid C]=\frac{1}{2}(-1)^2+\frac{1}{2}(1)^2=1.

Second-moment information matters here specifically because G(v)=v2G(v)=v^2: averaging the transformed values gives E[vJ2∣C]\mathbb{E}[v_J^2\mid C], the conditional second raw moment, whereas transforming the mean gives (E[vJ∣C])2(\mathbb{E}[v_J\mid C])^2. Their difference is the conditional variance:

E[vJ2∣C]−(E[vJ∣C])2=Var⁡(vJ∣C).\mathbb{E}[v_J^2\mid C]-(\mathbb{E}[v_J\mid C])^2=\operatorname{Var}(v_J\mid C).

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 ii, the outputs of the different heads are concatenated. Writing each head output as a column vector, the combined representation before output projection is

si=[zi(1)⋮zi(m)],s_i= \begin{bmatrix} z_i^{(1)}\\ \vdots\\ z_i^{(m)} \end{bmatrix},

with projected output WO⊤siW_O^\top s_i 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: zi(r)=E[Yi(r)∣Qi(r),K(r),V(r)]z_i^{(r)}=\mathbb{E}[Y_i^{(r)}\mid Q_i^{(r)},K^{(r)},V^{(r)}]. To interpret all concatenated outputs as one joint posterior mean, a compatible joint model and common conditioning information CC are needed. If such a model satisfies zi(r)=E[Yi(r)∣C]z_i^{(r)}=\mathbb{E}[Y_i^{(r)}\mid C] for every head, then stacking the payloads into Yi\mathbf{Y}_i gives si=E[Yi∣C]s_i=\mathbb{E}[\mathbf{Y}_i\mid C] by linearity.

Even under this common-conditioning assumption, a nonlinear downstream prediction function GG, including the output projection and subsequent computations as appropriate, need not satisfy

G(si)=G(E[Yi∣C])=E[G(Yi)∣C].G(s_i)=G(\mathbb{E}[\mathbf{Y}_i\mid C])=\mathbb{E}[G(\mathbf{Y}_i)\mid C].

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 pp be the true posterior distribution over accessible sources and p^\hat{p} an approximation to it. We examine how replacing pp by p^\hat{p}, while keeping the value vectors unchanged, affects the aggregated output.

Let the true posterior source probabilities be

pj=P(Ji=j∣qi,K),p_j = P(J_i = j \mid q_i, K),

and let their attention-based approximations be

p^j.\hat{p}_j.

Suppose the value vectors satisfy

∥vj∥≤Bfor every j.(20)\lVert v_j \rVert\le B \qquad\text{for every } j. \tag*{(20)}

The true posterior mean is

m=∑jpjvj.m = \sum_j p_j v_j.

The approximate attention output is

m^=∑jp^jv^j.\hat{m} = \sum_j \hat{p}_j \hat{v}_j.

We can bound the resulting approximation error as follows.

Proposition 2. Stability of attention-based posterior expectations

Under Equation (20),

∥m^−m∥≤2BDTV(p,p^),\lVert\hat{m} - m \rVert\le2B D_{\mathrm{TV}}(p,\hat{p}),

Here, total variation distance DTV(p,p^)D_{\mathrm{TV}}(p,\hat{p}) 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:

m^−m=∑j(p^j−pj)vj.\hat{m} - m = \sum_j (\hat{p}_j - p_j)v_j.

Apply the triangle inequality:

∥m^−m∥≤∑j∣p^j−pj∣∥vj∥.\lVert\hat{m} - m \rVert\leq\sum_j \lvert\hat{p}_j - p_j\rvert\lVert v_j\rVert.

Using ∥vj∥≤B\lVert v_j\rVert\leq B,

∥m^−m∥≤B∑j∣p^j−pj∣.\lVert\hat{m} - m \rVert\leq B \sum_j \lvert\hat{p}_j - p_j\rvert.

Using the standard identity for total variation distance [9],

DTV(p,p^)=12∑j∣pj−p^j∣,D_{\mathrm{TV}}(p,\hat{p}) = \frac{1}{2}\sum_j \lvert p_j-\hat{p}_j\rvert,

we obtain

∥m^−m∥≤2B DTV(p,p^).\lVert\hat{m} - m \rVert\leq2B\,D_{\mathrm{TV}}(p,\hat{p}).

This proves the proposition. □

Using natural logarithms, Kullback–Leibler divergence is defined by

DKL(p∥p^)=∑j:pj>0pjln⁡pjp^j.D_{\mathrm{KL}}(p\Vert\hat{p}) = \sum_{j:p_j>0} p_j \ln\frac{p_j}{\hat{p}_j}.

It computes the expected additional log loss from using the approximate source probabilities p^\hat{p} when the true source probabilities are pp. The divergence is zero when the distributions agree and positive otherwise. If p^j=0\hat{p}_j = 0 for a source with pj>0p_j > 0, the divergence is infinite.

Pinsker’s inequality [4], expressed using natural logarithms, gives

DTV(p,p^)≤12DKL(p∥p^).D_{\mathrm{TV}}(p,\hat{p}) \leq\sqrt{\frac{1}{2}D_{\mathrm{KL}}(p\Vert\hat{p})}.

Combining this with Proposition 2 yields

∥m^−m∥≤B2DKL(p∥p^).\lVert\hat{m} - m \rVert\leq B\sqrt{2D_{\mathrm{KL}}(p\Vert\hat{p})}.

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

S=T(X).S = T(X).

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, SS is sufficient for a parameter θ\theta if the conditional distribution of XX given SS does not depend on θ\theta. Once the statistic is known, the remaining details of the observations provide no additional information about that parameter.

A statistic S=T(X)S = T(X) 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

St=Φ(X1:t)S_t = \Phi(X_{1:t})

is predictively sufficient when

P(Xt+1∣X1:t)=P(Xt+1∣St).P(X_{t+1} \mid X_{1:t}) = P(X_{t+1} \mid S_t).

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 {A,B}\{A, B\}. 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:

P(H1)=P(H2)=12.P(H_1) = P(H_2) = \frac{1}{2}.

Suppose that their conditional symbol probabilities are

H1:P(A∣H1)=0.8,P(B∣H1)=0.2,H2:P(A∣H2)=0.2,P(B∣H2)=0.8.\begin{aligned} H_1 &: \quad P(A \mid H_1) = 0.8, \quad P(B \mid H_1) = 0.2, \\ H_2 &: \quad P(A \mid H_2) = 0.2, \quad P(B \mid H_2) = 0.8. \end{aligned}

An intuitive analogy is to choose one of two biased coins at random and repeatedly toss that same coin. The first favors AA, while the second favors BB.

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,

P(AAB∣H1)=0.8×0.8×0.2=0.128,P(AAB∣H2)=0.2×0.2×0.8=0.032.P(AAB \mid H_1) = 0.8 \times0.8 \times0.2 = 0.128,\quad P(AAB \mid H_2) = 0.2 \times0.2 \times0.8 = 0.032.

The observed sequence AABAAB is four times as likely under H1H_1. Bayes’ rule, with equal priors, gives

P(H1∣AAB)=(1/2)(0.128)(1/2)(0.128)+(1/2)(0.032)=0.8,P(H2∣AAB)=0.2.P(H_1 \mid AAB) = \frac{(1/2)(0.128)}{(1/2)(0.128) + (1/2)(0.032)} = 0.8,\quad P(H_2 \mid AAB) = 0.2.

The next-symbol prediction averages the two rules using these posterior probabilities:

P(X4=A∣AAB)=0.8(0.8)+0.2(0.2)=0.68.P(X_4 = A \mid AAB) = 0.8(0.8) + 0.2(0.2) = 0.68.

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 AA, averaged over the two equally likely hypotheses, is 0.50.5, but observing one AA raises the posterior probability of H1H_1 to 0.80.8 and the probability of another AA to 0.680.68. Neither generating rule assigns AA probability 0.50.5: one assigns 0.80.8, the other 0.20.2. The value 0.50.5 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

NA(t)=∑i=1t1{Xi=A},N_A(t) = \sum_{i=1}^{t} \mathbf{1}\{X_i = A\},
NB(t)=t−NA(t).N_B(t) = t - N_A(t).

With equal hypothesis priors, the posterior odds are

P(H1∣X1:t)P(H2∣X1:t)=0.8NA(t)0.2NB(t)0.2NA(t)0.8NB(t).\frac{P(H_1 \mid X_{1:t})}{P(H_2 \mid X_{1:t})} = \frac{0.8^{N_A(t)}0.2^{N_B(t)}}{0.2^{N_A(t)}0.8^{N_B(t)}}.

Taking logarithms gives

log⁡P(H1∣X1:t)P(H2∣X1:t)=(NA(t)−NB(t))log⁡4.\log\frac{P(H_1 \mid X_{1:t})}{P(H_2 \mid X_{1:t})} = \left(N_A(t)-N_B(t)\right)\log4.

Thus, the complete posterior can be recovered from the single number

St=NA(t)−NB(t).S_t=N_A(t)-N_B(t).

Writing s=NA(t)−NB(t)s=N_A(t)-N_B(t), the posterior probability of H1H_1 is 4s/(1+4s)4^s/(1+4^s). Consequently,

P(Xt+1=A∣X1:t)=0.84s1+4s+0.211+4s.P(X_{t+1}=A\mid X_{1:t})=0.8\frac{4^s}{1+4^s}+0.2\frac{1}{1+4^s}.

For the sequence AABAAB, s=2−1=1s=2-1=1, 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, St=NA(t)−NB(t)S_t=N_A(t)-N_B(t) 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 θ\theta fixed, write the Transformer’s representation and predictor as

Stθ=Φθ(X1:t),P^θ(⋅∣X1:t)=Gθ(Stθ),S_t^\theta=\Phi_\theta(X_{1:t}),\qquad\widehat{P}_\theta(\cdot\mid X_{1:t})=G_\theta(S_t^\theta),

where Φθ\Phi_\theta includes attention layers and GθG_\theta 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

DKL(P∗(⋅∣X1:t)∥Gθ(Stθ))≤ε,(21)D_{\mathrm{KL}}\left(P^*(\cdot\mid X_{1:t})\mathrel{\|}G_\theta(S_t^\theta)\right)\leq\varepsilon, \tag*{(21)}

where P∗P^* is the true next-token distribution and ε\varepsilon 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 C=X1:tC=X_{1:t} be the context, JJ a categorical latent source with finite source set A\mathcal{A}, and X\mathcal{X} the finite vocabulary. Suppose

vj(a;C)=P(Xt+1=a∣J=j,C),αj(C)=P(J=j∣C).v_j(a;C)=P(X_{t+1}=a\mid J=j,C),\qquad\alpha_j(C)=P(J=j\mid C).

The component vj(a;C)v_j(a;C) corresponds to token aa; the full vector vj(⋅;C)v_j(\cdot;C) has nonnegative components summing to one. The law of total probability gives

z(a;C)=∑j∈Aαj(C)vj(a;C)=P(Xt+1=a∣C),a∈X.z(a;C)=\sum_{j\in\mathcal{A}}\alpha_j(C)v_j(a;C)=P(X_{t+1}=a\mid C),\qquad a\in\mathcal{X}.

Under these additional assumptions, the posterior-weighted mean z(⋅;C)z(\cdot; C) contains the full next-token distribution and is predictively sufficient; an identity prediction head suffices.

For example, two sources with values

v1=(0.8,0.1,0.1)T,v2=(0.2,0.3,0.5)Tv_1 = (0.8, 0.1, 0.1)^{\mathsf{T}}, \qquad v_2 = (0.2, 0.3, 0.5)^{\mathsf{T}}

and posterior weights 0.75 and 0.25 produce

z=0.75v1+0.25v2=(0.65,0.15,0.20)T.z = 0.75v_1 + 0.25v_2 = (0.65, 0.15, 0.20)^{\mathsf{T}}.

All three token probabilities are retained.

To connect this construction to conditional-mean estimation, let TT be the random one-hot indicator of the next token: Ta=1T_a = 1 if token aa occurs and 0 otherwise. Unlike TT, V=(vj(⋅;C))j∈AV = (v_j(\cdot; C))_{j \in\mathcal{A}} is the collection of value vectors, given for a fixed context and fixed parameters. A realization of TT identifies one outcome; each value vector describes probabilities over outcomes under a source hypothesis. Consequently,

vj(⋅;C)=E[T∣J=j,C],z(⋅;C)=E[T∣C].v_j(\cdot; C) = \mathbb{E}[T \mid J = j, C], \qquad z(\cdot; C) = \mathbb{E}[T \mid C].

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 YiY_i to a prediction-specific payload TT.

The example also replaces conditioning on qiq_i, KK, VV with conditioning on the full context CC. Applying it to ordinary attention would require the contextual token representations hjh_j to retain enough information, and the learned projections producing qiq_i, kjk_j, and vjv_j 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 St=Φ(X1:t)S_t = \Phi(X_{1:t}), with learned parameters held fixed. Define

pt∗(⋅)=P(Xt+1=⋅∣X1:t),p_t^*(\cdot) = P(X_{t+1} = \cdot\mid X_{1:t}),
ptS(⋅)=P(Xt+1=⋅∣St),p_t^S(\cdot) = P(X_{t+1} = \cdot\mid S_t),
p^t(⋅)=Gθ(St).\hat{p}_t(\cdot) = G_\theta(S_t).

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

Using a predictive distribution qq incurs log loss −ln⁡q(a)-\ln q(a) when token aa occurs. If the true conditional distribution is pp, the expected additional log loss from using qq rather than pp is DKL(p∥q)D_{\mathrm{KL}}(p \mathbin{\Vert} q). Throughout this subsection, we use natural logarithms.

Two levels of averaging. For a fixed context cc, let pcp_c and p^c\hat{p}_c be its true and predicted next-token distributions. KL divergence averages over next tokens; the outer expectation then averages over contexts:

E[DKL(pt∗∥p^t)]=∑cP(X1:t=c)∑a:pc(a)>0pc(a)ln⁡pc(a)p^c(a).\mathbb{E}[D_{\mathrm{KL}(p_t^* \mathbin{\Vert} \hat{p}_t)}] = \sum_c P(X_{1:t} = c) \sum_{a:p_c(a)>0} p_c(a) \ln\frac{p_c(a)}{\hat{p}_c(a)}.

The following decomposition, presented by Silva et al. [11], separates the two sources of excess loss:

E[DKL(pt∗∥p^t)]=I(Xt+1;X1:t∣St)+E[DKL(ptS∥p^t)].(22)\begin{aligned} \mathbb{E}[D_{\mathrm{KL}(p_t^* \mathbin{\Vert} \hat{p}_t)}] &= I(X_{t+1}; X_{1:t} \mid S_t) + \mathbb{E}[D_{\mathrm{KL}(p_t^S \mathbin{\Vert} \hat{p}_t)}]. \tag*{(22)} \end{aligned}

Here, we apply it with the full context X1:tX_{1:t} as input, the next token Xt+1X_{t+1} as target, and the attention-based representation StS_t 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,

I(Xt+1;X1:t∣St)=E[DKL(pt∗∥ptS)].I(X_{t+1}; X_{1:t} \mid S_t) = \mathbb{E}\left[D_{\mathrm{KL}}(p^*_{t} \mathbin\Vert p^{S}_{t})\right].

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 p1=(0.9,0.1)p_1 = (0.9, 0.1) and p2=(0.1,0.9)p_2 = (0.1, 0.9), but map to the same summary. Its ideal predictor must average the two distributions:

pS=12p1+12p2=(0.5,0.5).p^S = \frac{1}{2}p_1 + \frac{1}{2}p_2 = (0.5, 0.5).

Representation loss averages the divergence from each full-context distribution to this summary-based predictor:

I(Xt+1;X1:t∣St)=12DKL(p1∥pS)+12DKL(p2∥pS).I(X_{t+1}; X_{1:t} \mid S_t) = \frac{1}{2}D_{\mathrm{KL}}(p_1 \mathbin\Vert p^S) + \frac{1}{2}D_{\mathrm{KL}}(p_2 \mathbin\Vert p^S).

For the first context,

DKL(p1∥pS)=0.9ln⁡0.90.5+0.1ln⁡0.10.5=0.9ln⁡(1.8)+0.1ln⁡(0.2)≈0.368 nats.\begin{aligned} D_{\mathrm{KL}}(p_1 \mathbin\Vert p^S) &= 0.9 \ln\frac{0.9}{0.5} + 0.1 \ln\frac{0.1}{0.5} \\ &= 0.9 \ln(1.8) + 0.1 \ln(0.2) \\ &\approx0.368\ \text{nats}. \end{aligned}

For the second context, the two contributions appear in the opposite order:

DKL(p2∥pS)=0.1ln⁡(0.2)+0.9ln⁡(1.8)=DKL(p1∥pS).D_{\mathrm{KL}}(p_2 \mathbin\Vert p^S) = 0.1\ln(0.2) + 0.9\ln(1.8) = D_{\mathrm{KL}}(p_1 \mathbin\Vert p^S).

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 (0.6,0.4)(0.6, 0.4), it adds

DKL((0.5,0.5)∥(0.6,0.4))≈0.0204 nats,D_{\mathrm{KL}}((0.5, 0.5) \mathbin\Vert(0.6, 0.4)) \approx0.0204\ \text{nats},

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 ∥vj∥≤B\lVert v_j\rVert\le B. Let pJ=(pJ,j)j∈Aip_J=(p_{J,j})_{j\in A_i} be the exact source-probability vector and p^J\widehat{p}_J an approximation, where

pJ,j=P(Ji=j∣qi,K),m=∑jpJ,jvj,m^=∑jp^J,jvj.p_{J,j}=P(J_i=j\mid q_i,K),\qquad m=\sum_j p_{J,j}v_j,\qquad\widehat{m}=\sum_j \widehat{p}_{J,j}v_j.

The subscript JJ distinguishes source probabilities from output-token probabilities; jj identifies one component. Under the exact Bayesian correspondence, attention weights satisfy αij=pJ,j\alpha_{ij}=p_{J,j}; approximate attention weights play the role of p^J,j\widehat{p}_{J,j}.

Suppose the fixed prediction head GG is LGL_G-Lipschitz; that is, there exists a finite constant LG≥0L_G\ge0 such that, for all input representations uu and vv in the domain under consideration,

∥G(u)−G(v)∥≤LG∥u−v∥.\lVert G(u)-G(v)\rVert\le L_G\lVert u-v\rVert.

This bounds its sensitivity: an input change cannot be amplified by more than LGL_G in the output. For example, LG=2L_G=2 turns an input difference of 0.01 into an output difference of at most 0.02. Writing pout=G(m)p_{\mathrm{out}}=G(m) and p^out=G(m^)\widehat{p}_{\mathrm{out}}=G(\widehat{m}), we obtain

∥p^out−pout∥≤LG∥m^−m∥≤2LGBDTV(pJ,p^J)≤LGB2DKL(pJ∥p^J).\begin{aligned} \lVert\widehat{p}_{\mathrm{out}}-p_{\mathrm{out}}\rVert&\le L_G\lVert\widehat{m}-m\rVert\\ &\le2L_GB D_{\mathrm{TV}}(p_J,\widehat{p}_J)\\ &\le L_GB\sqrt{2D_{\mathrm{KL}}(p_J\mathbin\Vert\widehat{p}_J)}. \end{aligned}

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, I(St;Xt+1)I(S_t;X_{t+1}) measures how informative the summary is about the next token. It is symmetric, and is zero exactly when the variables are independent. For St=Φ(X1:t)S_t=\Phi(X_{1:t}), an idealized bottleneck objective is

min⁡Φ[I(St;X1:t)−βI(St;Xt+1)].(23)\min_{\Phi}\left[I(S_t;X_{1:t})-\beta I(S_t;X_{t+1})\right]. \tag*{(23)}

The term “bottleneck” describes the summary as a restricted passage through which context information must reach the predictor:

X1:t⟶St⟶prediction.X_{1:t}\longrightarrow S_t\longrightarrow\text{prediction}.

The predictor receives the context only through StS_t. 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 Φ\Phi that balances compression against predictive usefulness. The first term, I(St;X1:t)I(S_t;X_{1:t}), measures how much knowing the summary tells us about the original context X1:t=(X1,…,Xt)X_{1:t}=(X_1,\ldots,X_t). 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 AABAAB, ABAABA, and BAABAA to the same value, discarding their order. Minimizing this term encourages removing such distinctions when they are unnecessary for prediction. The second term, I(St;Xt+1)I(S_t; X_{t+1}), 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 P(Xt+1)P(X_{t+1}); with it, the predictor uses P(Xt+1∣St)P(X_{t+1} \mid S_t). The expected improvement is

I(St;Xt+1)=ESt[DKL(P(Xt+1∣St)∥P(Xt+1))].I(S_t; X_{t+1}) = \mathbb{E}_{S_t}\left[D_{\mathrm{KL}}\left(P(X_{t+1} \mid S_t) \mathbin{\|} P(X_{t+1})\right)\right].

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 β≥0\beta\ge0 sets the relative importance of the two terms. A small β\beta favors compression, potentially sacrificing predictive information; a large β\beta places more emphasis on next-token information, potentially retaining more of the context.

We recall the chain rule for mutual information: for random variables AA, BB, CC,

I(A;B,C)=I(A;B)+I(A;C∣B).I(A; B, C) = I(A; B) + I(A; C \mid B).

The information supplied by BB and CC together about AA equals the information supplied by BB, plus the additional information supplied by CC once BB is known. Reversing the order gives

I(A;B,C)=I(A;C)+I(A;B∣C).I(A; B, C) = I(A; C) + I(A; B \mid C).

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 St=Φ(X1:t)S_t = \Phi(X_{1:t}) is determined by the context, adding it to the full context supplies no new information:

I(Xt+1;X1:t,St)=I(Xt+1;X1:t).I(X_{t+1}; X_{1:t}, S_t) = I(X_{t+1}; X_{1:t}).

The chain rule expresses the same quantity by first revealing the summary and then revealing the full context:

I(Xt+1;St,X1:t)=I(Xt+1;St)+I(Xt+1;X1:t∣St).I(X_{t+1}; S_t, X_{1:t}) = I(X_{t+1}; S_t) + I(X_{t+1}; X_{1:t} \mid S_t).

Combining these identities gives

I(Xt+1;X1:t)⏟full-context predictive information=I(Xt+1;St)⏟retained predictive information+I(Xt+1;X1:t∣St)⏟representation loss.\underbrace{I(X_{t+1}; X_{1:t})}_{\text{full-context predictive information}} = \underbrace{I(X_{t+1}; S_t)}_{\text{retained predictive information}} + \underbrace{I(X_{t+1}; X_{1:t} \mid S_t)}_{\text{representation loss}}.

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,

I(Xt+1;X1:t∣St)=E[DKL(pt∗∥ptS)].I(X_{t+1}; X_{1:t} \mid S_t) = \mathbb{E}\left[D_{\mathrm{KL}}\left(p_t^* \mathbin{\|} p_t^S\right)\right].

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 I(St;Xt+1)=I(X1:t;Xt+1)I(S_t; X_{t+1}) = I(X_{1:t}; X_{t+1}). The bottleneck objective balances compression against this preservation requirement.

In § 7.2, the count difference NA−NBN_A - N_B 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 (m=1m = 1), combine it with an additional predictor-approximation assumption, and apply the decomposition in § 7.4.

Fix a context length nn. Let the sequence follow a computable probability measure μ\mu on a finite alphabet X\mathcal{X}, and let Sn=Φ(X1:n)S_n = \Phi(X_{1:n}) be a deterministic attention-based representation with learned parameters fixed. A normalized predictor r(a∣Sn)r(a \mid S_n) assigns probabilities to the next token a∈Xa \in\mathcal{X}, using the context only through this representation. All logarithms and information quantities in this subsection use base 2.

Here, uppercase XiX_i denotes the random token at position ii, while lowercase xix_i denotes a particular observed value. Thus X1:n=(X1,…,Xn)X_{1:n} = (X_1,\ldots,X_n) is the random context and x=x1:n=(x1,…,xn)x = x_{1:n} = (x_1,\ldots,x_n) is an observed context. The bound involving B(x)B(x) below applies to a fixed observed context; EX1:n\mathbb{E}_{X_{1:n}} subsequently averages over possible contexts according to their probabilities under μ\mu.

The full-context result for one token. For an observed context x=x1:nx = x_{1:n} with μ(x)>0\mu(x) > 0, Theorem 1 of Chernov et al. [3], applied to a one-token continuation aa, gives

log⁡2μ(a∣x)M(a∣x)≤K(μ∣x)+K(n)+c0=:B(x)\log_2 \frac{\mu(a \mid x)}{M(a \mid x)} \le K(\mu\mid x) + K(n) + c_0 =: B(x)

whenever μ(a∣x)>0\mu(a \mid x) > 0. Here K(μ∣x)K(\mu\mid x) describes a shortest self-delimiting procedure computing μ\mu given xx, K(n)K(n) describes the context length, and c0c_0 is a reference-machine constant independent of xx, aa, μ\mu. The Solomonoff next-token weight is M(a∣x)=M(xa)/M(x)M(a \mid x) = M(xa)/M(x). Averaging over the next token bounds the ideal full-context predictor’s expected additional log loss by B(x)B(x).

The additional approximation requirement. Suppose a nonnegative penalty η(x)\eta(x) satisfies

r(a∣Φ(x))≥2−η(x)M(a∣x)r(a \mid\Phi(x)) \ge2^{-\eta(x)} M(a \mid x)

for every context of positive μ\mu-probability and every token with μ(a∣x)>0\mu(a \mid x) > 0. This limits the representation-based predictor’s additional log loss relative to MM, uniformly over those tokens. For example, η(x)=1\eta(x) = 1 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 rr is

ηr(x)=max⁡{0,max⁡a:μ(a∣x)>0log⁡2M(a∣x)r(a∣Φ(x))},\eta_r(x) = \max\left\{0,\max_{a:\mu(a\mid x)>0}\log_2\frac{M(a\mid x)}{r(a\mid\Phi(x))}\right\},

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

log⁡2μ(a∣x)M(a∣x)≤B(x),log⁡2M(a∣x)r(a∣Φ(x))≤η(x).\log_{2}\frac{\mu(a \mid x)}{M(a \mid x)} \le B(x), \qquad\log_{2}\frac{M(a \mid x)}{r(a \mid\Phi(x))} \le\eta(x).

Splitting the true-to-predicted log ratio at MM combines these bounds:

log⁡2μ(a∣x)r(a∣Φ(x))=log⁡2μ(a∣x)M(a∣x)+log⁡2M(a∣x)r(a∣Φ(x))≤B(x)+η(x).\begin{aligned} \log_{2}\frac{\mu(a \mid x)}{r(a \mid\Phi(x))} = \log_{2}\frac{\mu(a \mid x)}{M(a \mid x)} + \log_{2}\frac{M(a \mid x)}{r(a \mid\Phi(x))} \\ &\le B(x) + \eta(x). \end{aligned}

Next, we average over possible next tokens by multiplying by μ(a∣x)\mu(a \mid x) and summing:

DKL(μ(⋅∣x)∥r(⋅∣Φ(x)))=∑a:μ(a∣x)>0μ(a∣x)log⁡2μ(a∣x)r(a∣Φ(x))≤B(x)+η(x).\begin{aligned} D_{\mathrm{KL}}\bigl(\mu(\cdot\mid x) \mathbin{\|} r(\cdot\mid\Phi(x))\bigr) = \sum_{a:\mu(a \mid x)>0} \mu(a \mid x)\log_{2}\frac{\mu(a \mid x)}{r(a \mid\Phi(x))} \\ &\le B(x) + \eta(x). \end{aligned}

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 μ\mu, with Sn=Φ(X1:n)S_n = \Phi(X_{1:n}):

EX1:nDKL(μ(⋅∣X1:n)∥r(⋅∣Sn))≤EX1:n[B(X1:n)+η(X1:n)].\mathbb{E}_{X_{1:n}}D_{\mathrm{KL}}\bigl(\mu(\cdot\mid X_{1:n}) \mathbin{\|} r(\cdot\mid S_n)\bigr) \le\mathbb{E}_{X_{1:n}}\bigl[B(X_{1:n}) + \eta(X_{1:n})\bigr].

This bounds the representation-based predictor’s total expected excess log loss.

Finally, we apply § 7.4’s decomposition, now with base-2 logarithms:

EX1:nDKL(μ(⋅∣X1:n)∥r(⋅∣Sn))=Iμ(Xn+1;X1:n∣Sn)+ESnDKL(μ(⋅∣Sn)∥r(⋅∣Sn)).\mathbb{E}_{X_{1:n}}D_{\mathrm{KL}}\bigl(\mu(\cdot\mid X_{1:n}) \mathbin{\|} r(\cdot\mid S_n)\bigr) = I_{\mu}(X_{n+1};X_{1:n} \mid S_n) + \mathbb{E}_{S_n}D_{\mathrm{KL}}\bigl(\mu(\cdot\mid S_n) \mathbin{\|} r(\cdot\mid S_n)\bigr).

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,

Iμ(Xn+1;X1:n∣Sn)≤EX1:n[B(X1:n)+η(X1:n)].I_{\mu}(X_{n+1};X_{1:n} \mid S_n) \le\mathbb{E}_{X_{1:n}}\bigl[B(X_{1:n}) + \eta(X_{1:n})\bigr].

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 E[B(X1:n)+η(X1:n)]\mathbb{E}[B(X_{1:n})+\eta(X_{1:n})] on that total. The term B(x)B(x) bounds the reference predictor’s additional loss, while η(x)\eta(x) 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:

  1. Which contextual information should contribute?

  1. 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 H(ℓ)H^{(\ell)} into H(ℓ+1)H^{(\ell+1)}. Here, H(ℓ)H^{(\ell)} 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

I(Xt+1;H(ℓ+1))≤I(Xt+1;H(ℓ)).I(X_{t+1}; H^{(\ell+1)}) \le I(X_{t+1}; H^{(\ell)}).

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. [1]Brown, T. B., et al. (2020). Language Models Are Few-Shot Learners. arXiv:2005.14165 [cs.CL].arxiv.org/abs/2005.14165
  2. [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. [3]Chernov, A., Hutter, M., and Schmidhuber, J. (2007). Algorithmic Complexity Bounds on Future Prediction Errors. arXiv:cs/0701120v1 [cs.LG].DOI
  4. [4]Cover, T. M., and Thomas, J. A. (2006). Elements of Information Theory. 2nd ed. Wiley-Interscience.
  5. [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. [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. [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. [8]Hutter, M. (2005). Universal Artificial Intelligence: Sequential Decisions Based on Algorithmic Probability. Springer.
  9. [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. [10]Li, M., and Vitányi, P. (1993) An Introduction to Kolmogorov Complexity and Its Applications. Springer-Verlag.
  11. [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. [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. [13]Solomonoff, R. J. (1964). A Formal Theory of Inductive Inference. Information and Control, Parts I and II.
  14. [14]Tishby, N., Pereira, F. C., and Bialek, W. (1999). The Information Bottleneck Method. arXiv:physics/0004057 [physics.data-an].
  15. [15]Vaswani, A., et al. (2017). Attention Is All You Need. arXiv:1706.03762 [cs.CL].arxiv.org/abs/1706.03762
  16. [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.

Paper details

vlnc:W_n7gtq2jg
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 0

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Computer Science

Not recorded for this paper

View statement
Looking for related papers…
Contents