betaFeedback

WorksComputer Science

Enhancing Attention with Higher-Order Attention

Abstract

Current decoder large language models rely on a combination of attention, feed forward and residual layers. The attention used is autoregressive (AR) though this is not strictly correct, as we note. That motivates the introduction of other attention methods that, while also not strictly AR, do enhance the AR character. One is based on a decomposition of mutual information (MI) into a set of Conditional MIs (CMIs) that correlate key tokens with pairs of query tokens. A second, higher-order attention, introduces correlations between contiguous key and query tokens. A third introduces correlations between a set of key and query tokens and uses a Generalized Maximum Entropy Principle to obtain an attention expression spanning a sequence of tokens. All these methods may enhance the information content of the autoregressive probabilities that are used in inference/generation. Applications to contrastive decoding and a systematic analysis of autoregressive probabilities are presented.

Introduction

Attention-based decoder large language Models (LLMs), with their autoregressive character, are currently the dominant method for training language models [1, 2]. Each layer’s module consists of attention (ATTN) and MLP/FFN contributions, both summed with a residual connection and layer normalization. As emphasized in e.g. Elhage et al. [3], ATTN mixes tokens in such a way that accounts for their sequence. The non-mixing MLP/FFN incorporates abstract token interactions not relying on strict sequence order.

In this work, our focus is on the (self) ATTN contribution to a decoder LLM

x~t:=∑s≤tp(ks∣qt)vs(t=1,2,…,T)(1)\tilde{x}_t := \sum_{s \le t} p(k_s \mid q_t) v_s \quad(t=1,2,\ldots,T) \tag*{(1)}

where, for a particular query qtq_t, the conditional probabilities p(ks∣qt)p(k_s \mid q_t) of the ksk_s keys are summed over the (s≤t)(s \le t) tokens as introduced by the value vectors, vsv_s. The queries, keys and values are all from the same token set, xt∈Xx_t \in X, from a vocabulary V\mathcal{V} of size ∣V∣|\mathcal{V}|, in a TT-length context. The conditional probabilities (attention weights) p(ks∣qt)p(k_s \mid q_t) are obtained by optimization of

p(ks∣qt):=softmax⁡([ks⋅qtd]); (∑s=1s=Tp(ks∣qt)=1 (t∈T)).(2)p(k_s \mid q_t) := \operatorname{softmax}\left(\left[\frac{k_s \cdot q_t}{\sqrt{d}}\right]\right);\ \left(\sum_{s=1}^{s=T} p(k_s \mid q_t)=1\ (t \in T)\right). \tag*{(2)}

For xt=WE⋅wtx_t = W_E \cdot w_t positionally embedded tokens, query, key and value vectors are respectively parameterized as: qt=WQ⋅xtq_t = W_Q \cdot x_t; kt=WK⋅xtk_t = W_K \cdot x_t; vt=WV⋅xtv_t = W_V \cdot x_t and output with WOx~tW_O\tilde{x}_t. Neglecting biases, the scheme is parameterized using matrices: WE,WQ,WK,WV,WO,WUW_E,W_Q,W_K,W_V,W_O,W_U denoting, respectively, embedding, query, key, value, output, unembedding matrices. (In the following we suppress the embed dimension dd-factor for convenience.)

The autoregressive character of the scheme is embodied in the linear, additive expression of Eq. (1). However, what is being approximated by Eq. (1) is the formal autoregressive decomposition [4] of the TT-random variable (RV) probability over the TT-length window:

P(x1,x2,…,xT)=∏t=Tt=1p(xt∣xt−1,…,x1):=∏t=Tt=1p(xt∣xt−1:1).(3)P(x_1,x_2,\ldots,x_T)=\prod_{t=T}^{t=1}p(x_t\mid x_{t-1},\ldots,x_1):=\prod_{t=T}^{t=1}p(x_t\mid x_{t-1:1}). \tag*{(3)}

The negative log-likelihood loss (NLL)

L:=−log⁡P(x1,x2,…,xT)=−∑t=Tt=1log⁡p(xt∣xt−1:1)(4)\mathcal{L}:=-\log P(x_1,x_2,\ldots,x_T)=-\sum_{t=T}^{t=1}\log p(x_t\mid x_{t-1:1}) \tag*{(4)}

is the typical function optimized in training a LLM [5]. To try to connect with the standard attention expression in Eq. (1) make a Markov Chain (MC) approximation [6] to Eq. (1.3):

∏t=Tt=1p(xt∣xt−1:1)→MC∏t=Tt=1p(xt∣xt−1):=PMC(x1,x2,…,xT).(5)\prod_{t=T}^{t=1}p(x_t\mid x_{t-1:1})\xrightarrow{MC}\prod_{t=T}^{t=1}p(x_t\mid x_{t-1}):=P_{MC}(x_1,x_2,\ldots,x_T). \tag*{(5)}

This is not a Markov process but rather a local approximation to the exact autoregressive decomposition of P(x1,x2,…,xT)P(x_1,x_2,\ldots,x_T). It is the lowest-level approximation to Eq. (1.3a) that keeps token correlations. If these pair conditionals were known, then the chain’s probability could be sampled. In the LLM machine learning context,

log⁡PMC=∑t=Tt=1log⁡p(xt∣xt−1)(6)\log P_{MC}=\sum_{t=T}^{t=1}\log p(x_t\mid x_{t-1}) \tag*{(6)}

could be optimized by NLL gradient descent. Clearly, this is not what is optimized by NLL gradient descent of the probability p(xt):=sm⁡(x~t) (t∈T)p(x_t):=\operatorname{sm}(\tilde{x}_t)\ (t\in T), with sm denoting the softmax function, obtained from Eq. (1). Thus, one must conclude that attention as currently formulated is, at best, “pseudo-autoregressive”, and suggests that methods incorporating other correlation could be useful.

