On attention heads and bilinear forms

4 Moments and the Gram form

Definition 8 Odd, even and resolvent statistics

For a vector \(\lambda \) with \(|\lambda _i|{\lt}1\), define

\[ O(\lambda )=\sum _i\frac{\lambda _i}{1-\lambda _i^2},\qquad E(\lambda )=\sum _i\frac{\lambda _i^2}{1-\lambda _i^2},\qquad R(\lambda )=\sum _i\frac1{1-\lambda _i}. \]

Every \(\lambda \in \Lambda _m\) has \(|\lambda _i|{\lt}1\). Writing \(n=2m\),

\[ O(\lambda )=\sum _{r=0}^{\infty }\sum _i\lambda _i^{2r+1},\qquad E(\lambda )=\sum _{r=0}^{\infty }\sum _i\lambda _i^{2r+2}, \]

and both series converge absolutely. Moreover,

\[ O=\tfrac 12(R-R\circ \iota ),\qquad n+E=\tfrac 12(R+R\circ \iota ),\qquad O\circ \iota =-O,\qquad E\circ \iota =E. \]

If a symmetric matrix \(A\) has spectrum \(\lambda \), with multiplicity, then

\[ O(\lambda )=\operatorname {tr}(A(I-A^2)^{-1}),\quad E(\lambda )=\operatorname {tr}(A^2(I-A^2)^{-1}),\quad R(\lambda )=\operatorname {tr}((I-A)^{-1}). \]
Proof

The unit-norm condition and the presence of both signs force each coordinate to have absolute value below one. Sum the convergent geometric series coordinatewise. Partial fractions and reversal of the coordinates give the identities involving \(\iota \). For the trace formulas, diagonalize \(A\) orthogonally and evaluate the rational functions on its eigenvalues.

For \(W_K,W_Q\in M_{n\times N}(\mathbb {R})\), set

\[ M=\begin{pmatrix} W_K \\ W_Q \end{pmatrix},\qquad G=MM^T,\qquad J=\begin{pmatrix} 0 & I_n \\ I_n & 0 \end{pmatrix}. \]

The symmetric part of \(W_K^TW_Q\) is \(S=\tfrac 12M^TJM\). For every \(k\ge 1\),

\[ \operatorname {tr}(S^k)=\operatorname {tr}((\tfrac 12JG)^k),\qquad \lVert S\rVert ^2=\tfrac 14\operatorname {tr}((JG)^2). \]

If \(M:\mathbb {R}^N\to \mathbb {R}^{2n}\) is surjective and \(n\ge 1\), the nonzero spectrum of \(S\), with multiplicity, is the spectrum of \(\tfrac 12JG\). Its sorted normalized nonzero spectrum \(\lambda \) exists uniquely and belongs to \(\Lambda _n\). For \(H=JG/(2\lVert S\rVert )\),

\[ O(\lambda )=\operatorname {tr}(H(I-H^2)^{-1}),\qquad E(\lambda )=\operatorname {tr}(H^2(I-H^2)^{-1}),\qquad R(\lambda )=\operatorname {tr}((I-H)^{-1}). \]
Proof

Block multiplication gives the factorization of \(S\); cyclicity of trace gives the power identities. Under surjectivity, \(G\) is positive definite. The characteristic-polynomial identity for rectangular products identifies the nonzero spectrum, including multiplicities. Congruence with \(J\) gives exactly \(n\) eigenvalues of each sign, so sorting and normalization yield a vector in \(\Lambda _n\). The matrix \(JG\) is similar to the symmetric matrix \(G^{1/2}JG^{1/2}\); evaluate the three rational functions on its real eigenvalues and take traces.