The idea is to introduce more correlation into the conditional or the unconditional parts of autoregressive probability to the training of a LLM. In Section 2, we do so via conditional mutual information and focus on p(ks∣qt,qT+1)p(k_s \mid q_t,q_{T+1}) where ksk_s are key and qtq_t (t=1,2,…,Tt=1,2,\ldots,T) and qT+1q_{T+1} are query tokens. In Section 3 we introduce higher-order attention of the form p(ks+1,ks∣qt)p(k_{s+1},k_s \mid q_t) and further generalizations of the number of keys. In Section 4, we use trained probabilities p(ks+s′,ks∣qt)p(k_{s+s'},k_s \mid q_t) (s′=1,2,…,τs'=1,2,\ldots,\tau) (with τ≪T\tau\ll T as a practical matter) along with a Generalized Maximum Entropy Procedure (GMEP) as a post-training phase to extend the autoregressive probability to a sequence of length τ\tau using p(xt+t′,xt∣x<t)t′∈τp(x_{t+t'},x_t \mid x_{<t})_{t'\in\tau}.

It is essential to realize for the attention versions relying on the p(ks+s′,ks∣qt)p(k_{s+s'},k_s \mid q_t) that the identity

p(xt+t′,xt∣x<t)=p(xt+t′∣x<t+t′)p(xt∣x<t)(7)p(x_{t+t'},x_t \mid x_{<t})=p(x_{t+t'} \mid x_{<t+t'})p(x_t \mid x_{<t}) \tag*{(7)}

shows that there would be no difference with using the standard attention expressions on the right-hand side of the above versus that on the left-hand side. That would be the case under two conditions: 1) That training was exact and 2) that the NLL objective function did represent the linear combination over values of the attention method. With regard to item 1), the parameterization intrinsic to neural networks means that for the left and right sides of Eq. (7), one obtains, respectively, pθ(xt+t′,xt∣x<t)p_{\theta}(x_{t+t'},x_t \mid x_{<t}) and pφ(xt+t′∣x<t+t′)pφ(xt∣x<t)p_{\varphi}(x_{t+t'} \mid x_{<t+t'})p_{\varphi}(x_t \mid x_{<t}), with manifestly different parameterizations: θ\theta and φ\varphi.

Derivation of higher-order attention based on Conditional Mutual Information

We summarize, and manipulate for our purposes, expressions from Cover and Thomas’ “Elements of Information Theory” book [4]. The mutual information I(X;Y)I(X;Y) between RVs XX and YY is defined in terms of entropy H(X)H(X) and conditional entropy H(X∣Y)H(X\mid Y) as

I(X;Y)=H(X)−H(X∣Y).(8)I(X;Y)=H(X)-H(X\mid Y). \tag*{(8)}

Straightforward extension of Eq. (8) to the RV set X1,…,XT,YX_1,\ldots,X_T,Y is

I(X1,…,XT,Y)=H(X1,…,XT)−H(X1,…,XT∣Y).(9)I(X_1,\ldots,X_T,Y)=H(X_1,\ldots,X_T)-H(X_1,\ldots,X_T\mid Y). \tag*{(9)}

Using the autoregressive probability decomposition in Eq. (1.3a), chain rules for entropy and conditional entropy follow immediately:

H(X1,…,XT−1)=∑t=1T−1H(Xt∣Xt−1,…,X1)(10)H(X_1,\ldots,X_{T-1})=\sum_{t=1}^{T-1}H(X_t\mid X_{t-1},\ldots,X_1) \tag*{(10)}

and

H(X1,…,XT−1∣Y)=∑t=1T−1H(Xt∣Xt−1,…,X1,Y).(11)H(X_1,\ldots,X_{T-1}\mid Y)=\sum_{t=1}^{T-1}H(X_t\mid X_{t-1},\ldots,X_1,Y). \tag*{(11)}

Their difference

I(X1,…,XT−1,Y)=∑t=1T−1[H(Xt∣X1,…,Xt−1)−H(Xt∣X1,…,Xt−1,Y)](12)I(X_1,\ldots,X_{T-1},Y)=\sum_{t=1}^{T-1}\left[H(X_t\mid X_1,\ldots,X_{t-1})-H(X_t\mid X_1,\ldots,X_{t-1},Y)\right] \tag*{(12)}

expresses the MI as a sum of conditional mutual information (CMI) terms

I(X1,…,XT−1,Y)=∑t=1T−1I(Xt,Y∣X1,…,Xt−1):=∑t=1T−1I(Xt,Y∣Xt−1:1).(13)I(X_1,\ldots,X_{T-1},Y)=\sum_{t=1}^{T-1}I(X_t,Y\mid X_1,\ldots,X_{t-1}) := \sum_{t=1}^{T-1}I(X_t,Y\mid X_{t-1:1}). \tag*{(13)}

It is a “chain rule for information” [4] relating the MI on left hand side to a sum of CMIs on the right-hand side of Eq. (13) and follows from the autoregressive decomposition in Eq. (1.3a).

These conditional MIs are “natural” extension of the CMI I(X,Y∣Z)I(X,Y\mid Z) to composite RVs Z:=X1,X2,…,Xt−1Z:=X_1,X_2,\ldots,X_{t-1}, with explicit form

I(Xt,Y∣Xt−1:1)=∑xt−1:1∑xt∑yp(xt,y,xt−1:1)log⁡[p(xt,y∣xt−1:1)p(xt∣xt−1:1)p(y∣xt−1:1)].(14)I(X_t,Y\mid X_{t-1:1})=\sum_{x_{t-1:1}}\sum_{x_t}\sum_y p(x_t,y,x_{t-1:1})\log\left[\frac{p(x_t,y\mid x_{t-1:1})}{p(x_t\mid x_{t-1:1})p(y\mid x_{t-1:1})}\right]. \tag*{(14)}

Note that the expectation is over the distribution of all the RVs. These CMIs are the reduction in uncertainty in XtX_t due to knowledge of YY with the Xt−1:1X_{t-1:1} (t=1,…,T−1t=1,\ldots,T-1) given. For purposes of optimization, decompose Eq. (14) as

I(Xt,Y∣Xt−1:1)=∑xt,yp(xt,y)Ixt,y(Xt,Y∣Xt−1:1)(15)I(X_t,Y\mid X_{t-1:1})=\sum_{x_t,y}p(x_t,y)I_{x_t,y}(X_t,Y\mid X_{t-1:1}) \tag*{(15)}

with

Ixt,y(Xt,Y∣Xt−1:1):=∑xt−1:1p(xt−1:1∣xt,y)log⁡[p(xt−1:1∣xt,y)p(xt−1:1∣xt)p(xt−1:1∣y)].(16)I_{x_t,y}(X_t,Y\mid X_{t-1:1}):=\sum_{x_{t-1:1}}p(x_{t-1:1}\mid x_t,y)\log\left[\frac{p(x_{t-1:1}\mid x_t,y)}{p(x_{t-1:1}\mid x_t)p(x_{t-1:1}\mid y)}\right]. \tag*{(16)}

Note that the unconditional p(xt,xt−1:1;y)p(x_t,x_{t-1:1};y) aren’t involved in the optimization. As a sensible choice for RV YY, set Y=XTY=X_T, the next token in sequence, to obtain I(X1,…,XT)I(X_1,\ldots,X_T).

To implement the above, as in the transition from Eq. (1.3b) to Eq. (1); that is, from negative log likelihood to attention, make the replacement ∑xt−1:1⋯→∑s=1s=t−1∑xs⋯\sum_{x_{t-1:1}}\cdots\rightarrow\sum_{s=1}^{s=t-1}\sum_{x_s}\cdots to produce

Ixt,xT(Xt,XT∣Xt−1)→∑s=1s=t−1∑xsIxt,xT(Xt,XT∣Xs).(17)I_{x_t,x_T}(X_t,X_T \mid X_{t-1}) \rightarrow\sum_{s=1}^{s=t-1}\sum_{x_s} I_{x_t,x_T}(X_t,X_T \mid X_s). \tag*{(17)}

That leads to the replacement p(xt−1:1∣xt,xT)→p(xs∣xt,xT)p(x_{t-1:1}\mid x_t,x_T)\rightarrow p(x_s\mid x_t,x_T), along with the other two conditional probabilities in Eq. (2.7b). In Eq. (17), xt−1:1→ksx_{t-1:1}\rightarrow k_s represents each key token, and qTq_T and qtq_t (t=1,2,…,T−1t=1,2,\ldots,T-1) are a pair of query tokens. To be minimized is the conditional mutual information (the Kullback-Lieber distance) between p(ks∣qt,qT)p(k_s\mid q_t,q_T) and p(ks∣qt)p(ks∣qT)p(k_s\mid q_t)p(k_s\mid q_T). The resulting parameterized pθ(ks∣qt,qT)p_\theta(k_s\mid q_t,q_T)’s are used to create an analogous to Eq. (1) attention-like expression:

x~t,T=∑s≤ts=T−1pθ(ks∣qt,qT)vs; (t=1,2,…,T−1).(18)\tilde{x}_{t,T}=\sum_{s\le t}^{s=T-1}p_\theta(k_s\mid q_t,q_T)v_s;\ (t=1,2,\ldots,T-1). \tag*{(18)}

In this view, the probabilities of tokens (with s≤T−1s\le T-1) conditional on pairs of query tokens (between tt and T−1T-1) are to be obtained in similar fashion to the construction of the conventional attention in Eq. (1). The T−1T-1 added correlations are between query tokens separated as indicated in Eq. (18). This long-range correlation along the sequence may reinforce attention.

A parameterized expression for this attention expression is, via token embedding,

p(ks∣qt,qT)=[∑s<TexsT⋅WKQ⋅(xt+xT)]−1exsT⋅WKQ⋅(xt+xT):=softmax⁡(xsT⋅WKQ⋅(xt+xT));WKQ:=WKT⋅WQs.t.∑s<Tp(ks∣qt,qT)=1;(t=1,2,…,T−1).(19)\begin{aligned} p(k_s\mid q_t,q_T)&=\left[\sum_{s<T}e^{x_s^T\cdot\mathbf{W}_{KQ}\cdot(x_t+x_T)}\right]^{-1}e^{x_s^T\cdot\mathbf{W}_{KQ}\cdot(x_t+x_T)}\\ &:=\operatorname{softmax}\left(x_s^T\cdot\mathbf{W}_{KQ}\cdot(x_t+x_T)\right);\quad\mathbf{W}_{KQ}:=\mathbf{W}_K^T\cdot\mathbf{W}_Q\\ &\text{s.t.}\quad\sum_{s<T}p(k_s\mid q_t,q_T)=1;\quad(t=1,2,\ldots,T-1). \tag*{(19)} \end{aligned}

Derivation of higher-order attention based on local Markov chains

An alternative approach to enhancing attention starts from the formal decomposition in Eq. (1.3a) that we now write for composite RVs. To that end, partition integer sequence (n,n−1,…,1):=(n:1)(n,n-1,\ldots,1) := (n:1) into r−1r-1 slices with k=n/rk=n/r descending-ordered consecutive integers nrn_r per slice. Let n‾r\overline{n}_r indicate the remaining descending-ordered integers to that nrn_r. Then (excluding the last, singlet probability term)

P(n:1)=p(nr−1∣n‾r−1)p(nr−2∣n‾r−2)⋯p(n1∣n‾1)(20)P(n:1) = p(n_{r-1} \mid\overline{n}_{r-1})p(n_{r-2} \mid\overline{n}_{r-2})\cdots p(n_1 \mid\overline{n}_1) \tag*{(20)}

with the corresponding Markov chain approximation

PMC(n:1)=p(nr−1∣nr−2)p(nr−2∣nr−3)⋯p(n1∣n0)(n0:=n‾1).(21)P_{MC}(n:1) = p(n_{r-1} \mid n_{r-2})p(n_{r-2} \mid n_{r-3})\cdots p(n_1 \mid n_0) \quad(n_0 := \overline{n}_1). \tag*{(21)}

For example: r=5r=5; k=3k=3; n=kr=15n=kr=15 has 4 slices

P(15:1)=p(15,14,13∣12:1)p(12,11,10∣9:1)p(9,8,7∣6:1)p(6,5,4∣3:1)(22)P(15:1) = p(15,14,13 \mid12:1)p(12,11,10 \mid9:1)p(9,8,7 \mid6:1)p(6,5,4 \mid3:1) \tag*{(22)}

and

PMC(15:1)=p(15,14,13∣12:10)p(12,11,10∣9:7)p(9,8,7∣6:4)p(6,5,4∣3:1).(23)P_{MC}(15:1) = p(15,14,13 \mid12:10)p(12,11,10 \mid9:7)p(9,8,7 \mid6:4)p(6,5,4 \mid3:1). \tag*{(23)}

For example: r=6r=6; k=2k=2; n=kr=12n=kr=12 has 5 slices

P(12:1)=p(12,11∣10:1)p(10,9∣8:1)p(8,7∣6:1)p(6,5∣4:1)p(4,3∣2:1)(24)P(12:1) = p(12,11 \mid10:1)p(10,9 \mid8:1)p(8,7 \mid6:1)p(6,5 \mid4:1)p(4,3 \mid2:1) \tag*{(24)}

and

PMC(12:1)=p(12,11∣10,9)p(10,9∣8,7)p(8,7∣6,5)p(6,5∣4,3)p(4,3∣2,1).(25)P_{MC}(12:1) = p(12,11 \mid10,9)p(10,9 \mid8,7)p(8,7 \mid6,5)p(6,5 \mid4,3)p(4,3 \mid2,1). \tag*{(25)}

It would be impractical to deal with long Markov chains, as each additional conditional probability requires a partition function as a normalizing factor in the softmax construction. Thus, apply this MC idea at a low order to build higher-order attention. Namely,

PMC(n:1)=p(n2∣n1)p(n1∣n0)→p(k(T2)∣k(T1))P(k(T1)∣q(T0)).(26)P_{MC}(n:1) = p(n_2 \mid n_1)p(n_1 \mid n_0) \to p\left(k(T_2) \mid k(T_1)\right)P\left(k(T_1) \mid q(T_0)\right). \tag*{(26)}

This latter expression symbolizes the number of keys k(Ti)k(T_i) (i=1,2i=1,2) and queries q(T0)q(T_0) that will be needed to produce attention with increasing degrees of token correlation. Thus, at lowest MC order,

x~t=∑s≤tp(ks∣qt)vs(t=1,2,…,T)  (STD)(27)\widetilde{x}_t = \sum_{s \leq t} p(k_s \mid q_t)v_s \quad(t=1,2,\ldots,T) \; \text{(STD)} \tag*{(27)}

where STD denotes the standard attention [5].

With the assumption that x~t→p(xt∣x<t)\tilde{x}_t \to p(x_t \mid x_{<t}), the implicit autoregressive STD autoregressive attention expression introduces new correlations between keys:

x~t=∑s+1≤tp(ks+1∣ks)p(ks∣qt)[νs+νs+1](t=1,2,…,T)(singlet MC)(28)\tilde{x}_t=\sum_{s+1\leq t}p(k_{s+1}\mid k_s)p(k_s\mid q_t)\left[\nu_s+\nu_{s+1}\right](t=1,2,\ldots,T)\quad\text{(singlet MC)} \tag*{(28)}

where the singlet MC introduces neighbor key correlations separated from the query tokens per the attention paradigm. Note that the singlet MC can also be formulated via

x~t=∑s+1≤tp(ks+1,ks∣qt)[νs+νs+1](t=1,2,…,T)(singlet)(29)\tilde{x}_t=\sum_{s+1\leq t}p(k_{s+1},k_s\mid q_t)\left[\nu_s+\nu_{s+1}\right](t=1,2,\ldots,T)\quad\text{(singlet)} \tag*{(29)}

as follows from the autoregressive identity p(x3x2∣x1)=p(x3∣x2x1)p(x2∣x1)p(x_3x_2\mid x_1)=p(x_3\mid x_2x_1)p(x_2\mid x_1) followed by the MC p(x3x2∣x1)→MCp(x3∣x2)p(x2∣x1)p(x_3x_2\mid x_1)\xrightarrow{MC}p(x_3\mid x_2)p(x_2\mid x_1). The singlet requires a higher-order attention-like term, p(ks+1,ks∣qt)p(k_{s+1},k_s\mid q_t). The x~t\tilde{x}_t obtained from Eq. (28) is a representation of that from Eq. (29). With the attention paradigm, both versions of x~t\tilde{x}_t imply, with Eq. (7), that p(xt,xt+1∣x<t):=sm⁡(x~t+1)sm⁡(x~t)p(x_t,x_{t+1}\mid x_{<t}):=\operatorname{sm}(\tilde{x}_{t+1})\operatorname{sm}(\tilde{x}_t), with their incorporation of neighbor-token correlation. The downside of the, in principle, more accurate singlet expression in Eq. (29) is that it scales with ∣V∣3|\mathcal{V}|^3 versus the ∣V∣2|\mathcal{V}|^2 of the singlet MC in Eq. (28).

Proceeding systematically to higher order in key token correlation

x~t=∑s+2≤tp(ks+2∣ks+1)p(ks+1∣ks)p(ks∣qt)[νs+νs+1+νs+2](doublet MC)(30)\tilde{x}_t=\sum_{s+2\leq t}p(k_{s+2}\mid k_{s+1})p(k_{s+1}\mid k_s)p(k_s\mid q_t)\left[\nu_s+\nu_{s+1}+\nu_{s+2}\right]\quad\text{(doublet MC)} \tag*{(30)}

The scaling is 3∣V∣23|\mathcal{V}|^2 per query, thus still of the complexity of conventional attention. The scheme can be extended to triplet MC, and beyond. Note that, owing to the multiplicative MC form, back propagation is done with each term’s gradient multiplied by the remaining probabilities.

The requisite probabilities can be parameterized in “multiplicative” and “additive” versions.

The multiplicative versions are:

p(ks∣qt):=softmax⁡([xsT⋅WKQ⋅xt])p(k_s \mid q_t) := \operatorname{softmax}\left([x_s^T \cdot\mathbf{W}_{KQ} \cdot x_t]\right)
p(ks+1,ks∣qt):=softmax⁡([xs+1T⋅WKK⋅xs][xtT⋅WQ1⋅1TT])(31)p(k_{s+1},k_s \mid q_t) := \operatorname{softmax}\left([x_{s+1}^T \cdot\mathbf{W}_{KK} \cdot x_s]\left[x_t^T \cdot\mathbf{W}_{Q1} \cdot\mathbf{1}_T^T\right]\right) \tag*{(31)}

with

WK+K+:=WK+T⋅WK+\mathbf{W}_{K+K+} := \mathbf{W}_{K+}^T \cdot\mathbf{W}_{K+}; WKK:=WKT⋅WK\mathbf{W}_{KK} := \mathbf{W}_K^T \cdot\mathbf{W}_K; WKQ:=WKT⋅WQ\mathbf{W}_{KQ} := \mathbf{W}_K^T \cdot\mathbf{W}_Q; WQ1:=WQT⋅W1\mathbf{W}_{Q1} := \mathbf{W}_Q^T \cdot\mathbf{W}_1.

(For the p(ks+1,ks∣qt)p(k_{s+1},k_s \mid q_t) term, we introduce a new, learnable matrix W1\mathbf{W}_1 and a model-dimensioned column vector 1T1^T).

The additive versions are:

p(ks∣qt):=softmax⁡(xsT⋅WKQ⋅xt)p(k_s \mid q_t) := \operatorname{softmax}\left(x_s^T \cdot\mathbf{W}_{KQ} \cdot x_t\right)
p(ks+1,ks∣qt):=softmax⁡((xs+1T+xsT)⋅WKQ⋅xt)(32)p(k_{s+1},k_s \mid q_t) := \operatorname{softmax}\left((x_{s+1}^T + x_s^T) \cdot\mathbf{W}_{KQ} \cdot x_t\right) \tag*{(32)}

with WKQ:=WKT⋅WQ\mathbf{W}_{KQ} := \mathbf{W}_K^T \cdot\mathbf{W}_Q.

The different information contents of the underlying determinants of attention are readily obtained from the following (manifestly positive) mutual information:

I(ks+1,ks∣qt)=E(ks+1,ks∣qt)θlog⁡[pθ(ks+1,ks∣qt)pθ(ks+1∣qt) pθ(ks∣qt)].(33)I(k_{s+1},k_s \mid q_t) = \mathbb{E}^{\theta}_{(k_{s+1},k_s\mid q_t)} \log\left[\frac{p_{\theta}(k_{s+1},k_s \mid q_t)}{p_{\theta}(k_{s+1}\mid q_t)\,p_{\theta}(k_s\mid q_t)}\right]. \tag*{(33)}

Once the θ\theta parameters of pθ(ks+1,ks∣qt)p_{\theta}(k_{s+1},k_s \mid q_t) are obtained, the above denominator can be back calculated using Eq. (32), putting the ingredients of this mutual information onto a consistent basis. In Eq. (33) we left the expectation conditional on the query token qtq_t to allow investigation of the information content conditional on a query token.

Increasing the attention order with Generalized MEP (GMEP)

In order to increase τ\tau, the length of the token sequence considered, a Maximum Entropy Principle (MEP), introduced to Statistical Mechanics by Jaynes [7, 8, 9], can be invoked. The MEP maximizes entropy with suitable constraints on the various probabilities enforced by Lagrange Multipliers (LMs). MEP procedures were introduced to sequence-based data [10], and generalized in various ways [11]. One of them, the generalized MEP (GMEP), can be tailored to LLM inference.

First, train the model to obtain the p(ks+s′/ks∣qt)p\left(k_{s+s'}/k_s \mid q_t\right) (s′=1,2,…,τs'=1,2,\ldots,\tau) (with τ≪T\tau\ll T) and use the attention mechanism in Eq. (29) along with Eq. (7) to obtain p(xt,xt+t′∣x<t):=sm⁡(x~t)sm⁡(x~t+t′)p(x_t,x_{t+t'} \mid x_{<t}) := \operatorname{sm}(\tilde{x}_t)\operatorname{sm}(\tilde{x}_{t+t'}) for token pairs {xt,xt+t′}\{x_t,x_{t+t'}\} with (1≤t<t′≤t+τ)(1 \le t < t' \le t+\tau). While requiring additional calculation relative to s′=1s'=1 in Eq. (29), the τ′\tau's under consideration can’t be too large (e.g. τ<5\tau<5) as their use for even e.g. Look Ahead Greedy Search (L.A.G.S.) would become too expensive for large τ\tau.

Thus, do GMEP on p(xt,xt+t′∣x<t)p(x_t,x_{t+t'} \mid x_{<t}) to obtain {p(xt,xt+t′∣x<t)}t′∈τ→GMEPp(xt+τ:t∣x<t)\left\{p(x_t,x_{t+t'} \mid x_{<t})\right\}_{t'\in\tau} \xrightarrow{\mathrm{GMEP}} p(x_{t+\tau:t} \mid x_{<t}) over sequences of length τ\tau, as follows. The constraint equation on the target distribution ff, for token pair {xt,xt′}\{x_t,x_{t'}\} is

∑X−f(X)−p(xt,xt′∣x<t)=0(1≤t<t′≤t+τ),(34)\sum_{\mathbf{X}_{-}} f(\mathbf{X})-p(x_t,x_{t'} \mid x_{<t})=0 \quad(1\le t<t'\le t+\tau), \tag*{(34)}

with X=(x1,x2,…,xτ)\mathbf{X}=(x_1,x_2,\ldots,x_\tau) and X−≡X−{xt,xt′(t<t′)}\mathbf{X}_{-}\equiv\mathbf{X}-\{x_t,x_{t'}(t<t')\}.

The Lagrangian is

L=−∑Xf(X)log⁡f(X)+∑x2,x1λx2,x1[∑X−f(X)−p(x2,x1∣x1:1)]+∑x3,x1λx3,x1[∑X−f(X)−p(x3,x1∣x1:1)]+…+∑xτ,xτ−1λxτ,xτ−1[∑X−f(X)−p(xτ,xτ−1∣xτ−1:1)],(35)\begin{aligned} L=-\sum_{\mathbf{X}}f(\mathbf{X})\log f(\mathbf{X}) \\ &+\sum_{x_2,x_1}\lambda_{x_2,x_1}\left[\sum_{\mathbf{X}_{-}}f(\mathbf{X})-p(x_2,x_1\mid x_{1:1})\right]+\sum_{x_3,x_1}\lambda_{x_3,x_1}\left[\sum_{\mathbf{X}_{-}}f(\mathbf{X})-p(x_3,x_1\mid x_{1:1})\right] \\ &+\ldots+\sum_{x_\tau,x_{\tau-1}}\lambda_{x_\tau,x_{\tau-1}}\left[\sum_{\mathbf{X}_{-}}f(\mathbf{X})-p(x_\tau,x_{\tau-1}\mid x_{\tau-1:1})\right], \tag*{(35)} \end{aligned}

with Lagrange multipliers: λxt,xt′\lambda_{x_t,x_{t'}} and xt:1:=xt,xt−1,…,x1x_{t:1}:=x_t,x_{t-1},\ldots,x_1.

The Euler-Lagrange equation is

−1−log⁡f(X)+λx1,x2+λx1,x3+…+λxτ−1,xτ=0.(36)-1-\log f(\mathbf{X})+\lambda_{x_1,x_2}+\lambda_{x_1,x_3}+\ldots+\lambda_{x_{\tau-1},x_\tau}=0. \tag*{(36)}

Noting that S:=∑t=1τ−1∑t′=t+1τλxt,xt′S:=\sum_{t=1}^{\tau-1}\sum_{t'=t+1}^{\tau}\lambda_{x_t,x_{t'}} will generate the above-sum of Lagrange Multiplier terms, the Euler-Lagrange equation can be compacted to

−1−log⁡f(X)+S=0.(37)-1-\log f(\mathbf{X})+S=0. \tag*{(37)}

The scaling of this MEP follows from the (τ−1)τ/2∗∣V∣2∼τ2/2∗∣V∣2(\tau-1)\tau/2 * |\mathcal{V}|^2 \sim\tau^2/2 * |\mathcal{V}|^2 Lagrange Multipliers to be determined for the vocabulary V\mathcal{V}. With a candidate set VC\mathcal{V}_C (see below for a method to choose it), such that ∣VC∣≪∣V∣|\mathcal{V}_C| \ll|\mathcal{V}|, the scaling is order τ2/2∗∣VC∣2\tau^2/2 * |\mathcal{V}_C|^2. Optimization schemes such as the well-known Newton-Krylov method [12] are appropriate and, for large-scale systems, there are sophisticated methods available [13]. Two approaches that focus on the structure of the probability distributions can be used to speed up the calculation. Using PCA/SVD to obtain τC2\tau_C^2 modes reduces the τ2\tau^2 part to τC2≪τ2\tau_C^2 \ll\tau^2. Using Rényi entropy (with α>1\alpha> 1), versus Gibbs-Shannon entropy, reduces the ∣VC∣|\mathcal{V}_C| value by further focusing on (the desired) higher probability parts of the distribution.

Once the Lagrange Multipliers are obtained, the optimized values in Eq. (37)

p(xt+τ:t∣x<t)=f∗(xt+τ:t∣x<t)(38)p\left(x_{t+\tau:t}\mid x_{<t}\right)=f^*\left(x_{t+\tau:t}\mid x_{<t}\right) \tag*{(38)}

are the desired order-τ\tau token sequence probabilities. Of course, compared to training, this operation is done only once.

The Eq. (38) probabilities can be used for inference/generation. Over some context TT

p(xT:1):=p(xT,xT−1,…,x1)=∑t=1⌊T/τ⌋p(xtτ:(t−1)τ+1∣x<(t−1)τ+1).(39)p\left(x_{T:1}\right) := p\left(x_T,x_{T-1},\ldots,x_1\right)=\sum_{t=1}^{\lfloor T/\tau\rfloor}p\left(x_{t\tau:(t-1)\tau+1}\mid x_{<(t-1)\tau+1}\right). \tag*{(39)}

In the LM solution there are redundancies to eliminate. The pair probabilities satisfy the row-based (the last row is fixed) conditions:

p(xτ,xt′)=pt′(xt′)−∑t=1τ−1p(xt,xt′)(1≤t<t′≤τ).(40)p\left(x_\tau,x_{t'}\right)=p_{t'}\left(x_{t'}\right)-\sum_{t=1}^{\tau-1}p\left(x_t,x_{t'}\right)\left(1\leq t<t'\leq\tau\right). \tag*{(40)}

Alternatively, they can be formulated as column-based (the last column is fixed)

p(xt,xτ)=p(xt)−∑t′=1τ−1p(xt,xt′)(1≤t<t′≤τ).(41)p\left(x_t,x_\tau\right)=p\left(x_t\right)-\sum_{t'=1}^{\tau-1}p\left(x_t,x_{t'}\right)\left(1\leq t<t'\leq\tau\right). \tag*{(41)}

When decoding, as a practical matter, a scheme most likely must be used to restrict the state space to a manageable size. § 5 provides the series of inequalities:

min⁡xp(X=x)≥min⁡xp(X=x∣x1)≥min⁡xp(X=x∣x2,x1)≥…≥min⁡xp(X=x∣xT:1)(42)\min_x p(X=x)\geq\min_x p(X=x\mid x_1)\geq\min_x p(X=x\mid x_2,x_1)\geq\ldots\geq\min_x p(X=x\mid x_{T:1}) \tag*{(42)}

for any token xt∈Xx_t \in X from the vocabulary V\mathcal{V}. The min⁡xp(x)\min_x p(x) is an upper bound to all the conditional probabilities. Thus, pick the cut-off, candidate set Vc\mathcal{V}_c of V\mathcal{V} using min⁡xp(X=x)\min_x p(X=x) – i.e., just from the vocabulary. Then, for an e.g., L.A.G.S. of length τ\tau, the decoding scaling is ∼∣V∣clutτ\sim|\mathcal{V}|_{\mathrm{clut}}^\tau. That can turn an impractical search into a practical search for both higher-order attention and, especially, the GMEP scheme.

Application to Contrastive Decoding

The different methods presented in Sections 2-§ 3 are quite natural for Contrastive Decoding (CD). [14] CD invokes two or more models to be used at inference/generation where one is considered the Expert (E) and the other(s) the amateur(s)/anti-expert(s) (A,...). The approach is based on a score S(vt)S(v_t) for the ν\nu'th token at position tt in a sequence:

S(vt)∝log⁡pE(vt∣x<t)−αlog⁡pA(vt∣x<t)(43)S(v_t) \propto\log p_E(v_t \mid x_{<t}) - \alpha\log p_A(v_t \mid x_{<t}) \tag*{(43)}

with α\alpha an adjustable parameter.

For any tt, the score is normed to the CD probability:

pCD(v)=[pE(v)/pAα(v)]/∑w[pE(w)/pAα(w)].(44)p_{\mathrm{CD}}(v) = \left[p_E(v) / p_A^\alpha(v)\right] \bigg/ \sum_w \left[p_E(w) / p_A^\alpha(w)\right]. \tag*{(44)}

A token with high-to-moderate E and low A probability boosts the CD-based probability relative to its E value, while high-to-moderate E and high A probability suppresses the CD-based probability relative to its E value. Note that this scheme is based on the E probabilities; thus, they are in the high to middling range, while the corresponding A probabilities can range from high to low.

CD can lead to a reduction in repetitive text and reduce hallucinations, [15, 16, 17] and improve common sense reasoning [18]. Operating at inference/generation versus training is much less expensive than model development. However, when based on ATTN, it is intrinsically local to each position in a sequence versus optimized over a sequence. Our GMEP method, with its focus on sequence, may improve the quality of CD. To implement it for sequences, suppose the expert is taken from GMEP and the anti-expert from ATTN.

To generate the sequences for the E and A models in the simplest application consider using τ\tau–length L.A.G.S. for the A model:

xt∗(A)=arg⁡max⁡xt∈V∑i=ti=t+τlog⁡p(xi∣x<i)(45)x_t^*(A)=\mathop{\arg\max}_{x_t\in\mathcal{V}}\sum_{i=t}^{i=t+\tau}\log p(x_i\mid x_{<i}) \tag*{(45)}

and use the GMEP procedure for the E model.

xt∗(E)=arg⁡max⁡t+τ:t∈Vlog⁡p(xt+τ:t∣x<t)(46)x_t^*(E)=\mathop{\arg\max}_{t+\tau:t\in\mathcal{V}}\log p(x_{t+\tau:t}\mid x_{<t}) \tag*{(46)}

Again, as a practical matter, use the ∼∣V∣cutτ−1∣V∣\sim|\mathcal{V}|_{\mathrm{cut}}^{\tau-1}|\mathcal{V}| restriction of the pE(ν)p_E(\nu) to a high probability set.

Using these respective probabilities, for the E and A models, will reorder the token probabilities from those of pE(ν)p_E(\nu) to those of pCD(ν)p_{CD}(\nu) according to Eq. (44). The scheme can be applied to nucleus (top-p) and beam search sampling methods at the expense of more overhead to evaluate and store candidates.

The scheme could be elaborated with E from the GMEP and two anti-experts: A1 H.O. ATTN and A2 ATTN.

Some implications of higher-order attention

As the degree of autoregression decreases, the corresponding entropy should increase owing to the greater freedom of probabilities with decreased autoregression. To show this property, write a series of approximations to the exact τ\tau-point probability

Papprox(η):=∏t=Tt=1p(xt∣xt−1:η)(η=2,3,…,t−1)(47)P_{\mathrm{approx}}(\eta):=\prod_{t=T}^{t=1}p(x_t\mid x_{t-1:\eta})\quad(\eta=2,3,\ldots,t-1) \tag*{(47)}

where P(x1,x2,…,xT)=Pexact=Papprox(η=1)P(x_1,x_2,\ldots,x_T)=P_{\mathrm{exact}}=P_{\mathrm{approx}}(\eta=1) by Eq. (1.3a).

The corresponding entropies are

Happrox(η)=∑t=Tt=1H(Xt∣Xt−1:η)(η=2,3,…,t−1);Hexact=Happrox(1).(48)H_{\mathrm{approx}}(\eta)=\sum_{t=T}^{t=1}H(X_t\mid X_{t-1:\eta})\quad(\eta=2,3,\ldots,t-1); H_{\mathrm{exact}}=H_{\mathrm{approx}}(1). \tag*{(48)}

The conditional entropies H(Xt∣Xt−1:η)H(X_t\mid X_{t-1:\eta}) satisfy the inequalities [10]

H(Xt∣Xt−1:η)≤H(Xt∣Xt−1:η+1),(49)H(X_t\mid X_{t-1:\eta})\le H(X_t\mid X_{t-1:\eta+1}), \tag*{(49)}

as can be obtained from Jensen’s inequality applied to the convex entropy. Therefore, with Eq. (49), the approximate entropy in Eq. (48) satisfies

Happrox(η)≤Happrox(η+1)□.(50)H_{\mathrm{approx}}(\eta)\le H_{\mathrm{approx}}(\eta+1)\square. \tag*{(50)}

Thus

Hexact=Happrox(1)≤Happrox(2)≤…≤Happrox(t−1),(51)H_{\mathrm{exact}} = H_{\mathrm{approx}}(1) \le H_{\mathrm{approx}}(2) \le\ldots\le H_{\mathrm{approx}}(t-1), \tag*{(51)}

with the last term in the chain of inequalities the independent random variable limit.

The above is an average statement, of course. A stronger, more interesting, result can be proved, as shown in Appendix § 7. Namely, as more conditional RVs in Eq. (47) are introduced, the difference between minimum and maximum probabilities increases, leading to the series of inequalities for the quantities defined in Eq. (47):

min⁡Pexact=min⁡Papprox(1)≤min⁡Papprox(2)≤…≤min⁡Papprox(t−1)≤max⁡Papprox(t−1)≤…≤max⁡Papprox(2)≤max⁡Papprox(1)=max⁡Pexact.(52)\begin{aligned} \min P_{\mathrm{exact}} &= \min P_{\mathrm{approx}}(1) \le\min P_{\mathrm{approx}}(2) \le\ldots\le\min P_{\mathrm{approx}}(t-1) \\ &\le\max P_{\mathrm{approx}}(t-1) \le\ldots\le\max P_{\mathrm{approx}}(2) \le\max P_{\mathrm{approx}}(1) = \max P_{\mathrm{exact}} . \tag*{(52)} \end{aligned}

Increasing the conditionality of probabilities produces a greater spread in the min/max probability values. The min inequalities are particularly useful for systematically obtaining the probability cutoff Vc\mathcal{V}_{c} of the vocabulary V\mathcal{V}.

Now focus on the maximum conditional probabilities, as they are of greatest interest. The context-TT probability of Eq. (1.3a) using the ATTN mechanism relies on the conditional decomposition where the conditional terms are only known implicitly. Thus, to investigate the maximum inequalities of Eq. (52) a roundabout procedure is needed. Suppose you were to train on shorter, truncated contexts indexed by η=2,3,…,t−1\eta= 2,3,\ldots,t-1

P(xT,xT−1,…,xη):=∏τ=Tt=ηp(xt∣xt−1:t−η)(η=2,3,…,t−1)(x0:=0).(53)P\left(x_T,x_{T-1},\ldots,x_{\eta}\right) := \prod_{\tau=T}^{t=\eta} p\left(x_t \mid x_{t-1:t-\eta}\right)\left(\eta= 2,3,\ldots,t-1\right)\left(x_0 := 0\right). \tag*{(53)}

The corresponding conditionals are

p(xt∣xt−1:t−η):=p(xt,xt−1:t−η)/p(xt−1:t−η)(54)p\left(x_t \mid x_{t-1:t-\eta}\right) := p\left(x_t,x_{t-1:t-\eta}\right) \big/ p\left(x_{t-1:t-\eta}\right) \tag*{(54)}

and can be obtained by marginalization:

p(xt−1:t−η)=∑xtp(xt:t−η).(55)p\left(x_{t-1:t-\eta}\right) = \sum_{x_t} p\left(x_{t:t-\eta}\right). \tag*{(55)}

However, as a practical matter, a method of evaluation of these high dimensional probabilities, such as top-K or its simplest, L.A.G.S., that provides an approximation to the maximum probability must be used. Designate the maximum conditioned probabilities using ‘max’ and those obtained by Greedy Search as ‘K=1’ (from top-K search).

Then it is evident, denoting Xt=xt∗X_t = x_t^* as the maximizing value of RVs {Xt}\{X_t\}, that

pmax⁡(xt−1:t−η∗)=pK=1(xt:t−η∗)+∑xt≠xt∗p(xt,xt−1:t−η∗).(56)p^{\max}\left(x^*_{t-1:t-\eta}\right)=p^{K=1}\left(x^*_{t:t-\eta}\right)+\sum_{x_t\ne x_t^*}p\left(x_t,x^*_{t-1:t-\eta}\right). \tag*{(56)}

Thus:

pmax⁡(xt−1:t−η∗)≥pK=1(xt−1:t−η∗),(57)p^{\max}\left(x^*_{t-1:t-\eta}\right)\ge p^{K=1}\left(x^*_{t-1:t-\eta}\right), \tag*{(57)}

and

p(xt∣xt−1:t−η)=p(xt,xt−1:t−η)p(xt−1:t−η)(58)p\left(x_t\mid x_{t-1:t-\eta}\right)=\frac{p\left(x_t,x_{t-1:t-\eta}\right)}{p\left(x_{t-1:t-\eta}\right)} \tag*{(58)}

satisfies

pmax⁡(xt∣xt−1:t−η)≤pK=1(xt∣xt−1:t−η).(59)p^{\max}\left(x_t\mid x_{t-1:t-\eta}\right)\le p^{K=1}\left(x_t\mid x_{t-1:t-\eta}\right). \tag*{(59)}

Eqs. (59) and (52) lead to the “pairwise” comparisons

pK=1(xt∣xt−1:t−η)≥pmax⁡(xt∣xt−1:t−η)≥pmax⁡(xt∣xt−1:t−η+1).(60)p^{K=1}\left(x_t\mid x_{t-1:t-\eta}\right)\ge p^{\max}\left(x_t\mid x_{t-1:t-\eta}\right)\ge p^{\max}\left(x_t\mid x_{t-1:t-\eta+1}\right). \tag*{(60)}

But the ‘chain’ of inequalities of Eq. (52) would be broken by (6.13). For example:

pK=1(x3∣x2,x1)≥pmax⁡(x3∣x2,x1)≥pmax⁡(x3∣x2)≤pK=1(x3∣x2)≥pmax⁡(x3∣x2).(61)p^{K=1}\left(x_3\mid x_2,x_1\right)\ge p^{\max}\left(x_3\mid x_2,x_1\right)\ge p^{\max}\left(x_3\mid x_2\right)\le p^{K=1}\left(x_3\mid x_2\right)\ge p^{\max}\left(x_3\mid x_2\right). \tag*{(61)}

However, by definition, the L.A.G.S. approximation in fact sets the conditionals equal:

pK=1(xt∣xt−1:t−η)=pmax⁡(xt∣xt−1:t−η).(62)p^{K=1}\left(x_t\mid x_{t-1:t-\eta}\right)=p^{\max}\left(x_t\mid x_{t-1:t-\eta}\right). \tag*{(62)}

Thus, to this degree of approximation, which is driven by practicality, the chain of inequalities for the maxima in Eq. (52) hold equally well when using L.A.G.S..

As a convenient measure of the degree of loss of information with shortening the conditional ranges in Eq. (52) it is convenient to use (maximum) perplexity

PPmax⁡(η):=∏t=Tt=η1(pmax⁡(xt∣xt−1:t−η))1T(63)PP^{\max}(\eta):=\prod_{t=T}^{t=\eta}\frac{1}{\left(p^{\max}\left(x_t\mid x_{t-1:t-\eta}\right)\right)^{\frac{1}{T}}} \tag*{(63)}

or the negative of its log:

log⁡PPmax⁡(η):=−1T∑t=Tt=ηlog⁡pmax⁡(xt∣xt−1:t−η).(64)\log PP^{\max}(\eta):=-\frac{1}{T}\sum_{t=T}^{t=\eta}\log p^{\max}\left(x_t\mid x_{t-1:t-\eta}\right). \tag*{(64)}

This produces a chain of inequalities:

PPexactmax⁡=PPapproxmax⁡(1)≤PPapproxmax⁡(2)≤⋯≤PPapproxmax⁡(T−1).(65)PP^{\max}_{\mathrm{exact}}=PP^{\max}_{\mathrm{approx}}(1)\le PP^{\max}_{\mathrm{approx}}(2)\le\cdots\le PP^{\max}_{\mathrm{approx}}(T-1). \tag*{(65)}

A decrease in autoregression increases perplexity.

Concluding Remarks

There is a contradiction between the conventional attention expression with its linear combination of values, conditional on each query’s probability, and the autoregressive negative log-likelihood objective function that it is supposed to represent. They are not relatable by systematic approximation. The higher-order attention expressions introduced here are more correlated approximations to the NLL expression. Embedding more language structure in the training of the autoregressive probabilities that are then chained together for inference/generation may improve the coherence of the LLM output. Further, the empiricism inherent to training pθ(xt+1,xt∣x<t)p_\theta(x_{t+1},x_t \mid x_{<t}), or its MC approximation, with parameters θ\theta, vs. training pφ(xt∣x<t)p_\varphi(x_t \mid x_{<t}), with parameters φ\varphi, should provide a more accurate data representation in the former versus the latter. The various higher-order attentions developed here should produce systematically more specific probabilities with a richer account of language, though they may be impractical unless used for a restricted V\mathcal{V} alphabet.

The first alternative attention in Sec. 2 is based on the CMI decomposition of the mutual information that follows from the fundamental probability decomposition underlying the NLL objective. It, too, uses a linear combination of values but incorporates other correlation via its dependence on query token pairs separated in sequence by all token pairs, as displayed in Eq. (18). The second alternative of § 2 is based on incorporating various levels of neighbor key token correlation. The third method in § 3 does require the expense of training with pairs of keys over a τ\tau interval, and the overhead of running post-training GMEP. But it may provide a much more informative version of attention via p(xt+τ:t∣x<t)p(x_{t+\tau:t} \mid x_{<t}).

Section 5 provides an application of higher-order attention to Contrastive Decoding. Sequence-based decoding can also provide an entrée to enhanced L.A.G.S. methods for use when resources are limited. Also, distillation [18], as well as other teacher-student focused methods, could profit from this sequence version of attention, as it may reduce exposure bias.

Section 6 presents a systematic exploration of the information content of the maxima of conditional probabilities/perplexity dependence on the extent of auto-regression. How the accuracy of next token prediction degrades with a decrease in autoregression may help in evaluating the quality of language models. referral

Appendix

In this Appendix we prove that:

min⁡x3,x2,x1p(x3∣x2,x1)≤min⁡x3,x2p(x3∣x2)≤max⁡x3,x2p(x3∣x2)≤max⁡x3,x2,x1p(x3∣x2,x1)(66)\min_{x_3,x_2,x_1} p(x_3 \mid x_2,x_1) \le\min_{x_3,x_2} p(x_3 \mid x_2) \le\max_{x_3,x_2} p(x_3 \mid x_2) \le\max_{x_3,x_2,x_1} p(x_3 \mid x_2,x_1) \tag*{(66)}

and later straightforwardly generalize it to obtain the result underlying Eq. (52).

The proof relies on the law of iterated expectations:

E(X)=EYEX∣Y=∫dy p(y)∫dx xp(x∣y) dx=∫dy p(y)F(y)F(Y=y):=∫dx xp(x∣Y=y);EYF(Y)=∫dy p(y)F(y);(67)\begin{aligned} E(X) &= E_Y E_{X\mid Y} = \int dy\,p(y)\int dx\,x p(x\mid y)\,dx = \int dy\,p(y)F(y) \\ F(Y=y) &:= \int dx\,x p(x\mid Y=y); \quad E_Y F(Y) = \int dy\,p(y)F(y); \tag*{(67)} \end{aligned}

meaning the YY expectation is of the function F(Y)F(Y). Also of use is an indicator function: if A∈XA \in X

then 1A(x)=11_A(x)=1 if x∈Ax \in A and 1A(x)=01_A(x)=0 otherwise. Applying the law of iterated expectation from above, with X→X3;Y→X1X \to X_3; Y \to X_1

p(x3∣x2)=EX3[1X3=x3∣X2=x2]=EX1[EX3[1X3=x3∣X2=x2,X1]∣X2=x2](68)p(x_3\mid x_2)=E_{X_3}\left[1_{X_3=x_3}\mid X_2=x_2\right]=E_{X_1}\left[E_{X_3}\left[1_{X_3=x_3}\mid X_2=x_2,X_1\right]\mid X_2=x_2\right] \tag*{(68)}

where p(x3∣x2,X1):=EX3[1X3=x3∣X2=x2,X1]p(x_3\mid x_2,X_1):=E_{X_3}\left[1_{X_3=x_3}\mid X_2=x_2,X_1\right]. Therefore

p(x3∣x2)=EX1[p(x3∣x2,X1)∣X2=x2].(69)p(x_3\mid x_2)=E_{X_1}\left[p(x_3\mid x_2,X_1)\mid X_2=x_2\right]. \tag*{(69)}

Thus, p(x3∣x2)p(x_3\mid x_2) can be thought of as an average of p(x3∣x2,X1)p(x_3\mid x_2,X_1) over X1X_1, given fixed x2x_2 and x3x_3, implying that p(x3∣x2)p(x_3\mid x_2) is less than the maximum and greater than the minimum of p(x3∣x2,X1)p(x_3\mid x_2,X_1) over X1X_1, given fixed x2x_2 and x3x_3.

To prove this supposition, focus on RV X1X_1. Given any fixed x2x_2 and x3x_3

min⁡sp(x3∣x2,X1=s)≤p(x3∣x2,X1)≤max⁡sp(x3∣x2,X1=s)(70)\min_s p(x_3\mid x_2,X_1=s) \le p(x_3\mid x_2,X_1) \le\max_s p(x_3\mid x_2,X_1=s) \tag*{(70)}

by definition of minimum and maximum.

∴min⁡sp(x3∣x2,X1=s)≤EX1[p(x3∣x2,X1)∣X2=x2]≤max⁡sp(x3∣x2,X1=s)∴min⁡sp(x3∣x2,X1=s)≤p(x3∣x2)≤max⁡sp(x3∣x2,X1=s), by (A.5).(71)\begin{aligned} \therefore\min_s p(x_3\mid x_2,X_1=s) &\le E_{X_1}\left[p(x_3\mid x_2,X_1)\mid X_2=x_2\right]\le\max_s p(x_3\mid x_2,X_1=s) \\ \therefore\min_s p(x_3\mid x_2,X_1=s) &\le p(x_3\mid x_2)\le\max_s p(x_3\mid x_2,X_1=s),\text{ by (A.5).} \tag*{(71)} \end{aligned}

Thus,

min⁡s,t,up(X3=u∣X2=t,X1=s)≤min⁡sp(x3∣x2,X1=s)≤p(x3∣x2)(72)\min_{s,t,u} p(X_3=u\mid X_2=t,X_1=s) \le\min_s p(x_3\mid x_2,X_1=s) \le p(x_3\mid x_2) \tag*{(72)}

with the first inequality by definition of minimum and

p(x3∣x2)≤max⁡sp(x3∣x2,X1=s)≤max⁡s,t,up(X3=u∣X2=t,X1=s)(73)p(x_3\mid x_2) \le\max_s p(x_3\mid x_2,X_1=s) \le\max_{s,t,u} p(X_3=u\mid X_2=t,X_1=s) \tag*{(73)}

with the second inequality by definition of maximum. (Note that above is first for ss and then s,t,us,t,u, so ss is same in both, and fixes t,ut,u.) Therefore

min⁡s,t,up(X3=u∣X2=t,X1=s)≤p(x3∣x2)≤max⁡s,t,up(X3=u∣X2=t,X1=s)(74)\min_{s,t,u} p(X_3=u\mid X_2=t,X_1=s) \le p(x_3\mid x_2) \le\max_{s,t,u} p(X_3=u\mid X_2=t,X_1=s) \tag*{(74)}

Note that min⁡s,t,up(X3=u∣X2=t,X1=s)\min_{s,t,u} p(X_3=u\mid X_2=t,X_1=s) is a constant and is a lower bound on p(x3∣x2)p(x_3\mid x_2) and that max⁡s,t,up(X3=u∣X2=t,X1=s)\max_{s,t,u} p(X_3=u\mid X_2=t,X_1=s) is a constant and an upper bound of p(x3∣x2)p(x_3\mid x_2).

Therefore,

min⁡s,t,up(X3=u∣X2=t,X1=s)≤min⁡u,tp(X3=u∣X2=t)≤max⁡u,tp(X3=u∣X2=t)≤max⁡s,t,up(X3=u∣X2=t,X1=s)(75)\begin{aligned} \min_{s,t,u} p(X_3=u\mid X_2=t,X_1=s) &\le\min_{u,t} p(X_3=u\mid X_2=t)\\ &\le\max_{u,t} p(X_3=u\mid X_2=t) \le\max_{s,t,u} p(X_3=u\mid X_2=t,X_1=s) \tag*{(75)} \end{aligned}

Thus the X1X_1 conditionals lower and upper bound the unconditional on X1X_1 probability, verifying Eq. (A.1).

To apply this result to Papprox(η):=∏t=1t=Tp(xt∣xt−1:η)P_{\mathrm{approx}}(\eta) := \prod_{t=1}^{t=T}p(x_t\mid x_{t-1:\eta}) (η=2,3,…,t−1\eta=2,3,\ldots,t-1) of Eq. (47), make the variable ‘mapping’:

x3→xt; X3→Xt=ux2→xt−1,xt−2,…,xη+1:=xt−1:η+1;Xt−1:η+1=wt−1:η+1x1→xη; X1→Xη=s.(76)\begin{aligned} x_3 &\to x_t; \ X_3 \to X_t=u\\ x_2 &\to x_{t-1},x_{t-2},\ldots,x_{\eta+1}:=x_{t-1:\eta+1}; \quad X_{t-1:\eta+1}=w_{t-1:\eta+1}\\ x_1 &\to x_\eta; \ X_1\to X_\eta=s. \tag*{(76)} \end{aligned}

From Eq. (A.10) and Eq. (A.1),

min⁡xt,xt−1:ηp(xt∣xt−1:η)≤min⁡xt,xt−1:η+1p(xt∣xt−1:η+1)≤max⁡xt,xt−1:η+1p(xt∣xt−1:η+1)≤max⁡xt,xt−1:ηp(xt∣xt−1:η).(77)\begin{aligned} \min_{x_t,x_{t-1:\eta}} p(x_t\mid x_{t-1:\eta}) &\le\min_{x_t,x_{t-1:\eta+1}} p(x_t\mid x_{t-1:\eta+1})\\ &\le\max_{x_t,x_{t-1:\eta+1}} p(x_t\mid x_{t-1:\eta+1}) \le\max_{x_t,x_{t-1:\eta}} p(x_t\mid x_{t-1:\eta}). \tag*{(77)} \end{aligned}

Applying the inequalities in Eq. (A.12) term-by-term to Papprox(η)P_{\mathrm{approx}}(\eta) (noting that any individual term in Eq. (A.12) satisfies p(xt∣xt−1:η)≤1p(x_t\mid x_{t-1:\eta})\le1) results in

min⁡Pexact=min⁡Papprox(1)≤min⁡Papprox(2)≤…≤min⁡Papprox(t−1)≤max⁡Papprox(t−1)≤…≤max⁡Papprox(2)≤max⁡Papprox(1)=max⁡Pexact,(78)\min P_{\mathrm{exact}}=\min P_{\mathrm{approx}}(1)\leq\min P_{\mathrm{approx}}(2)\leq\ldots\leq\min P_{\mathrm{approx}}(t-1)\\ \leq\max P_{\mathrm{approx}}(t-1)\leq\ldots\leq\max P_{\mathrm{approx}}(2)\leq\max P_{\mathrm{approx}}(1)=\max P_{\mathrm{exact}}, \tag*{(78)}

which is Eq. (52). While Eq. (A.13) is exact its evaluation would be non-trivial except for short sequence lengths. For longer lengths, methods such as beam search [19] can only approximate max⁡Papprox(η)\max P_{\mathrm{approx}}(\eta) and may violate these strict inequalities.

Acknowledgement

We thank Dr. Hongfeng Lou for the elegant proof of Eq. (A.1).

References

  1. [1]Mary Phuong and Marcus Hutter, “Formal Algorithms for Transformers”, arXiv:2207.09238v1 [cs.LG], (2022).arxiv.org/abs/2207.09238
  2. [2]Tiany​​ang Lin, Yuxin Wang, Xiangyang Liu, and Xipeng Qiu, “A Survey of Transformers”, arXiv:2106.04554v2 [cs.LG], (2021).arxiv.org/abs/2106.04554
  3. [3]Nelson Elhage, Neel Nanda, Catherine Olsson, Tom Henighan, Nicholas Joseph, Ben Mann, Amanda Askell, Yuntao Bai, Anna Chen, Tom Conerly, Nova DasSarma, Dawn Drain, Deep Ganguli, Zac Hatfield-Dodds, Danny Hernandez, Andy Jones, Jackson Kernion, Liane Lovitt, Kamal Ndousse, Dario Amodei, Tom Brown, Jack Clark, Jared Kaplan, Sam McCandlish, Chris Olah, “A Mathematical Framework for Transformer Circuits”, 12.22.2021. https://transformer-circuits.pub/2021/framework/index.html.
  4. [4]Thomas. M. Cover and Joy. A. Thomas, Elements of Information Theory John Wiley & Sons, New York (1991).
  5. [5]Alec Radford, Karthik Narasimhan, Tim Salimans, and Ilya Sutskever, “Improving Language Understanding by Generative Pre-Training”, OpenAI Blog (2018).
  6. [6]Robert I. Cukier, “Generating Intrinsically Disordered Protein Conformational Ensembles from a Database of Ramachandran Space Pair Residue Probabilities Using a Markov Chain”, J. Phys. Chem. B. 122, 9087 (2018).DOI
  7. [7]E. T. Jaynes, “Information Theory and Statistical Mechanics”, Phys. Rev. 106, 620 (1957)DOI
  8. [8]E.T. Jaynes, Where Do We Stand on Maximum Entropy? in R.D. Levine, Tribus, M. (Ed.), The Maximum Entropy Formalism, MIT Press, Cambridge, MA, USA, 1979.
  9. [9]E.T. Jaynes, Proc. IEEE 70, 939 (1982) .
  10. [10]Hongfeng Lou and Robert I. Cukier, “A maximum entropy principle approach to a joint probability model for sequences with known neighbor and next neighbor pair probabilities”, Chemical Physics 538, 110872 (2020).DOI
  11. [11]Robert I. Cukier, “Maximum Entropy Principle (MEP) methods for Large Language Model Inference” (unpublished work).
  12. [12]D.A. Knoll and D.E. Keyes “ Jacobian-free Newton–Krylov methods: a survey of approaches and applications” Journal of Computational Physics 193, 357 (2004).DOI
  13. [13]https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.newton_krylov.html
  14. [14]Xiang Lisa Li, Ari Holtzman, Daniel Fried, Percy Liang, Jason Eisner, Tatsunori Hashimoto, Luke Zettlemoyer, and Mike Lewis. "Contrastive decoding: Open-ended text generation as optimization." arXiv preprint arXiv:2210.15097 (2022).arxiv.org/abs/2210.15097
  15. [15]Xun Liang, Shichao Song, Zifan Zheng, Hanyu Wang, Qingchen Yu, Xunkai Li, Rong-Hua Li, Yi Wang, Zhonghao Wang, Feiyu Xiong, Zhiyu Li. "Internal consistency and self-feedback in large language models: A survey." arXiv preprint arXiv:2407.14507 (2024).arxiv.org/abs/2407.14507
  16. [16]Max Peeperkorn, Tom Kouwenhoven, Dan Brown, and Anna Jordanous. "Mind the gap: Conformative decoding to improve output diversity of instruction-tuned large language models." arXiv preprint arXiv:2507.20956 (2025).arxiv.org/abs/2507.20956
  17. [17]Sean O’Brien, Mike Lewis “Contrastive Decoding Improves Reasoning in Large Language Models” arXiv:2309.09117v2 [cs.CL] 2023
  18. [18]Xiaohan Xu, Ming Li, Chongyang Tao, Tao Shen, Reynold Cheng, Jinyang Li, Can Xu, Dacheng Tao, Tianyi Zhou. “A Survey on Knowledge Distillation of Large Language Models“ arXiv:2402.13116v4 [cs.CL] (2024).arxiv.org/abs/2402.13116
  19. [19]Alexander M. Rush, Sumit Chopra and Jason Weston, “A Neural Attention Model for Abstractive Sentence Summarization”, arXiv:1509.00685v2 [cs.CL] (2015).arxiv.org/abs/1509.00685

Paper details

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

views · 8

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