A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions:
                  Representation, Training, Generalization


                                          Muhammed Ustaomeroglu 1 Guannan Qu 1


                           Abstract                                reinforcement learning (Chen et al., 2021). Despite the
                                                                   success of attention, our formal understanding of its repre-
        Self-attention has emerged as a core component
                                                                   sentation, optimization, and generalization abilities is in its
        of modern neural architectures, yet its theoretical
                                                                   early stages.
        underpinnings remain elusive. In this paper, we
        study self-attention through the lens of interact-         Recent theoretical investigations illuminated Transformers’
        ing entities, ranging from agents in multi-agent           representational abilities/limitations (Liu et al., 2023; San-
        reinforcement learning to alleles in genetic se-           ford et al., 2023) and training dynamics (Ahn et al., 2023;
        quences, and show that a single layer linear self-         Jelassi et al., 2022; Gao et al., 2024) from different perspec-
        attention can efficiently represent, learn, and gen-       tives (e.g., language modeling, image patch classification,
        eralize functions capturing pairwise interactions,         in context learning, etc.). Despite this progress, current
        including out-of-distribution scenarios. Our anal-         theoretical frameworks exhibit critical limitations:
        ysis reveals that self-attention acts as a mutual
                                                                    (i) Existing analyses often target isolated problems, lack-
        interaction learner under minimal assumptions
                                                                        ing a unified perspective for characterizing Transform-
        on the diversity of interaction patterns observed
                                                                        ers’ capabilities across diverse domains. In contrast,
        during training, thereby encompassing a wide va-
                                                                        our theory makes an attempt to provide a unified per-
        riety of real-world domains. In addition, we vali-
                                                                        spective by assuming that the data comes from a mu-
        date our theoretical insights through experiments
                                                                        tual interaction model, which we show captures broad
        demonstrating that self-attention learns interac-
                                                                        applications.
        tion functions and generalizes across both pop-
        ulation distributions and out-of-distribution sce-         (ii) Most mathematically rigorous theories overlook test-
        narios. Building on our theories, we introduce                  time generalization, particularly robustness to out-of-
        HyperFeatureAttention, a novel neural network                   distribution (OOD) shifts. Our analysis addresses OOD
        module designed to learn couplings of different                 in terms of length generalization.
        feature-level interactions between entities. Fur-          (iii) Mathematically rigorous theories typically offer inter-
        thermore, we propose HyperAttention, a new mod-                  pretations only for the predetermined parameters. In
        ule that extends beyond pairwise interactions to                 contrast, our approach explains a broader set of param-
        capture multi-entity dependencies, such as three-                eters—many of which may initially appear unintuitive.
        way, four-way, or general n-way interactions.
                                                                   (iv) Generally, rigorous theories rely on restrictive assump-
                                                                        tions about model parameters. In contrast, our frame-
1. Introduction                                                         work does not impose such assumptions on the param-
                                                                        eters. Our approach only requires mild and possibly
Ever since the invention of Transformers (Vaswani et al.,               inevitable conditions on the data distribution -such as
2023), attention is the building block for many domains,                training data versatility.
spanning natural language processing (Brown et al., 2020;
Devlin et al., 2019), computer vision (Dosovitskiy et al.,         In this work, we adopt a interacting entities viewpoint to
2021), protein structure prediction (Jumper et al., 2021),         study self-attention, where each token represents an interact-
                                                                   ing entity (e.g., agents in multi-agent reinforcement learn-
    1
     Department of Electrical and Computer Engineering,            ing, particles in physical simulations, amino acids in pro-
Carnegie Mellon University, Pittsburgh, USA. Correspondence        tein sequences, or words in natural language). Specifically,
to: Muhammed Ustaomeroglu <mustaome@andrew.cmu.edu>.               we introduce a function that models interactions among
Proceedings of the 42 nd International Conference on Machine       these entities and demonstrate its applicability across di-
Learning, Vancouver, Canada. PMLR 267, 2025. Copyright 2025        verse domains, including the colliding agents environment,
by the author(s).                                                  genotype-phenotype mapping task, vision task, and time

                                                               1
                          A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

series prediction. Under this viewpoint, we prove that a                       • In Section 7, we provide experiments that validate our
single-layer linear self-attention can efficiently represent                     theoretical predictions with clear interpretation of the
such functions and show that gradient-descent training con-                      learned parameters.
verges to the parameters realizing these interactions, under                   • In Section 5, we introduce HyperFeatureAttention, a
mild assumptions on the data.12 In addition, we demon-                           novel mechanism designed to capture couplings of
strate versatility requirements on the train data such that the                  feature interactions. In Section 6, we present Hyper-
learned parameters generalize both to the test distribution                      Attention, which models higher-order dependencies
and to out-of-distribution (length generalization). By nei-                      between entities, such as three-way and four-way in-
ther imposing restrictive constraints on model parameters                        teractions. Also, we provide accompanying theoretical
nor limiting ourselves to particular domains, our framework                      analyses of these models’ capabilities. We also provide
unifies some diverse application scenarios and offers a novel                    some preliminary experiments on these novel models
theoretical lens on how Transformers learn dependencies                          in Section 7.
among multiple interacting entities.
                                                                            Related Works.
We further validate our theoretical insights on representation,
                                                                            Transformer Representation Theory. A large body of
convergence, and generalization through controlled exper-
                                                                            work has illuminated the representational abilities of self-
iments, demonstrating that the learned model parameters
                                                                            attention from various angles (Yao et al., 2023; Bhattamishra
closely align with theoretical predictions. Beyond analyzing
                                                                            et al., 2020a; Wei et al., 2023; Kajitsuka & Sato, 2024; Nath
attention patterns, we highlight how the parameters them-
                                                                            et al., 2024; Luo et al., 2022; Li et al., 2024). For instance,
selves can be directly interpreted to uncover meaningful
                                                                            Transformers have been shown to be Turing-complete and
interactions among entities.
                                                                            capable of simulating intricate sequential computations
Building on these insights, investigations confirm that self-               (Bhattamishra et al., 2020b), act as provably efficient “com-
attention excels at capturing mutual interactions between                   pilers” for domain-specific languages (Zhai et al., 2024),
entities. Motivated by this, we introduce two novel gener-                  and approximate key operators such as sparse or local aver-
alizations named (i) HyperFeatureAttention, for capturing                   aging with sublinear complexity (Likhosherstov et al., 2021;
couplings of different interactions between features of the                 Sanford et al., 2023; Edelman et al., 2022). Their abilities
entities, and (ii) HyperAttention, for capturing higher-order               and limitations have also been explored in POMDP settings
interactions (e.g. three-way or four-way) between entities.                 (Lu et al., 2024), automata-theoretic perspectives (Liu et al.,
Extending our single-layer analysis, we show that Hyper-                    2023), sequence-to-sequence tasks (Yun et al., 2020), and
FeatureAttention can efficiently represent the couplings of                 hidden Markov model learning scenarios (Hu et al., 2024).
feature interactions. In addition, we show that HyperAtten-
                                                                            Transformer Convergence Analysis. Parallel to the
tion can represent and learn higher order interactions, with
                                                                            progress on representation, another line of research has
the corresponding theories.
                                                                            investigated the convergence properties of training Trans-
We summarize our main contributions as follows:                             formers (Ahn et al., 2023; Tarzanagh et al., 2024; Li et al.,
                                                                            2023; Tian et al., 2023; Song et al., 2024; Huang et al.,
   • In Section 3, we present a unified perspective where
                                                                            2024a; Chen et al., 2024). These studies analyze train-
     each token (e.g., agent, amino acid, pixel patch) is
                                                                            ing via gradient flow in simplified yet insightful settings
     treated as an interacting entity, seamlessly bridging
                                                                            (Yang et al., 2024), establish conditions under which one
     several experimental settings.
                                                                            can efficiently learn multi-head attention layers (Chen & Li,
   • In Section 4, we show that gradient flow, on standard
                                                                            2024; Deora et al., 2023), or employ mean-field methods to
     mean squared error loss, converges to a solution that
                                                                            show global convergence in large-scale regimes (Gao et al.,
     captures how the entities interact. Furthermore, the
                                                                            2024). Additional works examine specialized domains such
     learned parameters generalize to both unseen exam-
                                                                            as masked visual pretraining (Huang et al., 2024b) and spa-
     ples from the task distribution and out of distribution
                                                                            tial structure learning (Jelassi et al., 2022), or investigate
     (varying sequence lengths), under suitable versatility
                                                                            sparse token selection tasks (Wang et al., 2024).
     conditions in the training data.
   1
                                                                            Despite the valuable insights offered by these studies, the
      If linear self-attention requires O(k) parameters to represent
                                                                            majority have all or some of the limitations, i.e. (i), (ii), (iii)
the interaction function, dense layer requires O(k ·L2 ) parameters.
    2
      We motivate this choice further in subsequent sections, but           we listed in the second paragraph of introduction.
briefly: linear self-attention preserves essential optimization prop-
erties of full Transformers while offering reduced computational
complexity and simplified theoretical analysis (Ahn et al., 2024),
                                                                            2. Preliminaries
making it ideal for theoretical investigations. A detailed discussion       Self-Attention. The self-attention mechanism is a core
of linear self-attention appears in Section 2.
                                                                            component of Transformers (Vaswani et al., 2023), enabling

                                                                        2
                         A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

models to learn dependencies between input tokens effec-               functions in context (Cheng et al., 2024). Furthermore, (Ahn
tively. For a sequence of L input tokens represented as a              et al., 2024) demonstrates that linear self-attention replicates
matrix X ∈ RL×d , the self-attention is defined as:                    key optimization dynamics of Transformers -such as heavy-
                                                                       tailed gradient noise and ill-conditioned loss landscapes-
                       XWQ (XWK )⊤
                                         
           σ
        SA (X) = σ            √              XWV ,                     without softmax or feedforward layers. This simplification
                                dk                                     retains the computational advantages of linearity while en-
                                                                       abling rigorous analysis of phenomena like adaptive opti-
where WQ , WK , WV ∈ Rd×dk are the learnable
                                       √     projec-                   mizer superiority (e.g., Adam over SGD) and gradient con-
tion matrices. Defining C = WQ (WK )⊤ / dk , we can                    vergence. Critically, insights from this abstraction extend to
write the same equation as                                             softmax-based Transformers, particularly in understanding
                                                                       optimization stability and generalization under varying data
             SAσ (X) = σ XCX⊤ XWV .
                                
                                                                       distributions or model depths (Ahn et al., 2024).
Since the introduction of attention mechanisms (Bahdanau               In the following sections, we explore the capabilities of
et al., 2016), the function σ : RL×L → RL×L has been                   linear self-attention across diverse tasks to illustrate its
predominantly implemented as a row-wise softmax opera-                 practical and theoretical value. By striking a balance be-
tion, where the input matrix to σ, commonly referred to as             tween tractability and expressiveness, linear self-attention
the attention scores, determines the relative importance of            offers a powerful framework for investigating and enhancing
different tokens in the sequence.                                      attention-based architectures.
Alternative Attention Functions. Recent advancements
have explored alternative σ functions beyond the tradi-                3. Representing Mutual Interactions with
tional softmax. One prominent direction is using linear                   Attention
self-attention mechanisms, which reduce the computational
complexity of self-attention from O(L2 ) to O(L). Lin-                 Consider a discrete finite domain (or “vocabulary”) S =
ear attention methods approximate the softmax function                 {α, β, γ, ω, . . . } with cardinality |S|. In our setting we have
while maintaining comparable performance in many tasks                 tuples of L elements (or sequences of length L) from the
(Katharopoulos et al., 2020; Choromanski et al., 2022). For            domain, denoted by X and entries of which are uniquely
instance, the Performer model introduces kernel-based meth-            indexed by the integers in [L]. Here, [i] denotes the set
ods to approximate the softmax operation efficiently, achiev-          {0, 1, . . . , i − 1} for any i ∈ Z+ . For each index i, we
ing scalability without significant loss in accuracy (Choro-           denote the corresponding element X (i) ∈ S. Thus, we
manski et al., 2022). Moreover, alternative activation func-           can write X = (X (0) , X (1) , . . . , X (L − 1)), which is
tions, such as ReLU, cosine, polynomial and sigmoid based              distributed according to X ∼ D. We also have tuples Y with
transformations, have been explored, showing competitive               elements from a corresponding relatively small set SY . The
or even superior performance compared to softmax in some               tuples are jointly distributed according to a task distribution
tasks (Koohpayegani & Pirsiavash, 2024; Kacham et al.,                 (X , Y) ∼ DX ×Y . In order to train a neural network, we
2024; Ramapuram et al., 2024).                                         map each element of S to a d-dimensional embedding space
                                                                       via a function x : S → Rd and each element of SY to
To simplify theoretical analysis while shedding light on a             a corresponding vector or a scalar depending on the task,
diverse range of self-attention implementations, we adopt              via the function y : SY → Rd2 . Additionally, we stack
a linear variant of self-attention, which preserves the core           the embeddings of the elements in X and Y as rows of
characteristics of self-attention through its reliance on atten-       X ∈ RL×d and Y ∈ RL×d2 matrices. We denote their
tion scores.                                                           distribution as (X, Y) ∼ PX×Y
Linear Self-Attention. Linear self-attention simplifies the            Our first result concerns self-attention’ the representation for
attention by omitting the σ operation, resulting in:                   mutual interactions, which we define below. We introduce
              SAlin (X) = XCX⊤ XWV .
                                    
                                                        (1)            a pairwise effect function. For α, β ∈ S, let f (α, β) ∈
                                                                       R measure how strongly entity β affects entity α, and let
Although omitting the σ operation may appear to be over-               wβ ∈ Rd2 represent how that influence is expressed. The
simplification, extensive theoretical and empirical studies            aggregated effect on the i-th entity, from all other entities,
confirm the power of linear self-attention. Notably, layers of         is
                                                                                             X                     
linear self-attention can implement gradient descent and pre-                     yX (i) =        f X (i) , X (j) wX (j) ,          (2)
conditioned gradient descent (von Oswald et al., 2023; Ahn                                   j∈[L]
et al., 2023). In addition, variants of softmax, ReLU, and
linear transformers (including the exact version used here)            capturing mutual interactions: each entity’s behavior or state
can perform functional gradient descent to learn nonlinear             depends on every other entity in the sequence.

                                                                   3
                          A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

Theorem 3.1 (Representation Ability of Linear Self-At-                    Appendix B.1, we can writej th agent’s effect on ith agent’s
tention). d = |S| is sufficient for a single-layer linear                 value function as, f ri −rj wrj , where wrj ∈ R is a scalar
self-attention to exactly represent any aggregate pairwise                weight and f depends only on their relative position. Then
interaction functions {yX (i) }Li=1 in Eq. 2 for all entities si-         we consider the value function of the i-th agent as
multaneously. Also, d ≥ |S| is necessary for a single layer
                                                                                                   L
linear self-attention to exactly represent any such functions.                                     X               
                                                                                          Vri =           f ri − rj wrj .
                                                  2
Consequently, self-attention requires Θ(|S| ) parameters                                           j̸=i
to capture the interactions. The key distinction, however,
lies in efficiency. The following theorem demonstrates that               In Appendix B.1, we illustrate how a reward of −1 per
self-attention is efficient compared to fully connected neural            distinct collision is captured by the value function above.
networks. This kind efficiency is one of the reasons we                   This function fits directly into (2), allowing a single-layer
contend that Transformers are mutual interaction learners,                linear self-attention to represent the multi-agent value func-
while generic fully connected architectures are not.                      tion, when discrete positions are encoded orthogonally. In
                                                                          addition in Appendix B.1 we show similar results for non-
Theorem 3.2 (Efficiency of Self-Attention). A linear fully
                                         2                                identical agents setting, too.
connected network requires Ω(L2 · |S| ) parameters to rep-
resent the aggregate pairwise interaction functions {yi }Li=1             Example 2 (Genotype-Phenotype Mapping Task). In
in Eq. 2 exactly, for all entities simultaneously.                        many genotype–phenotype models, a DNA sequence of
                                                                          length L is composed of alleles which we represent as
The proofs of Theorems 3.1 and 3.2 appear in Appendix B.                  X (i) ∈ S. Some alleles are always active, others’ acti-
Equation 2 and Theorem 3.1 underpin all later examples: the               vation level depends on the presence of certain alleles, and
same simple formula can model multi-agent rewards, pixel                  some remain inactive regardless of context (Frommlet et al.,
patterns, time-series signals, and genotype-phenotype rela-               2016). Formally, in a simplistic setting,
tions, showing that one self-attention layer already captures
rich pairwise dependencies.
                                                                            PX (i) = I {X (i) is always active}
A more practical interpretation of these results appears in                          X
                                                                                   +     I {X (i) is activated by X (j)} wX (j) ,
the context of deep neural networks with a modular per-
                                                                                       j∈[L]
spective. Learning algorithms, such as gradient descent
applied to a loss criterion, often lead to the emergence of               where PX (i) captures activeness of the gene at position i.
task specialization within small subcomponents of a large                 By orthogonally embedding each allele, Theorem 3.1 again
neural network. Specifically, individual neural network                   ensures a single-layer linear self-attention can replicate these
blocks naturally become responsible for particular subtasks               interactions exactly. For more details see the demonstrations
-a phenomenon studied in (Elhage et al., 2021; Cammarata                  at Appendix B.2.
et al., 2020). Our representation theorem formally demon-
strates that each self-attention block is indeed sufficiently             We illustrate the generality of our theory with several addi-
powerful to execute any mutual interaction task potentially               tional case studies, time-series prediction (Appendix B.4),
allocated to it within a deep neural network, so theoretically            a computer-vision task (Appendix B.3), and variants of
supporting the more empirical observations.                               the colliding-agent environment (Appendix B.1.3). Study-
                                                                          ing isolated single-layer self-attention models uncovers
We provide the details about this section in Appendix B                   component-level behaviors that directly inform the design
and provide convergence and generalization analyses in                    and optimization of deep Transformer architectures. This
Section 4. Finally, Section 7 presents empirical results that             mirrors the role of circuit theory in electrical engineering:
confirm our theoretical findings and provide interpretation               although large-scale designs rely on simulation and proto-
of the learned parameters.                                                typing, foundational insights about transistors, resistors, and
Example 1 (Colliding Agents Environment). In a multi-                     capacitors remain indispensable. Likewise, our block-level
agent system with L identical agents positioned in a dim-                 theory is a step toward a datasheet for self-attention units,
dimensional space, with position vectors ri ∈ Rdim (or                    helping steer the construction of deep Transformers. Full-
ri ∈ [N ]dim for a discrete setup). We aim to capture how                 network experiments remain vital, but a precise block-level
each agent’s value function Vri depends on other agents’                  theory focuses the design space and boosts the likelihood of
initial states (positions).3 Seeing that the system is transla-           success.
tionally and rotationally invariant, as explained detailly in             Why d = |S| While setting the embedding dimension d
   3
    In a reinforcement learning context, the value function Vri for       equal to the domain size |S| may be impractical for large
agent i typically denotes the expected return (sum of discounted          vocabularies, it simplifies our analysis without altering core
rewards) from a particular configuration.                                 insights. Our goal is to understand how self attention cap-

                                                                      4
                           A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

tures mutual interactions, and d = |S| ensures orthogo-                       linearly independent, as redundant patterns (e.g., fixed linear
nal domain embeddings, yielding an exact and transparent                      relationships between element counts) are highly unlikely
representation. Compressing to d < |S| is perpendicular                       under unstructured or randomized data. Moreover, if the
to this focus and can be addressed separately using stan-                     data distribution satisfies even milder assumption that the
dard techniques, such as Johnson-Lindenstrauss projections,                   covariance of s(n) is positive definite (Assumption
                                                                                                                                E.1), we
to approximate high-dimensional orthogonal embeddings.                        show in Theorem E.2 that P rank(SBµ ) < |S| ≤ e−γ|Bµ |
Starting with d = |S| allows us to establish clean, exact                     for some γ ∈ R, meaning Assumption 4.2 is satisfied with
theorems that elucidate how self-attention captures pairwise                  high probability.
interactions, while reducing to d < |S| merely introduces
a small approximation gap without altering the core theory.                   4.1. Convergence
For completeness, we provide an approximate version of
Theorem 3.1 in Appendix B (Theorem B.2).                                      In this section, we show that if the target function is repre-
                                                                              sentable by a single-layer linear self-attention model (as
                                                                              guaranteed by Theorem 3.1), then gradient descent on
4. Training and Generalization                                                LMSE (C, WV ) converges zero training error under mild
In this section, we analyze how a single layer linear self-                   conditions. It is stated below with proof in Appendix C.
attention can achieve zero training error and demonstrate                     Seeing that our main aim is studying the mutual interaction
its generalization guarantees under mild assumptions. We                      perspective, so the attention scores are the core component,
focus on learning mutual interaction functions of the form                    which is also the core mechanism defining self-attention,
(2), which, as ensured by Theorem 3.1, can be represented                     we choose d2 = 1 to simplify the convergence analysis.
by linear self-attention.                                                     Thus, WV is one dimensional which we denote as w in
                                          B                                 this subsection. Lastly, we denote wα = x(α)⊤ w for any
Setup and Notation. Let X(n) , Y(n) n=1 be the train-
                                      ∗                                       α ∈ S.
ing data, where (X(n) , Y(n) ) ∼ PX×Y
                                    L
                                          , for a specific L∗ ,
so in the training set all tuples have the same length L∗ .                   Assumption 4.3 (Weak Realizability). The task is realiz-
             ∀L
Also, let PX×Y     be the universal distribution that covers                  able, i.e, there exist C∗ and w∗ that perfectly fits the training
                                                                              data. That is, y(n) = X(n) C∗ X(n) ⊤ X(n) w∗ ∀n ∈ B.
                                                                                                                       
samples of any length. Throughout, we focus on the mean-
squared error (MSE) objective                                                 Theorem 4.4 (Convergence to Zero Training Error). Let
                                                                              the dimensions d = |S| and d2 = 1. Also, let the initial
                                B                     2
                          1 X                                                 parameters C(t=0) = 0, ⟨x (α) , w(t=0) ⟩ ≥ b > 0, ∀α ∈
LMSE C, WV                      SAlin    (n)
                                               − Y(n) ,
                                            
                     =            C,WV X
                          B n=1                                               S. Then, under the assumptions 4.2 and 4.3, gradient flow
                                                                              on LMSE C, w converges to zero training error.
We address three key questions: (1) Convergence: Under
what conditions does gradient flow reach zero training error?                 The realizability assumption decomposes into two parts: (i)
(2) Generalization: When does a perfect fit on the training                   the task genuinely involves mutual interactions, and (ii) the
                                            ∗
set imply zero error on new data from PXL ×Y ? (3) OOD                        data are noise-free. The second condition, analogous to
Generalization: Can such a model generalize to longer or                      fixing d = |S|, simplifies the presentation without alter-
shorter sequences than those seen in training?                                ing the core insight. Extending our results to noisy data
Definition 4.1 (Data Matrix for Element µ). Let Bµ as the                     is straightforward: in that setting, exact zero-error conver-
set of training indices that contain element µ ∈ S. Denoting                  gence is replaced by nonzero error bounds and probabilistic
the number of times an element µ appears in tuple X (n) as                    guarantees.4 We leave such generalizations to future work.
 (n)
sµ , we define the data matrix for element µ as
                                                                              4.2. Test Generalization
       h                        i⊤                             ⊤
s(n) = s(n)         (n)                     
        α       sβ        ...        , SBµ = . . .   s(n)   . . . n∈B .       Under training data versatility and strong realizability,
                                                                      µ
                                                                              achieving zero training error with linear self-attention im-
                  (n)                                                       plies perfect generalization to new data from the same dis-
In short, SBµ nν = sν , but for n such that µ ∈ X (n) .
                                                                              tribution. Moreover, under even milder assumptions, zero
Assumption 4.2 (Training Data Versatility). For all µ ∈ S,                    test error ensures generalization to unseen sequence lengths.
SBµ is full column rank.
                                                                              Assumption 4.5 (Strong Realizability). The task is strongly
This assumption is mild in practice. When elements in X             (n)       realizable, meaning there exist matrices C† and WV † such
are drawn from a diverse distribution (e.g., uniformly or with                that the model perfectly fits the underlying population dis-
                                               (n)
non-degenerate correlations), the counts {sν } for ν ∈ S                        4
                                                                                  Condition (ii) mirrors the simplification in Newton’s laws of
naturally vary. This ensures that the columns of SBµ remain                   motion, where measurement errors are simply neglected.

                                                                          5
                         A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

tribution at a fixed sequence length L∗ . Specifically, we          4.4. Discussion
assume that Y = XC† X⊤ XWV † holds almost surely
                  L∗                                                 Our theoretical findings in this section show that a single-
for (X, Y) ∼ PX×Y     .
                                                                     layer linear self-attention model not only converges to zero
Due to Theorem 3.1 and Appendix B, we can safely assume              training error but also generalizes to both unseen data and
strong realizability.                                                unseen sequence lengths. In Section 7, we present controlled
Theorem 4.6 (Generalization). Suppose Assumptions 4.2                experiments, confirming our convergence and generalization
and 4.5 hold, than zero training error forces (C, WV ) to            guarantees hold.
agree with (C† , WV † ) on (X, Y) ∼ PX×Y . That is, the              Building on the modular perspective introduced in Section
solution achieving zero training error also satisfies                3, we view a deep Transformer as a stack of self-contained
                                                                    blocks, each capable of shouldering a distinct subtask that
         E(X,Y)∼P L∗ fC,WV X − Y = 0.
                    X×Y                                              emerges during gradient-based optimization. Our analysis
Hence, it generalizes perfectly to new examples from the             shows that when a mutual-interaction subtask is delegated to
same distribution.                                                   a single-layer linear self-attention block, that block provably
                                                                     (i) converges to zero error for the subtask and (ii) general-
See Appendix D for the proof of Theorem 4.6.                         izes to unseen data and longer sequences. Earlier layer-wise
                                                                     results support this modular viewpoint. In deep linear net-
4.3. Out of Distribution (Length) Generalization                     works, (Shin, 2020) prove that block-coordinate (layer-by-
                                                                     layer) gradient descent reaches the same global optimum
A unique strength of self-attention is its ability to process
                                                                     as full end-to-end training, provided every hidden layer
sequences of variable length. In many tasks, we might train
                                                                     is at least as wide as the input and output. For nonlinear
on sequences of length L∗ yet hope to predict accurately on
                                                                     architectures, (Zeng et al., 2019) show that cyclic block-
sequences of different lengths L ̸= L∗ . To state our result
                                                                     coordinate descent converges to a stationary point at an
Theorem 4.8 (with proof in Appendix D.2) , we need the
                                                                     O(1/k) rate, and (Akiyama, 2024) recently extend global-
following assumption, which holds due to Theorem 3.1.
                                                                     minimum guarantees to networks with strictly monotone
Assumption 4.7 (Universal Realizability). The task is uni-           activations (and, with skip connections, to modified ReLU
versally realizable, meaning there exist matrices C∀L and            nets). Although these results do not yet cover soft-max
WV,∀L such that the model perfectly fits the population dis-         attention, they suggest that if each Transformer block can
                         lengths. Specifically, we assume
tribution for all sequence                                           provably master its assigned mutual-interaction task—as es-
that Y = XC∀L X⊤ XWV,∀L holds almost surely for                      tablished here for linear self-attention—then an alternating
(X, Y) ∼ PX∀L×Y .                                                    layer-wise schedule can, under suitable conditions, approach
Theorem 4.8 (Length Generalization). Under the Assump-               the performance of joint optimization. Our block-level theo-
                                                        L∗
tions 4.2 and 4.7, any C† , WV † that generalizes to PX×Y    ,       rem thus provides an “atomic” guarantee that future work
                      ∀L
must generalize to PX×Y    .                                         can build on to analyze full Transformer training.
Building on the proof of Theorem 4.8 (in Appendix D.2),              A key assumption throughout is training data versatility
we observe a key relationship between the matrices C and             (Assumption 4.2). Intuitively, this requires each element
WV , which underpins the model’s ability to generalize. We           in the domain to appear in sufficiently diverse contexts, en-
state this formally in the following corollary:                      suring the corresponding data matrix SBµ has full column
                                                                     rank. This richness is crucial for generalization, as it allows
                                                
Corollary     4.9. Two sets of parameters C1 , W1,V
 2
  C , W2,V lead to functionally equivalent linear self-              the model to learn meaningful interactions that extend be-
attention blocks if and only if they satisfy                         yond the training set. In realistic settings -where domain
                                                                     elements vary meaningfully (e.g., different agent configura-
       Tµ,k C1 , W1,V = Tµ,k C2 , W2,V , ∀µ, k,
                                             
                                                                     tions, protein sequences, or natural language tokens)- such
where                                                                rank deficiencies are unlikely. Consequently, data versatility
                   X                                                 ensures that the model not only fits the training data but also
                          x⊤ (µ) Cx (ν)       x⊤ (ν) W:,k .
                                                        
  Tµ,k (C, W) =                                                      generalizes effectively to new distributions and sequence
                   ν∈S
                                                                     lengths.
Consequently, if you apply the transformation Tµ,k to the
parameters, all of the sets of parameters that lead to func-
tionally equivalent linear self-attentions be mapped to a
                                                                     5. Extension to HyperFeatureAttention
specific matrix (over index µ, k) that depends on the func-          In the previous sections, we showed how self-attention
tion they represent. Thus, for a specific task all length            learns pairwise interactions between entities. However,
generalizing sets of parameters will lead to the same matrix         in practical scenarios, the entities µ ∈ S are not mono-
under this transformation.

                                                                 6
                         A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

lithic. In other words, they are composed of features.                   From the preceding discussion, Linear HyperFeatureAtten-
For instance, consider µ to be composed of M ∈ Z+                        tion requires only Θ(M ) embedding dimension and parame-
features, µ = (µϕ1 , . . . , µϕM ), where µϕi ∈ Sϕi , so                 ters to express (3). One may concern that in practice we use
S = Sϕ1 × . . . × SϕM .5 Those features may be the (red,                 layers of multi-head attention, which may possibly express
green, blue) components of an RGB pixel in an image or                   Eq. 3, without exponential embedding dimension. However,
(height, weight,...) characteristics of a person in a population         we showed in Remark F.6 that even two layer multihead
or something else depending on the contex. To illustrate how             linear self-attention cannot express (3). After all these mo-
the couplings of interactions between features are crucial,              tivations, we formally defined Multihead HyperFeatureAt-
let us revisit the colliding agents environment of Section 3,            tention in Appendix F.2. Also, a detailed comparison of
with modifications.6                                                     the new modules’ memory and computational requirements
                                                                         versus standard self-attention appears in Appendix H.
Colliding Agents Revisited. Assume the same setting as
before except now the agents are not identical. We need                  In short, similar to how self-attention generalizes dense lay-
labels for the agents ℓi ∈ Sℓ . Thus, each agent is composed             ers by enabling entity (token)-level interactions, HyperFea-
of two features xi = (ℓi , ri ). In Appendix F, we showed                tureAttention extends Self-Attention by enabling coupling
that for non-identical agents, it is natural to have the value           between the feature interactions. It enhances traditional
function of the form                                                     self-attention by allowing attentions to be coupled, which
                                     !                 !                 enables model to capture coupled feature level interactions.
         X Y                            Y
  Vi =              fa (ϕa,i , θa,j )        wa (γa,j ) , (3)
        j∈[L]   a∈A                      a∈A                             6. Extension to HyperAttention
where ϕa,i , θaj , γa,j are the corresponding features (label            Similar to pairwise interactions, some tasks may involve
or position) picked depending on the scenario and fa , wa                higher-order interactions, three-way four-way, n-way. Thus,
are some functions from features to real numbers.                        in a tuple X we may have µ ∈ S that is influenced by a
Here we provide a simplified illustration of how Hyper-                  composite function of ν and γ ∈ S. In this case, we would
FeatureAttention emerges from our theoretical framework;                 need our attention scores to be able to capture interaction
see Appendix F.1 for a detailed motivation. Seeing that                  functions of the form f (µ, ν, γ). From this need, we develop
|S| = |Sℓ ||Sr |, from Theorem 3.1, a linear self-attention re-          a novel generalization, named HyperAttention for capturing
quires d = Θ(|Sℓ ||Sr |), so Θ(|Sℓ |2 |Sr |2 ) parameters to rep-        higher-order interactions, alongside (Sanford et al., 2023;
resent (3). However, defining new attention matrices, C(h,a)             Alman & Song, 2023).8 Here we state third order and linear
for each fa , we can represent the corresponding function                version, please see Appendix G for the full version.
only with Θ(|Sℓ |2 ), Θ(|Sr |2 ), or Θ(|Sℓ ||Sℓ |) parameters            Definition 6.1 (Third order Linear HyperAttention).
depending on which features are used for fa . For example,                                           X
f (ℓi , ℓj ) requires Θ(|Sℓ |2 ) parameters. As a result, if there                  Aij1 j2 =                    Cαζ1 ζ2 Xiα Xj1 ζ1 Xj2 ζ2
are M features, self-attention would require embedding di-                                       α,ζ1 ,ζ2 ∈[d]
mension and number of parameters in Θ(exp(M )), while                                              X
                                                                                    Vj1 j2 τ =                 Xj1 ξ1 Xj2 ξ2 WξV1 ξ2 τ
defining attention for individual fa ’s only require Θ(M )
                                                                                                 ξ1 ,ξ2 ∈[d]
(see Appendix F for exact calculation).7 This brings us to                                           X
HyperFeatureAttention.                                                          HAlin
                                                                                  iτ (X) =                        Aij1 j2 Vj1 j2 τ ,
Definition 5.1 (Linear HyperFeatureAttention of order                                            1≤j1 ≤j2 ≤L

A ∈ Z+ ).
                                                                         where we denote (i, j, k)-th entry of a tensor T as Tijk and
                                                                         C ∈ Rd×d×d , WV ∈ Rd×d×d2 and Table H.
                                              
                  ⊙
                  Y                 ⊙
                                    Y
HFAlin (X) =         XC(a) X⊤        XWV,(a)  ,
                    a∈[A]                  a∈[A]                         Ternary Synergies in Multi-Agent Collaboration Imagine
      Q⊙                                                                 a multi-agent system in which each agent’s payoff depends
where       is Hadamard (element-wise) product between                   not just on pairwise interactions with other agents, but on
the matrices, and C(a) , WV,(a) ∈ Rd×d .                                 three-way synergies. For instance, suppose agent i gets re-
   5
                                                                         ward only if it forms an alliance with agents j and k, but
     Here, we do not assume knowledge of the features, we just
assume each entity have some features.                                       8
                                                                               There are small differences between our definition and their
   6
     For an easy transition to the following example we sug-             ((Sanford et al., 2023; Alman & Song, 2023)) definition be-
gest going over Appendix B.1 -without the subsections- and Ap-           cause the way we reached to the architecture is different. For
pendix B.1.3.                                                            instance, their formulation is a low-rank approximation that as-
   7
     For a more practical comparison of parameter counts with            sumes Vj1 j2 τ = Vj11 τ Vj22 τ . In contrast, our approach offers more
approximate represenations please refer to Remark F.1.                   representational capacity while maintaining comparable efficiency.

                                                                     7
                         A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

agents j and k does not form an alliance with each other. For-           on the initial states. We leverage Theorem 3.1 and show
mally, each agent i has a discrete state X (i) that inclues its          how this reward structure and the final value function can
strategic type or coalition membership. Whenever i, j, and               be exactly represented by a single layer linear self-attention.
k all share a compatible configuration of states, i gains an ad-        Under this setting, the final value function for each agent
ditional bonus. Concretely, define, f X (i) , X (j) , X (k) ,            can be expressed as
a ternary synergy function which is nonzero only when i, j,                           L
and k are all in an appropriate joint configuration (e.g. i is al-
                                                                                      X
                                                                                        I min nyi − nyj , N − nyi −nyj ≤ 2R
                                                                                                                     
                                                                           V ri = −
lied with j and k but j and k are not allied). Let wX (j),X (k)                       j̸=i
be a weight that captures how the pair (j, k) specifically con-                                                                    (4)
tributes to i’s reward under that triple configuration. Then             Seeing that the value function depends only on the y-
agent i’s total payoff takes the form:                                   coordinates, we focus our discussion on a one-dimensional
                X                                                       case for simplicity. The extension to value functions with
   VX (i) =            f X (i) , X (j) , X (k) wX (j),X (k) .            higher dimension dependence follows naturally and is illus-
            1≤j<k≤L
                                                                         trated in Appendix B.1. We trained linear self-attention, for
In this setup, standard pairwise interactions (as in ordinary            different embeddings one-hot and sinusoidal.9 It has an em-
self-attention) are insufficient to capture the triple compat-           bedding dimension of N and its parameters are initialized
ibility requirement. However, assigning each state X (·) a               as C(t=0) = 0, ⟨x (α) , w(t=0) ⟩, ∀α ∈ S.
suitable embedding enables encoding these ternary syner-                 One-Hot. We first use a one-hot embedding: each position
gies into a higher-order extension of (2), allowing the result-          n ∈ [N ] is represented by the standard basis vector en ∈
ing HyperAttention mechanism to learn how three agents                   RN . In Appendix B.1, we demonstrate how a single-layer
jointly influence each other’s rewards. We also provably                 linear self-attention with WV = −1N , and
explained how HyperAttention learns those higher order                               (
interactions in Appendix G.4.                                                          1, min(|m − n|, N − |m − n|) ≤ 2R,
                                                                            Cmn =                                               (5)
For an additional example illustrating the representational                            0, otherwise,
capabilities of HyperAttention, see Appendix G.2, where                  can exactly implement the value function in (4), irrespective
we analyze the “skip-trigram bug” (Elhage et al., 2021).                 of L, so all realizability assumptions are satisfied. Under
A potential concern is the O(L3 ) computational cost intro-              these, Theorem 4.4 predicts that the training mean squared
duced by the final equation in Definition 6.1, which may                 error (MSE) converges to zero, which matches our obser-
pose efficiency challenges for long sequences. Leverag-                  vations in practice. Furthermore, as the Theorems 4.6 and
ing techniques similar to those in (Katharopoulos et al.,                4.8 predict, we see generalization results: negligible er-
2020; Choromanski et al., 2022), we address this issue in                ror (Θ(10−7 )) on test sets both when L = 20 and when
Appendix G.3. Also, a detailed comparison of the new                     L ∈ {2, 5, 10, 30, 40} varies.
modules’ memory and computational requirements versus                    Sinusoidal. We next consider a sinusoidal embedding, in-
standard self-attention appears in Appendix H.                           spired by common positional encodings in attention models
                                                                         (Vaswani et al., 2023; Su et al., 2023). For even N , the
7. Experiments                                                           position ni of agent i is mapped to
                                                                               h 1                                
7.1. Experiments for the Theories                                                               2πk            2πk
                                                                         pi = √ , . . . , sin       ni , cos       ni , . . . ,
                                                                                  2              N              N
We empirically validate our linear-SA theories, i.e. repre-                                                          i
                                                                                                                                ⊤
                                                                          1        2π N                  1        2π N
sentation (Theorem 3.1), convergence (Theorem 4.4), and                  √ cos               − 1 ni , √ cos            ni         ∈ RN .
generalization (Theorem 4.6, Theorem 4.8) with the collid-                 2        N     2                2      N 2
ing agents environment.                                                  Note that pi ⊤pj = N2 δi,j . Due to Lemma B.4 and
Setup: Colliding Agents on a Cylindrical Grid. Consider                  Threorem B.6, a single layer linear self-attention with
                                                                                    √                    ⊤
                                                 [N ] × [N ],
L identical agents on a cylindrical grid of size                        WV,∀L = − 2 0 0 . . .                  ∈ RN ×1 and diagonal
with initial position vectors ri = nxi nyi ∈ [N ]2 , with                C∀L ∈ RN ×N , such that
wrap-around in y (cylinder). Each agent is modeled as a                               4
                                                                                            2R + 12
                                                                                                      
circle of radius R executes a simple “move-right” policy                              
                                                                                       N                             if µ = 0,
                                                                                       2 sin[ 2π             µ+1
                                                                                                  (      1
                                                                                                           )(      )]
                                                                                                   2R+
(one step to the right per time step if there is space to move,                                N         2      2
                                                                                                                      if µ odd,
                                                                               Cµµ = N        sin[ 2π 1 µ+1
                                                                                                    N 2 ( 2 )]
nxi < N − 1, otherwise stays where it is). Whenever agent                                                     µ
                                                                                       2 [N(  2π
                                                                                                         2 )( 2 )]
                                                                                                         1
                                                                                      
                                                                                         sin       2R+
i collides with agent j (distinct), it receives a penalty of                          
                                                                                        N     sin[ 2π 1 µ             if µ even,
                                                                                                    N 2 ( 2 )]
−1. Our goal is to capture how each agent’s final total
                                                                            9
accumulated reward, that is the value function Vi , depends                     Under L = 20, N = 360, and B = 100k.

                                                                     8
                          A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

    Model                           Order      Perplexity ↓               same embedding, MLP and optimiser settings (as in GPT3);
    Self-Attention                     –            62.28                 HFA has the same Θ(L2 ) time/space cost as SA, while HA
    HyperFeatureAttention              4            60.22                 (evaluated without low-rank tricks) scales as Θ(L3 ) in com-
    HyperAttention                     3            51.26                 putation. The tables report the final validation perplexities.
    HyperAttention (no sharing)        3            48.50                 The results support our claim that the flexibility with richer
                                                                          interaction blocks improve language-model quality.
Table 1. 1-layer, 1-head, 256-token window bencmark All mod-
els share GPT3-small hyper-parameters (dmodel =768, vocab size
50257, and identical optimiser settings). Training: 28 k itera-           8. Conclusion
tions, batch 0.16M tokens, cosine LR schedule with warm-up
(ηmax =6×10−4 , ηmin =0.1 ηmax ). Per-epoch validation perplexi-          We introduced a unifying theoretical framework that in-
ties are Gaussian-smoothed; final values are reported. SA and HFA         terprets tokens in self-attention as interacting entities and
have identical parameter counts and Θ(L2 ) compute; HA retains            showed that a single layer linear self-attention mechanism
the same parameter count but, without the low-rank trick, scales as       can capture pairwise interactions across a broad range of
Θ(L3 ). HA (no sharing) has slightly more parameters explained            domains. Our analysis clarified how self-attention learns
in Appendix G.                                                            and generalizes these interaction functions without relying
                                                                          on domain-specific assumptions. In particular, we proved
                                                                          that (i) such models converge under simple gradient-based
           Model     Heads / Order      Perplexity ↓
                                                                          training, (ii) they generalize to both unseen data, and vari-
           SA             3/2               28.70                         able sequence lengths when the training set is sufficiently
           HFA            3/3               27.97
           HFAv2     4/(2×2, 2×3)           27.75
                                                                          diverse
                                                                          Building on our theories for self-attention, we introduced
Table 2. 3-layer, 1024-token benchmark. Hyper-parameters and              novel HyperFeatureAttention and HyperAttention modules
optimiser settings match Table 1. HFA incurs < 0.1% extra com-            that extend self-attention’s abilities to capturing couplings
pute over SA due to attention products. The hybrid HFAv2 (2 SA
                                                                          of different feature level interactions and higher-order in-
heads + 2 order-3 HFA heads) attains the best perplexity.
                                                                          teractions among multiple entities. Beyond the theoretical
                                                                          guarantees, our language-modeling benchmarks show that
                                                                          both HFA and HA consistently achieve lower perplexity
can represent the value functions at Eq. 4 exactly, for any               than standard attention, confirming that their enhanced inter-
L, which is plotted at Figure 1. The entries of C are simply              action capacity translates into tangible performance gains.
Fourier transform of the interaction function, which is an
artifact of the sinusoidal embedding. Seeing that the same                Taken together, our theoretical and empirical findings es-
assumptions are satisfied for sinusoidal embedding, we ob-                tablish self-attention -and its HyperFeatureAttention and
serve the same convergence and generalization results for                 HyperAttention variants- as efficient learners of complex
sinusoidal embedding.                                                     entity interactions. Our language-modeling experiments
                                                                          confirm the feasibility of these modules, showing consis-
Although the results match the theorems, the learned pa-                  tent perplexity reductions under matched compute budgets.
rameters do not overlap with the parameters we originally                 A natural next step is to stress-test HFA and HA at larger
devised, especially for sinusoidal embedding, seen in Fig-                scales and in applications such as multi-agent control, pro-
ure 2 -these learned parameters lack an intuitive and easy                tein design, and the other scenarios motivated in this paper.
interpretation. However, as discussed in Corollary 4.9, this              We hope this interaction-centric lens spurs the creation of
outcome is a natural consequence of the generalization theo-              even more adaptable attention architectures and motivates
ries (Theorems 4.6 and 4.8). Therefore, we focus on the ma-               deeper analyses of softmax attention, stacked transformer
trices we get under the nontrivial transformation explained               layers, and emerging attention mechanisms.
in 4.9. As shown in Figures 3 and 4, these matrices are
                from the theoretical counterparts. With
indistinguishable
only Θ 10−4 mean square distance between their entries.
Thus, the parameters we get from training are functionally
equivalent to the length generalizing parameters we devised.

7.2. Experiments for the Novel Modules
To verify that the theoretical benefits of our layers translate
into practice, we ran two small-scale next-token-prediction
benchmarks on OpenWebText under hyperparameter parity
with GPT3-small, see Tables 1 and 2. All models share the

                                                                      9
                       A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

Acknowledgements                                                       languages, 2020a. URL http://arxiv.org/abs/
                                                                       2009.11264.
This research was supported by NSF Grants 2154171, CA-
REER Award 2339112, CMU CyLab Seed Funding.                          Bhattamishra, S., Patel, A., and Goyal, N. On the Com-
                                                                       putational Power of Transformers and its Implications
Impact Statement                                                       in Sequence Modeling, October 2020b. URL http://
                                                                       arxiv.org/abs/2006.09286. arXiv:2006.09286
This work advances the theoretical understanding of self-              [cs].
attention and its generalizations -HyperFeatureAttention
and HyperAttention- by providing a unifying framework                Brown, T., Mann, B., Ryder, N., Subbiah, M., Kaplan,
for learning complex interactions. Our insights could ben-             J. D., Dhariwal, P., Neelakantan, A., Shyam, P., Sastry,
efit diverse applications, including NLP, computer vision,             G., Askell, A., Agarwal, S., Herbert-Voss, A., Krueger,
multi-agent systems, and scientific modeling. Improved                 G., Henighan, T., Child, R., Ramesh, A., Ziegler, D.,
interpretability and training efficiency may enhance model             Wu, J., Winter, C., Hesse, C., Chen, M., Sigler, E.,
reliability and user trust.                                            Litwin, M., Gray, S., Chess, B., Clark, J., Berner,
                                                                       C., McCandlish, S., Radford, A., Sutskever, I., and
While theoretical, our findings could indirectly impact real-          Amodei, D. Language Models are Few-Shot Learn-
world risks, such as biased decision-making or misuse in               ers. In Advances in Neural Information Processing
misinformation and surveillance. Mitigating such risks re-             Systems, volume 33, pp. 1877–1901. Curran Asso-
quires policy measures rather than changes to fundamental              ciates, Inc., 2020. URL https://proceedings.
theory. Additionally, optimizing attention mechanisms may              neurips.cc/paper/2020/hash/
contribute to more efficient models, reducing the environ-             1457c0d6bfcb4967418bfb8ac142f64a-Abstract.
mental footprint of large-scale training. Overall, this work           html.
presents no unique societal risks beyond typical concerns in
machine learning research.                                           Cammarata, N., Carter, S., Goh, G., Olah, C., Petrov, M.,
                                                                       Schubert, L., Voss, C., Egan, B., and Lim, S. K. Thread:
                                                                       Circuits. Distill, 2020. doi: 10.23915/distill.00024.
References                                                             https://distill.pub/2020/circuits.
Ahn, K., Cheng, X., Daneshmand, H., and Sra,
  S. Transformers learn to implement preconditioned                  Chen, L., Lu, K., Rajeswaran, A., Lee, K., Grover, A.,
  gradient descent for in-context learning, Novem-                     Laskin, M., Abbeel, P., Srinivas, A., and Mordatch, I.
  ber 2023. URL http://arxiv.org/abs/2306.                             Decision Transformer: Reinforcement Learning via Se-
  00297. arXiv:2306.00297 [cs].                                        quence Modeling, June 2021. URL http://arxiv.
                                                                       org/abs/2106.01345. arXiv:2106.01345 [cs].
Ahn, K., Cheng, X., Song, M., Yun, C., Jadbabaie, A.,
                                                                     Chen, S. and Li, Y. Provably learning a multi-head at-
  and Sra, S. Linear attention is (maybe) all you need (to
                                                                       tention layer, February 2024. URL http://arxiv.
  understand transformer optimization). arXiv preprint
                                                                       org/abs/2402.04084. arXiv:2402.04084 [cs, stat].
  arXiv:2310.01082, 2024. URL https://arxiv.
  org/abs/2310.01082.                                                Chen, S., Sheen, H., Wang, T., and Yang, Z. Training
                                                                       dynamics of multi-head softmax attention for in-context
Akiyama, S. Block coordinate descent for neural networks               learning: Emergence, convergence, and optimality. arXiv
  provably finds global minima. 2024. URL https://                     preprint arXiv:2402.19442, 2024.
  openreview.net/forum?id=n2RIkaf1S4.
                                                                     Cheng, X., Chen, Y., and Sra, S. Transformers imple-
Alman, J. and Song, Z. How to Capture Higher-order                     ment functional gradient descent to learn non-linear
  Correlations? Generalizing Matrix Softmax Attention                  functions in context. In Proceedings of the 41st In-
  to Kronecker Computation, October 2023. URL https:                   ternational Conference on Machine Learning, volume
  //arxiv.org/abs/2310.04064v1.                                        235 of Proceedings of Machine Learning Research, pp.
                                                                       8002–8037. PMLR, July 2024. doi: 10.48550/arXiv.
Bahdanau, D., Cho, K., and Bengio, Y. Neural Machine                   2312.06528. URL https://proceedings.mlr.
  Translation by Jointly Learning to Align and Translate,              press/v235/cheng24a.html. arXiv:2312.06528
  May 2016. URL http://arxiv.org/abs/1409.                             [cs.LG].
  0473. arXiv:1409.0473 [cs].
                                                                     Choromanski, K., Likhosherstov, V., Dohan, D., Song,
Bhattamishra, S., Ahuja, K., and Goyal, N. On the abil-                X., Gane, A., Sarlos, T., Hawkins, P., Davis, J., Mo-
  ity and limitations of transformers to recognize formal              hiuddin, A., Kaiser, L., Belanger, D., Colwell, L., and

                                                                10
                       A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

  Weller, A. Rethinking Attention with Performers, Novem-          Huang, Y., Wen, Z., Chi, Y., and Liang, Y. How Trans-
  ber 2022. URL http://arxiv.org/abs/2009.                           formers Learn Diverse Attention Correlations in Masked
  14794. arXiv:2009.14794 [cs].                                     Vision Pretraining. 2024b.
Deora, P., Ghaderi, R., Taheri, H., and Thrampoulidis, C.          Jelassi, S., Sander, M. E., and Li, Y.          Vision
  On the Optimization and Generalization of Multi-head               Transformers provably learn spatial structure, Octo-
  Attention, October 2023. URL http://arxiv.org/                      ber 2022. URL http://arxiv.org/abs/2210.
  abs/2310.12680. arXiv:2310.12680 [cs, math, stat].                  09221. arXiv:2210.09221 [cs].
Devlin, J., Chang, M.-W., Lee, K., and Toutanova, K.               Jensen, H. J.     Complexity Science: The Study
  BERT: Pre-training of Deep Bidirectional Transformers              of Emergence.       Higher Education from Cam-
  for Language Understanding, May 2019. URL http://                  bridge   University    Press,   November       2022.
  arxiv.org/abs/1810.04805. arXiv:1810.04805                         doi:   10.1017/9781108873710.       URL https:
  [cs].                                                              //www.cambridge.org/highereducation/
                                                                     books/complexity-science/
Dosovitskiy, A., Beyer, L., Kolesnikov, A., Weissenborn,
                                                                     E0761D26BDAB25D75C6AB868AECE2F2D. ISBN:
  D., Zhai, X., Unterthiner, T., Dehghani, M., Minderer,
                                                                     9781108873710, Publisher: Cambridge University Press.
  M., Heigold, G., Gelly, S., Uszkoreit, J., and Houlsby,
  N. An Image is Worth 16x16 Words: Transformers for               Jumper, J., Evans, R., Pritzel, A., Green, T., Figurnov, M.,
  Image Recognition at Scale, June 2021. URL http://                 Ronneberger, O., Tunyasuvunakool, K., Bates, R., Žı́dek,
  arxiv.org/abs/2010.11929. arXiv:2010.11929                         A., Potapenko, A., Bridgland, A., Meyer, C., Kohl, S.
  [cs].                                                              A. A., Ballard, A. J., Cowie, A., Romera-Paredes, B.,
Edelman, B. L., Goel, S., Kakade, S., and Zhang, C. In-              Nikolov, S., Jain, R., Adler, J., Back, T., Petersen, S.,
  ductive Biases and Variable Creation in Self-Attention             Reiman, D., Clancy, E., Zielinski, M., Steinegger, M.,
  Mechanisms, June 2022. URL http://arxiv.org/                       Pacholska, M., Berghammer, T., Bodenstein, S., Sil-
  abs/2110.10090. arXiv:2110.10090 [cs, stat].                       ver, D., Vinyals, O., Senior, A. W., Kavukcuoglu, K.,
                                                                     Kohli, P., and Hassabis, D. Highly accurate protein struc-
Elhage, N., Nanda, N., Olsson, C., Henighan, T., Joseph,             ture prediction with AlphaFold. Nature, 596(7873):583–
  N., Mann, B., Askell, A., Bai, Y., Chen, A., Conerly,              589, August 2021. ISSN 1476-4687. doi: 10.1038/
  T., DasSarma, N., Drain, D., Ganguli, D., Hatfield-                s41586-021-03819-2. URL https://www.nature.
  Dodds, Z., Hernandez, D., Jones, A., Kernion, J., Lovitt,          com/articles/s41586-021-03819-2.                     Pub-
  L., Ndousse, K., Amodei, D., Brown, T., Clark, J.,                 lisher: Nature Publishing Group.
  Kaplan, J., McCandlish, S., and Olah, C. A math-
  ematical framework for transformer circuits. Trans-              Kacham, P., Mirrokni, V., and Zhong, P. PolySketch-
  former Circuits Thread, 2021. https://transformer-                 Former: Fast Transformers via Sketching Polynomial
  circuits.pub/2021/framework/index.html.                            Kernels, March 2024. URL http://arxiv.org/
                                                                     abs/2310.01655. arXiv:2310.01655 [cs].
Frommlet, F., Bogdan, M., and Ramsey, D. Phenotypes
  and Genotypes: The Search for Influential Genes, vol-            Kajitsuka, T. and Sato, I. Are transformers with one layer
  ume 18 of Computational Biology. Springer, 2016. ISBN              self-attention using low-rank weight matrices universal
  978-1-4471-5309-2. doi: 10.1007/978-1-4471-5310-8.                 approximators? In International Conference on Learning
  URL https://link.springer.com/book/10.                             Representations (ICLR), 2024.
  1007/978-1-4471-5310-8.
                                                                   Katharopoulos, A., Vyas, A., Pappas, N., and Fleuret,
Gao, C., Cao, Y., Li, Z., He, Y., Wang, M., Liu, H., Klu-            F. Transformers are RNNs: Fast Autoregressive Trans-
  sowski, J. M., and Fan, J. Global convergence in train-            formers with Linear Attention. Proceedings of Machine
  ing large-scale transformers. In Proceedings of the 38th           Learning Research, August 2020. doi: 10.48550/arXiv.
  Conference on Neural Information Processing Systems                2006.16236. URL http://arxiv.org/abs/2006.
 (NeurIPS 2024), 2024.                                               16236. arXiv:2006.16236 [cs].

Hu, J., Liu, Q., and Jin, C. On Limitation of Transformer          Koohpayegani, S. A. and Pirsiavash, H. SimA: Sim-
  for Learning HMMs, June 2024. URL http://arxiv.                    ple Softmax-free Attention for Vision Transformers,
  org/abs/2406.04089. arXiv:2406.04089 [cs].                         March 2024.     URL http://arxiv.org/abs/
                                                                     2206.08898. arXiv:2206.08898 [cs].
Huang, Y., Cheng, Y., and Liang, Y. In-context convergence
  of transformers. In Proceedings of the 41st International        Li, H., Wang, M., Liu, S., and Chen, P.-y. A theoreti-
  Conference on Machine Learning (ICML). PMLR, 2024a.                cal understanding of shallow vision transformers: Learn-

                                                              11
                       A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

  ing, generalization, and sample complexity, 2023. URL                arxiv.org/abs/2104.09864. Available at http:
  http://arxiv.org/abs/2302.06015.                                     //arxiv.org/abs/2104.09864.

Li, S., Song, Z., Xia, Y., Yu, T., and Zhou, T. The closeness        Tarzanagh, D. A., Li, Y., Thrampoulidis, C., and Oymak,
   of in-context learning and weight shifting for softmax              S. Transformers as support vector machines, 2024. URL
   regression. arXiv preprint arXiv:2304.13276, 2024.                  http://arxiv.org/abs/2308.16898.

Likhosherstov, V., Choromanski, K., and Weller, A.                   Tian, Y., Wang, Y., Chen, B., and Du, S. Scan and snap:
  On the Expressive Power of Self-Attention Matrices,                  Understanding training dynamics and token composition
  June 2021. URL http://arxiv.org/abs/2106.                            in 1-layer transformer, 2023. URL http://arxiv.
  03764. arXiv:2106.03764 [cs].                                        org/abs/2305.16380.

Liu, B., Ash, J. T., Goel, S., Krishnamurthy, A., and                Tropp, J. A. An introduction to matrix concentration in-
  Zhang, C. Transformers Learn Shortcuts to Automata,                  equalities, 2015. URL https://arxiv.org/abs/
  May 2023. URL http://arxiv.org/abs/2210.                             1501.01571.
  10749. arXiv:2210.10749 [cs, stat].                                Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones,
Lu, C., Shi, R., Liu, Y., Hu, K., Du, S. S., and Xu,                   L., Gomez, A. N., Kaiser, L., and Polosukhin, I. Attention
  H. Rethinking Transformers in Solving POMDPs,                        Is All You Need, August 2023. URL http://arxiv.
  May 2024. URL http://arxiv.org/abs/2405.                             org/abs/1706.03762. arXiv:1706.03762 [cs].
  17358. arXiv:2405.17358 [cs].                                      von Oswald, J., Niklasson, E., Randazzo, E., Sacramento,
                                                                       J., Mordvintsev, A., Zhmoginov, A., and Vladymy-
Luo, S., Li, S., Zheng, S., Liu, T.-Y., Wang, L., and He, D.
                                                                       rov, M. Transformers learn in-context by gradient de-
  Your transformer may not be as powerful as you expect.
                                                                       scent, 2023. URL http://arxiv.org/abs/2212.
  In Advances in Neural Information Processing Systems
                                                                       07677. arXiv preprint arXiv:2212.07677.
  (NeurIPS), 2022.
                                                                     Wang, S., Li, B. Z., Khabsa, M., Fang, H., and Ma,
Nath, S., Khadilkar, H., and Bhattacharyya, P. Transform-
                                                                      H. Linformer: Self-Attention with Linear Complexity,
  ers are expressive, but are they expressive enough for
                                                                      June 2020. URL http://arxiv.org/abs/2006.
  regression? arXiv preprint arXiv:2402.15478, 2024.
                                                                      04768. arXiv:2006.04768 [cs].
Ramapuram, J., Danieli, F., Dhekane, E., Weers, F., Bus-             Wang, Z., Wei, S., Hsu, D., and Lee, J. D. Transform-
  bridge, D., Ablin, P., Likhomanenko, T., Digani, J.,                ers Provably Learn Sparse Token Selection While Fully-
  Gu, Z., Shidani, A., and Webb, R. Theory, Analysis,                 Connected Nets Cannot, June 2024. URL http://
  and Best Practices for Sigmoid Self-Attention, Septem-              arxiv.org/abs/2406.06893. arXiv:2406.06893
  ber 2024. URL http://arxiv.org/abs/2409.                            [cs, math, stat].
  04431. arXiv:2409.04431 [cs].
                                                                     Wei, C., Chen, Y., and Ma, T. Statistically meaning-
Sanford, C., Hsu, D., and Telgarsky, M. Representa-                   ful approximation: a case study on approximating tur-
  tional Strengths and Limitations of Transformers, Novem-            ing machines with transformers, 2023. URL http:
  ber 2023. URL http://arxiv.org/abs/2306.                            //arxiv.org/abs/2107.13163.
  02896. arXiv:2306.02896 [cs, stat].
                                                                     Yang, H., Kailkhura, B., Wang, Z., and Liang, Y. Train-
Shin, Y. Effects of depth, width, and initialization: A con-           ing Dynamics of Transformers to Recognize Word
  vergence analysis of layer-wise training for deep linear             Co-occurrence via Gradient Flow Analysis, Octo-
  neural networks. arXiv, 2020. doi: 10.48550/arXiv.                   ber 2024. URL http://arxiv.org/abs/2410.
  1910.05874. URL http://arxiv.org/abs/1910.                           09605. arXiv:2410.09605.
  05874.
                                                                     Yao, S., Peng, B., Papadimitriou, C., and Narasimhan, K.
Song, B., Han, B., Zhang, S., Ding, J., and Hong, M. Un-               Self-attention networks can process bounded hierarchical
  raveling the gradient descent dynamics of transformers.              languages, 2023. URL http://arxiv.org/abs/
  In Advances in Neural Information Processing Systems                 2105.11115.
  (NeurIPS), 2024.
                                                                     Yun, C., Bhojanapalli, S., Rawat, A. S., Reddi, S. J.,
Su, J., Lu, Y., Pan, S., Murtadha, A., Wen, B., and Liu, Y.            and Kumar, S. Are Transformers universal approx-
  RoFormer: Enhanced Transformer with Rotary Position                  imators of sequence-to-sequence functions?, Febru-
  Embedding. arXiv preprint arXiv:2104.09864, November                 ary 2020. URL http://arxiv.org/abs/1912.
  2023. doi: 10.48550/arXiv.2104.09864. URL http://                    10077. arXiv:1912.10077 [cs, stat].

                                                                12
                       A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

Zeng, J., Lau, T. T.-K., Lin, S., and Yao, Y. Global conver-
  gence of block coordinate descent in deep learning, 2019.
  URL http://arxiv.org/abs/1803.00225.
Zhai, X., Zhou, R., Zhang, L., and Du, S. S. Trans-
  formers are Efficient Compilers, Provably, Octo-
  ber 2024. URL http://arxiv.org/abs/2410.
  14706. arXiv:2410.14706 [cs].




                                                               13
                        A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

A. Notation and Definitions
Consider a discrete domain (or “vocabulary”) S = {α, β, γ, ω, . . . } with cardinality |S|. In our setting we have tuples of L
elements (sequences of length L) from the domain, denoted by X and entries of which are uniquely indexed by the integers
in [L]. Here, [i] denotes the set {0, 1, . . . , i−1} for any i ∈ Z+ , positive integer. We define the function, X : [L] → S assign
each index i to the corresponding element X (i) ∈ S. Thus, we can write X = (X (0) , X (1) , . . . , X (L − 1)), which is
distributed according to X ∼ D. We also have tuples Y, length of which depends on the specific task we have, with elements
from a corresponding relatively small set SY . The tuples are distributed according to a task distribution (X , Y) ∼ DX ×Y .
                                                                                                                          ∀L
When needed we use DL and DX      L
                                    ×Y to denote the same distributions for specifically tuple length of L. Similarly, D    means
                                                                                                                (n)   (n)
the distribution covering all possible lengths. In our training dataset, we have B such pairs that X , Y                  ∼ DX ×Y ,
which are uniquely indexed by the elements in the set B = [B]. We also define, Bµ as the set of training indices that contain
                                                                                                 (n)
the element µ. We denote the number of times an element µ appears in tuple X (n) as sµ . We define the corresponding
        h                    i⊤                                  ⊤                                           ⊤
s(n) = s(n)        (n)                                                                     
           α     sβ     . . . , S = s(1) s(2) . . . s(B)            ∈ RB×N and SBµ = . . . s(n) . . . n∈B matrices.
                                                                                                               µ


In order to train a neural network, we map each element of S to a d-dimensional embedding space via a function x : S → Rd
and each element of SY to a corresponding vector or a scalar depending on the task. We can now define the domain
embedding matrix                                            ⊤ 
                                                             x (α)
                                                           x⊤ (β)
                                                     B=            .                                                 (6)
                                                                 ..
                                                                  .
Additionally, we stack the embeddings of the elements in X and Y as rows of X ∈ RL×d and Y ∈ RL×d2 matrices, which
                                                L
we say are distributed according to (X, Y) ∼ PX×Y   . For training sample n it can be written as,

                                                        x⊤ (X (0))        x⊤
                                                                           
                                                                            0
                                                       x⊤ (X (1))     x⊤
                                                                       1 
                                                                              
                                            X=                       =  ..  ,
                                              
                                                            ..
                                                            .         . 
                                               x⊤ (X (L − 1))                   x⊤
                                                                                 L−1
                                                                                       
where in the last equality we denote the embedding of the i-th element as xi := x X (i) ∈ Rd , to reduce the notational
cluttering.
We denote matrices and vectors by bold characters. Let M ∈ Rd1 ×d2 , w ∈ Rd be any matrix and vector respectively. We
denote k-th row of a M as Mk,: or mk , similarly we denote k-th column as M:,k or mk . We denote k-th entry of m as mk
and (k, l)-th entry of M as Mkl . Similarly, if a vector is defined in terms of blocks we explicity state it and denote each the
                                ⊤
blocks as w = w1⊤ w2⊤ . . . . The same notations naturally extend to tensors, e.g., we denote (i, j, k, . . . )-th entry of
                

a tensor T ∈ Rd×d×d×... as Tijk... .
In addition we denote ith eigenvalue of a matrix M as λi (M), where λ1 (M) ≥ λ2 (M) ≥ . . .. Similarly we denote the
ith singular value as σi (M). Lastly we have some operators diagonalization
                                                                        
                                                           w1
                                             diag (w) = 
                                                               ..       
                                                                   .     
                                                                            wd

and Kronecker product of two matrices A ∈ Rm×n , B ∈ Rp×q

                                                                                      
                                                a11 B           a12 B    ...     a1n B
                                               a21 B           a22 B    ...     a2n B 
                                         A⊗B = .                                  ..  ,
                                                                                      
                                                                  ..     ..
                                               ..                 .        .       . 
                                                      am1 B    am2 B     ...     amn B

where each entry aij in A is multiplied by the entire matrix B, which results in a matrix of size (mp) × (nq).

                                                               14
                        A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

B. Representation Abilities of Linear Self-Attention
Proof of Theorem 3.1 (Representation Ability of Linear Self Attention). We first show sufficiency of d = |S|. We can
define an orthonormal embedding x : S → RN such that

                                              x(α)⊤ x(β) = δα,β             ∀ a, b ∈ S,

where δa,b is the Kronecker delta. Recall that (X , Y) ∼ DX ×Y are tuples whose elements are indexed from the set [L].
         that we let s : [L] → S map each index i to its corresponding symbol X (i) ∈ S. We arrange the embeddings
Also, recall
x X (i) row-wise into X ∈ RL×|S| .
Goal. We wish to represent the family of functions
                                          X                  
                              yX (i) =        f X (i) , X (j) w X (j) ,             for each i ∈ [L],
                                           j∈[L]

using a single-layer linear self-attention of dimension d = |S|. Here, f : S × S → R measures how strongly one entity
affects another, and w X (j) ∈ Rd2 encodes how that influence is expressed (e.g., a direction vector or contribution to a
subsequent feature).
Recall that a single-layer linear self-attention can be written as

                                             Attnlin (X) =     X C X⊤ X W V ,
                                                                     

where C ∈ Rd×d captures the attention scores (keys × queries) in a linear setting, WV ∈ Rd×d2 represents the values
transformation.
Constructing C and V. We define C and WV to satisfy:

                                  x(α)⊤ C x(β) = f (α, β),           and x(a)⊤ WV = wa .

Such C and V exist because, {x(a)}a∈S forms an orthonormal basis in Rd , due to d = |S|. Concretely, C can be chosen so
that its bilinear form on basis vectors x(α), x(β) equals f (α, β). Likewise, WV can be chosen so that x(α) maps to wa .
Verification. Given a sequence of length L, the matrix X ∈ RL×|S| is
                                                               ⊤ 
                                                         x X (0)
                                                               ⊤ 
                                                       x X (1)
                                                                     
                                                                      
                                               X =                   .
                                                            ..       
                                                      
                                                             .       
                                                                      
                                                                   ⊤
                                                       x X (L − 1)

Thus,                                                                                                  
                                     f X (0) , X (0)                 ···        f X (0) , X (L − 1)
                         X C X⊤ =          ..                       ..                   ..
                                                                                                             ,
                                                                                                            
                                             .                         .                  .             
                                   f X (L − 1) , X (0)               ···     f X (L − 1) , X (L − 1)
and
                                                                      ⊤
                                                                     wX
                                                                               
                                                                        (0)
                                                           w⊤       
                                                               X (1) 
                                                   X WV = 
                                                          
                                                                     .
                                                               ..   
                                                                .   
                                                           wX (L−1)⊤
Multiplying these terms in the linear self-attention expression yields, for each row i ∈ [L]:
                                                        L−1
                                                        X
                                      X C X⊤ X WV i,: =
                                                                        
                                                            f X (i) , X (j) wX (j) .
                                                                j=0


                                                              15
                        A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions
                                        P                        
This matches the desired function Fi = j∈[L] f X (i) , X (j) wX (j) . Hence, a single-layer linear self-attention with
dimension |S| can represent any pairwise interaction function of this form.
Now, we focus on necessity of d ≥ |S|. Remember, f : S × S → R represent any pairwise interaction function. For fixed
embeddings {x(a) ∈ Rd }a∈S and any matrix C ∈ Rd×d , the product X C X⊤ is at most rank d. Formally, if we stack all
dictionary embeddings x(a) into a matrix X ∈ R|S|×d , then

                                                   rank(X C X⊤ ) ≤ d.

Thus, any pairwise function f (a, b) = x(a)⊤ C x(b) produces an |S| × |S| matrix with rank at most d.
Consider the pairwise function f ∗ (a, b) whose corresponding matrix F ∗ ∈ R|S|×|S| is full-rank, i.e., rank(F ∗ ) = |S|. For
example, take F ∗ = I|S| (the identity matrix), corresponding to f ∗ (a, b) = δa,b (the Kronecker delta).
If d < |S|, then any matrix X C X⊤ has rank ≤ d and hence cannot equal F ∗ , which has rank(F ∗ ) = |S| > d. Therefore,
the self-attention mechanism cannot represent f ∗ (a, b) exactly when d < |S|.
Since a single-layer linear self-attention mechanism of dimension d < |S| cannot represent the full-rank function f ∗ , it
follows that d ≥ |S| is necessary to exactly represent all pairwise functions f (a, b).

                                                                    2
As a consequence of the above Theorem, it requires O(|S| ) parameters to exactly represent any such sequence to
sequence interaction mapping seen in (2). Further, the output dimension, d2 , plays a largely peripheral role in the self-
attention mechanism’s ability to capture pairwise interactions. Its primary function is to align with the desired output
representation—whether it be the dimensionality of subsequent features or the final embedding size —without restricting
the expressiveness of the attention scores. The latter is dictated by setting d = |S|, ensuring that all necessary pairwise
interactions f (α, β) can be effectively captured. Thus, d2 should not be viewed as a bottleneck; it is simply a design choice
for how the represented interactions are ultimately projected or stored.
Corollary B.1 (Orthogonal Transforms Preserve Representational Capacity). Under d = |S|, let x(α) be the orthonormal
embedding constructed therein. For any orthogonal matrix Q ∈ Rd×d , define the new embedding x′ (α) = Q x(α). Then
the same pairwise function f (α, β) can be represented exactly by redefining

                                        C′ = Q C Q ⊤         and        W′V = Q WV .

Hence, any orthonormal transformation of x(α) leaves the representational capacity of the single-layer linear self-attention
unchanged. Since the construction in the Proof of Threorem 3.1 (in Appendix B) relies only on the orthogonality of x(α),
the same argument applies to any embedding x′ (α) = Q x(α) with Q ∈ Rd×d orthogonal. Thus, representational capacity
is invariant to the choice of orthonormal basis.

Proof of Theorem 3.2 (Efficiency of Linear Self Attention). We count the minimum number of parameters needed for a fully
connected network.
                                                                            2
Step 1: Because f (α, β) can be chosen arbitrarily for each of the |S| ordered pairs (α, β), the model must be able to
                    2
realize at least |S| independent scalar parameters to represent f itself.
Step 2: For a fixed position i, the quantity
                                                      L
                                                      X                    
                                           yX (i) =         f X (i) , X (j) wX (j)
                                                      j=1


sums over j = 1, . . . , L. Although there may be some degeneracies as f (X (i) , X (j)) wX (j) = f (X (i) , X (k)) wX (k)
for some j, k, or f (X (i) , X (j)) wX (j) + f (X (i) , X (k)) wX (k) = (f (X (i) , X (m)) wX (m) + f (X (i) , X (l)) wX (l) ,
that reduces the total number of parameters, we analyze the most general case. In the most general case, each
f (X (i) , X (j)) wX (j) in the summation should be calculated separately. Seeing that there are L such terms in the
summation, a fully connected network with no build-in parameter sharing cannot collapse these L terms at no cost. Each
summand could be different and must be learned with its own parameters. Hence, even for representing one output yX (i) ,
                              2
the network needs Ω(L · |S| ) .

                                                               16
                          A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

Step 3: The network must simultaneously produce yX (1) , . . . , yX (l) . Without additional structure or shared weights across
output positions, a fully connected network pays a separate parameter cost for each output yX (i) .
Therefore, any linear fully connected network that realizes all such pairwise interaction mappings with zero error must have
                 2
at least Ω(L2 |S| ) parameters.
Theorem B.2 (Approximate Representation Abilities of Single-Layer Linear Self-Attention). Recall S is a finite set and
f : S × S → R is any pairwise interaction function. For each symbol µ ∈ S, recall that wµ ∈ Rd2 is (value) representation.
Suppose the embedding dimension is less than the domain size, d ≤ |S|. Then, there exist an embedding x : S → Rd , and
parameters C ∈ Rd×d and WV ∈ Rd×d2 for a single-layer linear self-attention mechanism such that, for any sequence
s : [L] → S, the output of the linear self-attention block

                                               SAlin (X) = XCX⊤ XWV ,
                                                                  
                                                                                                                       (7)

approximates the “pairwise-sum” mapping
                                                         L−1
                                                         X                    
                                              yX (i) =         f X (i) , X (j) wX (j) ,                                          (8)
                                                         j=0

such that for all, i = 0, 1, . . . , L − 1,
                                              
                                              ζ1 Lσd+1 (F) ,
                                                                                                      d2 ≤ d < |S|
                                                                  qP
                         lin                                          d2     2
                      ∥SAi,: (X) − yX (i) ∥2 ≤ ζ1 Lσd+1 (F) + ζ2 L    i=d+1 σi (W),                    d < d2 < |S|
                                              
                                                                  q P|S|
                                                ζ1 Lσd+1 (F) + ζ2 L          2                         d < |S| ≤ d2 ,
                                                                      i=d+1 σi (W).
                                              


where ζ1 = maxµ∈S ∥wµ ∥2 , ζ2 = maxµ, ν∈S C̃µν and σi (F) is i-th singular value of F such that σ1 (F) ≥ σ2 (F) ≥
· · · ≥ σ|S| (F).

Proof. Recall B is the embedding matrix seen in (6). Form an |S| × |S| matrix F such that Fµν = f (µ, ν) ∀µ, ν ∈ S.
We have C ∈ Rd×d , so
                                             C̃ := BCBT ∈ R|S|×|S|
is an arbitrary matrix of rank at most d. Similarly, let W ∈ R|S|×d2 such that Wµ,: = wµ , and W̃V := BWV ∈ R|S|×d2 .
Thus, for each i ∈ [L], we can write,
                                       X                               X
                            yX (i) =        f X (i) , X (j) w X (j) =        FX (i),X (j) WX (j),:               (9)
                                          j∈[L]                                   j∈[L]


As d ≤ |S| and we can freely choose the embedding, we can choose the embedding such that the embedding base is
orthonormal, i.e. B⊤ B = I, we can write
                                                                                              L−1
                                                                                              X
                                   ⊤                     ⊤           ⊤     ⊤      ⊤
                    SAlin
                      i,: = Xi,: CX XW
                                       V
                                                  = Xi,: B BCB BX XB BW =                 V                         V
                                                                                                    C̃X (i),X (j) W̃X (j),: .   (10)
                                                                                              j=0

We start the approximation by writing the singular value decomposition of F as
                                                               |S|
                                                               X
                                                         F=          σi (F)ui vi⊤ ,
                                                               i=1


where σi (F) is i-th singular value of F such that σ1 (F) ≥ σ2 (F) ≥ · · · ≥ σ|S| (F). We can set C̃ to

                                                               d
                                                               X
                                                      C̃ =           σi (F)ui vi⊤ ,
                                                               i=1

                                                                     17
                       A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

which satisfies the only constraint we have on C̃, that it is of rank d. Consequently,
                                                                 |S|
                                                                 X
                                                     F − C̃ =              σi (F)ui vi⊤
                                                                i=d+1

From classical linear algebra we get

                                          max |Fi,j − C̃i,j | ≤ ||F − C̃||2 = σd+1 (F).                                               (11)
                                            ij



We can choose W̃V to minimize ∥W̃V − W∥2 . Note that the only constraint on W̃V is it of rank at most min(d, d2 ),
because W̃V = BWV where WV ∈ Rd×d2 can be freely chosen and B ∈ R|S|×d is full column rank. Therefore, there
exists a W̃V such that ∥W̃V − W∥2 is upper bounded by the min(d, d2 ) + 1’st largest singular value of W. Then, using
the identity ∥A∥2 ≤ ∥A∥2 for any A matrix,
                                   s       X
                                      max     (W̃ij − Wij )2 ≤ ∥W̃V − W∥2 ,
                                                 i
                                                     j


we have,                                                      
                            s                                 
                                                              0,                             d2 ≤ d < |S|
                                                              qP
                                                              d2
                                      X
                                                                     2                        d < d2 < |S|
                                max      (W̃ijV − Wij )2 ≤    i=d+1 σi (W),                                                           (12)
                                 i                         q
                                       j                    P|S|
                                                                    2
                                                              i=d+1 σi (W).                   d < |S| ≤ d2

Returning to Equations 9 and 10, the error can be written as
                               L−1
                               Xn                                                         o
           SAlin
             i,: − yX (i) =
                                                      V
                                      C̃X (i),X (j) W̃X (j),: − FX (i),X (j) WX (j),:
                               j=0
                               L−1
                               X n                                                                              o
                                                                                               V
                           =           C̃X (i),X (j) − FX (i),X (j) WX (j),: + C̃X (i),X (j) W̃X (j),: − W X (j),:
                               j=0
                               L−1
                               Xn                                                                                                 o
       ∥SAlin
          i,: − yX (i) ∥2 ≤           C̃X (i),X (j) − FX (i),X (j)        WX (j),: 2 + C̃X (i),X (j)     V
                                                                                                       W̃X (j),: − WX (j),:
                                                                                                                              2
                               j=0


Letting ζ1 = maxµ∈S ∥wµ ∥2 , ζ2 = maxµ, ν∈S C̃µν substituting Equations 11 and 12,

                                          L−1
                                          X
                 ∥SAlin
                    i,: − yX (i) ∥2 ≤            σd+1 (F) WX (j),: 2 + C̃X (i),X (j)             V
                                                                                               W̃X (j),: − WX (j),:
                                                                                                                      2
                                           j=0
                                        
                                        ζ1 Lσd+1 (F) ,
                                                                            d2 ≤ d < |S|
                                                            qP
                                                               d2
                                       ≤ ζ1 Lσd+1 (F) + ζ2 L         σ (W), d < d2 < |S|
                                                            qPi=d+1 i
                                                              |S|
                                         ζ1 Lσd+1 (F) + ζ2 L   i=d+1 σi (W), d < |S| ≤ d2
                                        




Justification for the d = |S| Assumption. A common concern may arise from our theoretical results, which assume the
embedding dimension d equals the domain size |S|. While this may seem restrictive for large vocabularies, this assumption
is well-motivated for the following reasons:

   • Clarifying the Core Mechanism and Simplifying Analysis. Our primary goal is to study how self-attention
     models interactions between entities, independent of embedding dimension constraints. Setting d = |S| ensures an

                                                                     18
                        A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

     exact orthonormal representation, making both representational power and training dynamics fully transparent. This
     choice highlights the fundamental ability of self-attention to encode all pairwise interactions while simplifying the
     theoretical analysis without losing generality. By removing extraneous complexities, we preserve the core insights into
     representation, convergence, and generalization.
   • Establishing a Natural Theoretical Baseline. The assumption d = |S| serves as an idealized yet expressive starting
     point in theoretical analysis, providing a one-to-one mapping from domain elements to embeddings. This eliminates
     unnecessary confounding factors, allowing a clean study of self-attention’s structural properties. Future work can
     systematically extend these results to cases where d < |S|, exploring compressed or approximate embeddings.
   • Scalability to Lower Dimensions. Although we analyze d = |S|, our insights extend to d < |S| through approximate
     orthonormal embeddings. Techniques such as random projections (e.g., via the Johnson–Lindenstrauss lemma) allow
     for efficient lower-dimensional embeddings while preserving essential properties. Thus, our results remain applicable
     in practical settings with small approximation errors.

In summary, the d = |S| assumption is a deliberate choice to make our analysis transparent and tractable, enabling exact
theorems that clarify the core design principles of self-attention. While not always practical, the insights gained from this
assumption shed light on why self-attention mechanisms are so effective in learning interactions, thereby paving the way for
future research on more approximate and scalable extensions.

Overview and Motivation of the Following Examples In this appendix, we present several illustrative examples that
showcase how single-layer linear self-attention can capture important pairwise interactions across diverse domains: multi-
agent collision settings, time series forecasting, genotype-phenotype mapping, simple vision tasks, and more. Although
there exist many possible configurations, we focus on relatively straightforward, yet representative cases that make it clear
how to embed domain-specific features into our theoretical framework.

B.1. Colliding Agents Environment
We consider L identical agents on a cylindrical grid of size [N ] × [N ], with initial position vector ri = nxi nyi ∈ [N ]2 ,
                                                                                                                     

where y axis is looped, that is, the distance between nyi = 1 and nyi = N − 1 is just 2. An analogy for such a grid world is
that ants moving on the surface of a water pipe. Each agent is modeled as a circle of radius R executes a simple “move-right”
policy (one step to the right per time step if there is space to move, nxi < N − 1, otherwise stays where it is). We denote the
value function for agent i as Vi , which corresponds to the expected return (sum of discounted rewards) from a particular
configuration.Our goal is to capture how each agent’s value function Vi depends on the initial states (positions) of other
agents: whenever agent i collides with agent j (distinct), it receives a penalty of −1. Leveraging Theorem 3.1, we show how
this reward structure (and hence the value function if continuing in time) can be exactly represented by a single-layer linear
self-attention mechanism.
Under this setting, adding −1 bias to all value functions for simplicity, the value function for each agent can be expressed as
                                      X
                                           I{min nyi − nyj , N − nyi − nyj ≤ 2R} · (−1)
                                                                                 
                              Vri =                                                                                        (13)
                                     j∈[L]
                                      j̸=i

Seeing that the value function depends only on the y-coordinates, we focus our discussion on a one-dimensional case for
simplicity. The extension to value functions with higher dimension dependence follows naturally and is illustrated after the
one-dimensional case discussed here. In addition, we provide two versions of the similar representation construction for
different positional embeddings.

B.1.1. O NE -H OT E MBEDDING
One of the most straightforward approaches is to embed each agent’s position ni ∈ [N ] as the standard basis vector
eni ∈ RN . Concretely, ni -th entry of eni is one and the rest are zeros. This guarantees e⊤
                                                                                           ni enj = δni ,nj , making the
embedding orthonormal.

Representing the Collision Value Function. By Theorem 3.1, there exists a single-layer linear self-attention model
(dimension d = N ) that encodes the collision-based value function Vi via an appropriate choice of C ∈ RN ×N and

                                                              19
                             A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

WV ∈ RN ×1 . To represent the value function in Eq. (13) using a single-layer linear self-attention mechanism, we explicitly
construct the attention weight matrix C and value projection matrix WV . Define WV ∈ RN ×1 as a vector of all −1s:
                                                                                                 ⊤
                                              WV = −1N = −1
                                                        
                                                                                −1    ...      −1 .                                                (14)

This ensures that the output of self-attention sums over the interactions weighted by C. The interaction matrix C ∈ RN ×N
is defined to capture the penalty for collisions:
                                             (
                                               1, if min(|m − n|, N − |m − n|) ≤ 2R,
                                    Cmn =                                                                             (15)
                                               0, otherwise.

Here, Cmn = 1 whenever the y-coordinates m and n are within a radius of 2R, accounting for cylindrical wrapping. The
resulting attention computation effectively sums over all nearby agents within the collision range.

B.1.2. S INUSOIDAL E MBEDDING
We now consider sinusoidal embeddings, inspired by various positional embedding techniques that leverage sinusoidal
representations. These include absolute positional embeddings from (Vaswani et al., 2023) and the more recent rotational
embeddings in (Su et al., 2023). Specifically, assuming N is an even number, we embed the position of the i-th agent as:
                   h                                                                                                                     i ⊤
                       √1                2πk               2πk                    √1 cos     2π   N                    √1 cos   2π N
                                                                                                                
  x (ri ) = pi =         2
                             ...   sin    N ni       cos    N ni        ...         2        N    2 −1        ni         2      N 2 ni          ∈ RN .
                                                                                                                                                   (16)
It is a simple exercise to check that pi ⊤pj = N2 δi,j
The main result of this section is that: due to Lemma B.4 and Threorem B.6, a single layer linear self-attention 1 with
       √                  ⊤
WV = − 2 0 0 . . . ∈ RN ×1 and diagonal C ∈ RN ×N , such that
                                                 4             1
                                                                  
                                                  N 2R + 2
                                                 
                                                                         n+1
                                                                                             if n = 0,
                                                          N (2R+ 2 )( 2 )]
                                                  2 sin[ 2π
                                                                   1

                                            Cnn = N      sin[ 2π  1 n+1                      if n odd,
                                                               N 2 (   2 )]
                                                     sin[ 2π ( 2R+ 12 )( n2 )]
                                                 
                                                   2
                                                         N
                                                                                             if n even,
                                                 
                                                 
                                                   N     sin[ 2π
                                                               N 2 ( 2 )]
                                                                  1 n



can represent the value functions at Eq. (13) exactly, for any L, which is plotted at Figure 1.
Definition B.3 (Discrete-Time Fourier Series (DTFS)). DTFS of a function f : [N ] → R is defined as
                                                                   N −1
                                                                                      2π
                                                                   X
                                                        F [k] =              f [n]e−j N kn .
                                                                    n=0

Lemma B.4 (Discrete-Time Fourier Series Expansion of Window Function). Let f be:

                                                            f [n] = I [|n| ≤ 2R]

Then the DFS, F is:                                      
                                                                  N (2R+ 2 )k ]
                                                          1 sin[ 2π       1
                                                                                            if k ̸= 0
                                                           N     sin[ N 2 k]
                                                                      2π 1
                                                 F [k] =
                                                          2 2R + 1                        if k = 0
                                                           N           2


Proof. Straightforward.
Lemma B.5 (Real Valued, i.e. Sinusoidal, Expression of Discrete-Time Fourier Series). The Discrete Fourier Series (DFS)
of a periodic discrete function x[n] with period N is given by:
                                                                    N −1
                                                                                     2π
                                                                    X
                                                           x[n] =            X[k]ei N kn
                                                                       k=0

                                                                         20
                         A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

        0.12
        0.10
        0.08
        0.06
 Cnn
        0.04
        0.02
        0.00
        0.02

                     0      30       60       90       120       150    180      210      240      270     300      330
                                                                  Matrix Index n

Figure 1. Diagonal entries of the interaction matrix C for N = 360 agents with radius R = 5. The pattern emerges from Fourier analysis
of collision dynamics in the agent movement model. The matrix indices are from 0 to N − 1.



Letting ak = 2 Re{X[k]} and bk = −2 Im{X[k]}, the same function can be expressed as

                          N −1
                     
                            2                                
                     
                      a0
                          X               2π               2π
                     2 +        ak cos      kn + bk sin      kn                                            , for odd N
                     
                     
                                          N                N
                     
            x[n] =            k=1
                                              NX
                                                 2 −1                                
                     
                      a0   aN/2       2π N                      2π                 2π
                          +      cos        n  +        a  cos      kn   + b  sin      kn   , for even N
                     
                     
                     
                     2                                  k                  k
                             2         N 2                       N                  N
                                                         k=1


Proof. Using Euler’s formula, the complex exponential term can be rewritten as:
                                                                           
                                        i 2π kn         2π              2π
                                      e   N     = cos      kn + i sin      kn
                                                        N               N

Substitute this expression into the DTFS equation:
                                              N −1                                
                                              X                 2π              2π
                                     x[n] =          X[k] cos      kn + i sin      kn
                                                                N               N
                                              k=0

Separate the real and imaginary parts of the equation:
                                     N −1                                          
                                     X                    2π                     2π
                             x[n] =       Re{X[k]} cos       kn − Im{X[k]} sin      kn
                                                          N                      N
                                    k=0
                                     N −1                                           
                                     X                     2π                     2π
                                  +i        Im{X[k]} cos      kn + Re{X[k]} sin      kn
                                                           N                      N
                                       k=0

x[n] is a real function, so the imaginary part sums to zero. Therefore, for odd N we have:

   • Im{X[0]} = 0

   • Im{X[k]} + Im{X[N − k]} = 0 because cosine function has period of π

                                                                  21
                        A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

  • Re{X[k]} − Re{X[N − k]} = 0 because sine function has period of π

As for the even N we have an additional requirement:

  • Im{X[N/2]} = 0

Thus x[n] for odd N is:
                                          N −1
                                          X2                                                           
                                                                            2π                       2π
                    x[n] = Re{X[0]} +             2 Re{X[k]} cos               kn − 2 Im{X[k]} sin      kn    ,
                                                                            N                        N
                                          k=1

As for even N we have:

                  x[n] = Re{X[0]} + Re{X[N/2]}(−1)n
                                    N
                                    2 −1                                               
                                    X                       2π                       2π
                                  +        2 Re{X[k]} cos      kn − 2 Im{X[k]} sin      kn    ,
                                                            N                        N
                                          k=1


Letting ak = 2 Re{X[k]} and bk = −2 Im{X[k]}, we get the final form as:

                           N −1
                    
                             2                                
                    
                     a0
                           X               2π                2π
                         +       a   cos      kn  + b  sin      kn                                        , for odd N
                    
                                   k                 k
                    
                    2
                    
                                           N                 N
           x[n] =           k=1
                                      NX
                                         2 −1                               
                    
                     a0 aN/2    2π N                    2π               2π
                     2 + 2 cos N 2 n +         ak cos      kn + bk sin      kn                           , for even N
                    
                    
                    
                                                         N                N
                                                         k=1




Theorem B.6. Let us denote DTFS of a function f [n] as F [k]. Defining ak = 2 Re{F [k]} and bk = −2 Im{F [k]} a
attention score matrix C of the form
                                                                                                  
                                      a0
                                     
                                                a1     b1                                         
                                                                                                   
                                     
                                                −b1    a1                                         
                                                                                                   
                                   C=
                                                            ..                                    ,
                                                                                                   
                                                                                                                         (17)
                                                                 .                                
                                     
                                                                     aN/2−1       bN/2−1          
                                                                                                   
                                                                     −bN/2−1      aN/2−1          
                                                                                            aN/2

can represent any function f [ni − nj ] = pi CpTj , where pi is given at Eq. (16).


Proof. Setting C as in (17),

                                                           NX
                                                              2 −1                               
                           a0   aN/2                 2π N                     2π               2π
                 pi CpTj =    +      cos                  n +        ak cos      kn + bk sin      kn    .
                               2      2              N 2                      N                N
                                                                      k=1


That is equal to f [n] owing to Lemma B.5,

Remark B.7. If f is symmetric, then the corresponding C is diagonal.

                                                                      22
                        A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

B.1.3. M ORE C OMPLEX C OLLIDING AGENTS E NVIRONMENTS
Value Functions That Depend on Both Coordinates. Assume the same basic grid setup described earlier, but now
suppose each agent’s value function depends on both coordinates. A trivial example is when agents receive huge penalties
−10 if they collide even though initially they are far away, i.e, dist(ni , nj ) ≥ R2 for some R2 ∈ R and any dist(·) function.
They receive small −1 penalties, if initially they are very close, so escaping from the collision is difficult. Thus, the value
function becomes                     X
                            Vi = −        I{|nyi − nyj | ≤ 2R} · (1 + 9 · I{dist(ni , nj ) ≤ R2 }) ,
                                      j̸=i

where the x-coordinate condition encodes temporal proximity. This value function, along with similar ones, can be expressed
in a general form as follows. Consider L agents on a two-dimensional [N ] × [N ] grid, with each agent i occupying a cell at
                                    ⊤
integer coordinates ri = nxi nyi
                           
                                        ∈ [N ]2 . Each agent’s value function is then influenced by pairwise interactions of
the form                            X                         X
                                                                   f nxi − nxj , nyi − nyj wrj ,
                                                                                         
                             Vi =        f ri − rj wrj =
                                    j∈[L]                              j∈[L]
                                     j̸=i                               j̸=i

where f : [N ]2 → R measures how agent j (via its relative position) influences agent i. To represent f exactly as a linear
self-attention kernel (as in Theorem 3.1), we embed each 2D position ri into a vector of dimension N 2 , defined by the
Kronecker (outer) product
                                                                                   2
                                                    pi = pxi ⊗ pyi ∈ R N .
Here, pxi , pyi ∈ RN are the 1D sinusoidal embeddings from Equation (16), applied separately to the x- and y-coordinates.
                                                        N2
By construction, {pi }Li=1 spans an orthogonal set in R    , with one vector per distinct grid cell.

From 1D to 2D Discrete-Time Fourier Series. Recall from Lemma B.4 and Theorem B.6 that any function g(n) on a 1D
grid [N ] can be written as p⊤
                             i C pj for a suitably chosen matrix C. Precisely the same reasoning applies in two dimensions
via a 2D Discrete-Time Fourier Series (DTFS). Specifically, one writes

                                                         N −1 N −1
                                                         X    X                 2π     kx (nx   x        y   y
                                                                                                                
                                                                                             i −nj )+ky (ni −nj )
                      f nxi − nxj , nyi − nyj                         F kx , ky e i N
                                                                      
                                                    =                                                               ,
                                                        kx =0 ky =0


and then rewrites each exponential in terms of sines/cosines matching the tensor-product embedding pxi ⊗ pyi . Consequently,
                                         2   2
there exists a block-structured C ∈ RN ×N such that

                                                  p⊤
                                                                         
                                                   i C pj = f ri − rj .

Hence, by choosing WV so that pi 7→ wri , a single-layer linear self-attention (dimension d = N 2 ) recovers exactly the
mapping
                                                   X              
                                            Vi =        f ri − rj wrj .
                                                             j̸=i

                                                                                                                2
All the 1D collision arguments from earlier carry over: once the domain is embedded into RN , Theorem 3.1 implies
that single-layer linear self-attention can represent any pairwise function f (ri − rj ). Of course, this comes at the cost of
embedding dimension N 2 , so the resulting kernel C has size N 2 × N 2 , i.e. an O(N 4 ) parameter count for a fully general
2D interaction.

Non-Identical Agents. One can likewise handle agents with different behavior or policies. For example, suppose half of
the agents always move right until they reach the boundary, while the others always move up. Label these two behaviors (or
policies) via a discrete set Sq = {R, U}, and let each agent i carry an extra label qi ∈ Sq . Then the value function is
                                                          X                  
                                             Vri ,qi =     f ri − rj , qi , qj wrj ,qj .                                  (18)
                                                          j∈[L]
                                                           j̸=i


                                                                      23
                          A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

Following steps similar to the value functions that depend on both coordinates example, we now view the domain of each
agent as
                                                  S = Sq × Sx × Sy ,
where Sx and Sy are each [N ]. Its cardinality is |S| = 2 N 2 , in this simple example. We then embed each agent’s label and
                            2
position as a vector in R2N . For instance, if qi = R we might set
                                   
                                    1                                                           2
                            qi =      , pxi , pyi ∈ RN , zi = qi ⊗ pxi ⊗ pyi ∈ R2N .
                                    0
                                                                                                     
Likewise if qi = U, we flip those two bits in qi . By expanding the definition of f ri − rj , qi , qj via a suitable DTFS,
one again obtains a matrix C of size (2N 2 ) × (2N 2 ) that captures all pairwise interactions. Thus a single-layer linear
self-attention with d = 2N 2 dimensions suffices to represent Eq. (18). The parameter count grows to O(4 N 4 ) in the fully
general case, but the construction exactly parallels the identical-agent scenario.

B.2. Genotype–Phenotype Mapping Task
Each allele (or gene variant) in the domain S is labeled with a unique integer and embedded using a one-hot vector. We
consider a DNA sequence of length L in which every position corresponds to a unique allele. In other words, each allele
appears at most once in the sequence (no duplicates). Our experiments randomly sample activation relations: an allele
µ ∈ S is activated if another allele ν exists somewhere in the sequence. Symbolically, we might store these relations in a
dictionary of the form
                                                      µ : [ν1 , ν2 , ...],
meaning “allele i is activated by the set of alleles-νk ” If i : [ ] (an empty list), then allele i is always active, while alleles not
present in the dictionary behave like redundant or inactive genetic material.
Constructing C and WV . To model these activation patterns via a single-layer linear self-attention, we build C ∈ Rd×d
and WV ∈ Rd×1 as follows (assuming each allele is one-hot embedded into Rd , with d = |S|):

   • For every dictionary entry of the form i : [j1 , . . . , jm ], set
                                                Ci, jk = 1/m for each k = 1, . . . , m,
     and set all other entries in row i to zero.
   • For entries i : [ ] (i.e., allele i is always active), assign each entry in row i to L1 . This ensures allele i gains a constant
     contribution from the entire sequence.
   • Set every entry of WV to 1 (i.e., WV ∈ Rd×1 is a vector of all ones).

An example dictionary may be {1:[3], 2:[], 4:[2]}. Seeing that we have one hot encoding
                                                                                  
                                            0        0         0       0        0
                                         0          0         0       1        0 
                                                                                  
                                  C=    1/L       1/L      1/L      1/L      1/L 
                                                                                   
                                         0          0         0       0        0 
                                            0        0         1       0        0

This is an example task for which a single layer linear self-attention cannot length generalize. However, a simple dense layer
with ReLU activation addition after single layer linear self-attention, trivially enables it to generalize any length

B.3. Vision Task
In this example, each token or entity corresponds to a single pixel in an image. Suppose there are d possible pixel positions
in the image, each with a positional embedding pi ∈ Rd . We also have a binary indicator bi ∈ {0, 1} denoting whether
pixel i is black (bi = 1) or white (bi = 0). We embed each pixel jointly as
                                                 xi = bi , pi ∈ R 1+d .
                                                              


                                                                   24
                        A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

Thus, the first coordinate captures color, and the remaining coordinates capture position. We want to detect whether a
specific pattern of black pixels occurs around the position pi . Formally, we want to detect if pixels in a set of relative offsets

                                                     ∆ = {∆1 , ∆2 , . . . }

are all black around position i. For example, ∆ might define a small pattern (e.g., a 3 × 3 cross), such that for each ∆k ∈ ∆,
the pixel at pi + ∆k must be black for us to declare “shape present at i.”
Block-Structured C Matrix. Consider a single-layer linear self-attention of dimension d + 1. Let C ∈ R(d+1)×(d+1) be
block-structured, meaning:                                         
                                                      01×1 01×d
                                             C =              e d×d ,
                                                      0d×1 C
where 0 denotes a zero block (ensuring that the binary coordinate bi does not directly alter which positions are relevant). If
we want to detect a shape around pi by checking offsets ∆ = {∆1 , . . . , ∆m } ⊆ Rd , then for each row i (representing pi in
the C
    e submatrix), we set
                                                     (
                                                       1, if pj is in pi + ∆,
                                            Ci,j =
                                            e
                                                       0, otherwise.
This ensures pi attends to exactly those pixel positions pj that lie within the shape region around i.
Capturing the Binary Color. To incorporate the notion that only black pixels (bj = 1) contribute, we define WV ∈
R(d+1)×1 so that its entries corresponding to the binary part of xj are nonzero, while its entries corresponding to the
positional part are zero. More formally,                " #
                                                  V       1
                                               W =             ∈ R 1+d .
                                                         0d

Hence, when we multiply xj by WV , the outcome is simply bj . In other words, if bj = 1, the pixel contributes; if bj = 0, it
does not.
Overall Operation. Putting it together, our single-layer linear self-attention

                                                     X C X⊤ X W V
                                                              


                        e identifies the relevant offsets pj around each pi , i.e., it checks which pixels could participate in a
behaves as follows: (i) C                               
                    V
pattern at i. (ii) W converts the embedding bj , pj into bj , effectively a blackness indicator. (iii) Summing across the
image yields, for each position i, the count of black pixels at the appropriate offsets ∆.
If this count matches the size of ∆, we conclude that the shape is present around pixel i. Thus, the linear self-attention
mechanism can recognize patterns of arbitrary size and structure without changing the kernel size or other architectural
hyperparameters.

CNN Versus Transformer: Theoretical Insight. A single-layer Convolutional Neural Network (CNN) with a fixed 3 × 3
kernel cannot detect patterns larger than 3 × 3 within that same layer. Extending the receptive field would require either
deeper networks or larger kernels. However, we do not know even the task of a layer in a large and deep neural network.
Therefore, generally we do not know the required kernel for the task in advance, so we just cross validate different over
different trials. This design constraint makes CNNs less flexible when the optimal pattern scale is not known a priori. By
contrast, Transformers can attend to any subset of positions in the input —whether nearby or distant— in a single layer. In
our example, the shape offsets ∆ might be large or irregular, yet the same C  e submatrix can be adapted to capture those
long-range relationships. Consequently, Transformers provide a more versatile framework for shape detection (which is
simply learning how different parts of image interact with each other) or other vision tasks where the required pattern scale
or geometry may vary significantly from one scenario to another.

B.4. Time Series Prediction
Consider a univariate or multivariate time series {m[t]}L+1
                                                        t=1 , where each m[t] ∈ R
                                                                                       d2
                                                                                          is the observed value at time t. We
assume m[t] depends on a set of specific past delays D = {t1 , t2 , . . . } ⊂ N, along with scalar multipliers {ak }k∈D and a

                                                                25
                        A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

linear transform A ∈ Rd2 ×d2 capturing how past values affect the current state:
                                                      X
                                            m[t] =         ak A m[t − k].
                                                           k∈D

For instance, if D = {2, 5}, then m[t] = 3 A m[t − 2] + 7 A m[t − 5]. For example, if D = {2, 5}, we get m[t] =
3 A m[t − 2] + 7 A m[t − 5].
To embed each time step t as an entity, define
                                                 xt = m[t], p[t] ∈ Rd+d2 ,
                                                               

where m[t] ∈ Rd2 is the observed state, and p[t] ∈ Rd is a positional embedding (e.g., one-hot or continuous encoding). An
indicator-based formulation ensures the attention mechanism recovers delays in D:
                                               X X                             
                               m[L + 1] =                ak I (L + 1) − j = k A m[j].
                                                 j∈[L] k∈D

Our goal is to show how a single-layer linear self-attention can represent this dependency structure exactly, following
Theorem 3.1.
We treat each time step t as a distinct entity in the sequence. Its embedding xt ∈ Rd+d2 combines:
                                                                       
                                                      xt = m[t], p[t] ,
where:

   • m[t] ∈ Rd2 is the observed state at time t (univariate or multivariate).
   • p[t] ∈ Rd is a positional embedding encoding the index t. This could be a one-hot vector of length L, or a sinusoidal
     embedding.

Define a block-structured matrix C ∈ R(d+d2 )×(d+d2 ) to separate the m[t] coordinates from the positional coordinates p[t].
We can denote:                                                             
                                                          0 d2 ×d2 0 d2 ×d
                                                  C =                 e d×d ,
                                                           0 d×d2 C
                            e encodes which time delays matter, while the m[t] portion does not directly determine which
so that the positional part C
                                      e u,v = 1 if position v is a valid activator for position u under one of the delays in D,
indices to attend to. Concretely, let C
and 0 otherwise. Equivalently, we can define
                                                          X                   
                                               C
                                               e u,v =         ak I u − v = k ,
                                                          k∈D

if we index the positional embedding such that u, v ∈ {1, . . . , L}. This ensures that time step u attends to time step v if v is
exactly one of the valid delays k behind u.
Next, we define WV ∈ R(d+d2 )×d2 to extract the actual state m[t] from each token:
                                                           "        #
                                                    V          A
                                                 W =                  ,
                                                             0 d×d2
where A ∈ Rd2 ×d2 is precisely the transformation from the autoregressive model. This construction means that when we
multiply xt by WV , we obtain A m[t], and the positional coordinates are ignored in this step (since their block is zero).
Putting it all together, a single-layer linear self-attention computes
                                                                
                                                          X C X⊤ X W V .
For the row corresponding to the final time step L + 1, the multiplication by C picks out those time steps j such that
(L + 1) − j ∈ D. Then multiplying by WV retrieves A m[j]. Summing the contributions yields precisely
                                                     X
                                       m[L + 1] =         ak A m[ L + 1 − k ],
                                                          k∈D

mirroring the autoregressive formula.

                                                                26
                        A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

C. Proof of Theorem 4.4: Convergence to Zero Training Error
Recall that B ∈ R|S|×d is the embedding base matrix whose rows are embeddings of each element in the domain. We start
with the following simple observation.
Lemma C.1. If the domain embeddings are orthonormal, that is , ⟨x(α), x(β)⟩ = δa,b , ∀ α, β ∈ S, then X⊤ X is diagonal
                                                                   (n)
in the embedding basis, and BX(n) ⊤ X(n) B⊤ = diag(s(n) ), where sµ is the number of times the element µ appears in
the n-th sample.

Since we set d = |S|, we can freely adopt an orthonormal domain embedding, ensuring that

                                                      ⟨Bi,: , Bj,: ⟩ = δi,j .

For the remainder of this section, we conduct all calculations in the domain embedding basis. To formalize this, we define
the following orthonormal transformations:

                                                  X(n) one−hot = X(n) B⊤ ,
                                                     Cone−hot = BCB⊤ ,
                                                     wone−hot = Bw.

For notational simplicity, we omit the one − hot superscripts in the rest of this section. This will not cause any confusion as
we are always referring to the one-hot transformed versions. That is, whenever we write X(n) , C, w, they actually represent
X(n) one−hot , Cone−hot , wone−hot . Also, seeing that B is orthonormal matrix, when we establish the convergence of the
one-hot parameter representations, it directly implies the convergence of the original parameters, which can be recovered
by applying the inverse transformation in the B basis. What we do is simply change our perspective to how we look at
coordinate system. Lastly, in this section, we denote eµ ∈ R|S| as unique one-hot encoded vector for all µ ∈ S, i.e. the base
vector.
We will firstly derive the gradients of the loss function with respect to the parameters than we will state a lemma that will be
useful for the proof of Theorem 3.1.

Gradients of the LMSE (C, w) with Respect to C and w. For convenience, denote WV ∈ Rd×1 as w ∈ Rd . It is easy
to verify the following equation:
                     B                                                                   B
   ∂LMSE (C, w)   1 X (n) ⊤ ∂                                       ∂LMSE (C, w)   1 X (n) ⊤ ∂          
                =       D      SAlin X(n) ,                                         =       D      SAlin X(n) .
       ∂C         B n=1     ∂C                                             ∂w         B n=1     ∂w

Since d2 = 1 the linear self-attention in Eq.1 can be written as
                                                              
                                            SAlin X(n) = X C X⊤ X w,

where w ∈ Rd . We have
                                            ∂SAlin X(n)
                                                                      h      i
                                                                  = X:µ X⊤ X w .
                                               ∂Cµν                                  ν

Hence,
                                                 B
                               ∂LMSE (C, w)   2 X h (n) ⊤ (n) i  (n) ⊤ (n)
                                            =       X    X w     X:µ    D .
                                  ∂Cµν        B n=1            ν

Similarly,
                                           ∂SAlin X(n)
                                                                              
                                                                  =       X C X⊤ X:α ,
                                              ∂wα
                                                 B
                               ∂LMSE (C, w)   2 X  (n) ⊤   (n) ⊤ (n) ⊤  (n)
                                            =       X         X C X        D .
                                  ∂wα         B n=1        α:


                                                                  27
                       A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

We can write the same gradient equations as

                                  ∂LMSE (C, w)   2 X (n) ⊤ (n) ⊤ (n) ⊤ (n)
                                               =     X    D w X       X ,
                                      ∂C         B n
                                  ∂LMSE (C, w)   2 X (n) ⊤ (n) ⊤ (n) ⊤ (n)
                                               =     X    X C X       D .
                                      ∂w         B n

Lemma C.2. If we choose initial parameters as C(0) = 0 and wα (0) ≥ b > 0, then wα (t) ≥ b > 0, ∀α and ∀t ≥ 0.

Proof. Firstly, we will show that wα (t)2 ≥ wα (0)2 , ∀t and ∀i, than we will prove the statement in the lemma.We can copy
the previous gradient derivations and gradient flow equations

                           dC      ∂LMSE (C, w)      2 X (n) ⊤ (n) ⊤ (n) ⊤ (n)
                              = −η              = −η     X    D w X       X ,
                           dt          ∂C            B n
                           dw      ∂LMSE (C, w)      2 X (n) ⊤ (n) ⊤ (n) ⊤ (n)
                              = −η              = −η     X    X C X       D .
                           dt          ∂w            B n

Let Λ be a matrix that is diagonal in the embedding base B. However, we again abuse the notation. We do not rewrite the
one − hot in Λone−hot = BCB⊤ and denote it just as Λ in the rest of the proof. We can now write
                                  dC        2 X ⊤ (n) ⊤ (n) ⊤ (n) ⊤ (n)
                                 C⊤  Λ = −η     C X      D w X          X Λ,
                                  dt        B n
                             n dC o         2 X n ⊤ (n) ⊤ (n) ⊤ (n) ⊤ (n) o
                           Tr C     Λ = −η      Tr C X       D w X          X Λ ,
                                 dt         B n
                                dw ⊤        2 X
                              Λ     w = −η      ΛX(n) ⊤ X(n) C⊤ X(n) ⊤ D(n) w⊤ ,
                                dt          B n
                            n dw     o      2 X n ⊤ (n) ⊤ (n) ⊤ (n) ⊤ (n) o
                          Tr Λ    w⊤ = −η       Tr C X       D w X          X Λ .
                               dt           B n

Thus, we have
                                              n    dC o       n dw     o
                                            Tr C⊤     Λ = Tr Λ      w⊤ ,
                                                   dt            dt
                                              n dC
                                                                ⊤ dw
                                                        o     n        o
                                                      ⊤
                                            Tr     ΛC     = Tr w Λ      .                                                (19)
                                                dt                  dt
Seeing that Λ is diagonal Λ⊤ = Λ. Thus, from Equation 19 we can get
                                          d
                                            Tr CΛC⊤ − Tr w⊤ Λw = 0
                                                                
                                         dt
                 Tr C(t)ΛC(t)⊤        − Tr w⊤ (t)Λw(t) = Tr C(0)ΛC(0)⊤ − Tr w⊤ (0)Λw(0)
                                                                        

Letting Λ = diag(eα ), where eα is the unit basis vector corresponding to α, we reach to

                           wα2 (t) = wα2 (0) + ∥C:,i (t)∥22 − ∥C:,α (0)∥22 = wα2 (0) + ∥C:,α (t)∥22 ,

where the last equality follows because C(0) = 0. As a result we reach to

                                                    wα2 (t) ≥ wα2 (0) ≥ b2                                               (20)

Seeing that dwdt is finite ∀t, wα (t) is continuous. As a result if wα (0) ≥ b > 0, then wα (t) ≥ b, ∀t which can be proven by
                α


contradiction. Assume ∃t∗ > 0 such that wα (t∗ ) ≤ b. By Equation 20, wα (t∗ ) ≤ −b < 0. By intermediate value theorem
∃τ ∈ (0, t∗ ) such that wα (τ ) = 0, so wα2 (τ ) = 0 < wα2 (0) ≥ b2 , which contradicts with (20)

                                                              28
                       A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

Proof of Theorem 4.4 (Convergence to Zero Training Error). Gradient Flow for the Residuals and the Loss. We define
the residual (error) on the n-th example
                                                              
                                          D(n) = SAlin X(n) − y(n) .

Let t denote the (continuous) gradient-descent time, with

                                           dC      ∂L             dw      ∂L
                                              = −η    ,              = −η    .
                                           dt      ∂C             dt      ∂w

Consider the time derivative of the residual

                                          ∂SAlin X(m) dC    ∂SAlin X(m) dw
                                                                      
                                  dD(m)
                                        =                 +                 .
                                   dt          ∂C      dt        ∂w      dt
Expanding each term, we substitute

          ∂SAlin X(m)                                   ∂SAlin X(m)
                                     h            i                               
                                        (m) ⊤ (m)
                           = X:µ X(m)
                                             X    w and               = X(m) C X(m) ⊤ X(m)
                                                                                       :α .
                ∂Cµν                                ν       ∂wα

As for the gradient updates we subsitute
                B                                         B
   dCµν     2 η X h (n) ⊤ (n) i  (n) ⊤ (n)  dwα     2 η X  (n) ⊤   (n)       
        = −        X     X w     X:µ    D and     = −        X          X C X(n) ⊤ D(n) ,
    dt      B n=1              ν               dt     B n=1          α:


Thus, we arrive to
                                                       B h
               dD(m)   X        h
                                   (m) ⊤ (m)
                                               i  2ηX                  i       ⊤
                     =     X(m)
                            :µ   X      X    w    −        X(n) ⊤ X(n) w     X(n)
                                                                              :µ     D(n)
                dt     µ,ν
                                                ν   B n=1
                                                                          ν


                              X                      2ηXB                        
                          +        X(m) C X(m) ⊤ X(m)
                                                  :α   −        X(n) ⊤     X(n) C X(n) ⊤ D(n) .
                              α
                                                         B n=1          α:


Rearranging terms,

              B
  dD(m)    2η X h ⊤ (m) ⊤ (m) (n) ⊤ (n)  (m) (n)⊤
        =−        w X     X X       X w X X
   dt      B n=1
                                                                                                             i
                                                                    + X(m) C X(m) ⊤ X(m) X(n) ⊤ X(n) C X(n) ⊤ D(n)

Seeing that the term in the parenthesis is a scalar, we can write the same equation in terms for kronocker product for future
convenience, which leads to

                B
  dD(m)     2 η X h ⊤ (m) ⊤ (m) (n) ⊤ (n)   (m) (n) ⊤ 
        = −         w X     X X       X w ⊗ X X
   dt       B n=1
                                                                                                        i
                                                               + X(m) CX(m) ⊤ X(m) X(n) ⊤ X(n) C⊤ X(n) ⊤ D(n) . (21)

Stacking different samples with the following definitions

                           ..                           ..                            ..
                                                                                            
                        .                             .                          .         
                           (n)  , M =      ⊤ (n) ⊤ (n)         (n)  , M =  (n)     (n) ⊤ (n)  ,
                   D=  D               w   X       X     ⊗ X         2  X    CX       X 
                            ..                         ..                            ..
                             .                          .                             .

                                                             29
                       A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

we can write the Eq. 21
                                                   dD     2η 
                                                              MM⊤ + M2 M⊤
                                                                          
                                                       =−               2 D.
                                                    dt    B
We can write the derivative of the loss as
                                       B
                     dLMSE (C, w)   2 X (m) ⊤ dD(m)    4η
                                                    = − 2 D⊤ MM⊤ + M2 M⊤
                                                                        
                                  =       D                            2 D.
                         dt         B m=1      dt      B

Clearly, both MM⊤ and M2 M⊤
                          2 are positive semidefinite, so

                                               dLMSE (C, w)    4η
                                                            ≤ − 2 D⊤ MM⊤ D.                                                                 (22)
                                                   dt          B

Now, we will write Eq. 22 differently by re-expressing D. Thanks to the realizability, we can write,

                          D(n) = X(n) C X(n) ⊤ X(n) w − X(n) C∗ X(n) ⊤ X(n) w∗ .
                                                                                   

                                                                                           ∗
Due to Lemma C.2 wi ̸= 0, so w∗ i /wi is defined for all i ∈ [d]. Thus we can define, diag ww to be the diagonal matrix,
whose entries are w∗ i /wi in order.

                                                                                                                              w∗
                                                                                                                                  
                          (n)           (n)        (n) ⊤       (n)               (n)    ∗    (n) ⊤           (n)
                                                                                                    
                      D         =   X         CX               X     w − X             C X               X         diag                w.
                                                                                                                              w

In the orthonormal basis, X(n) ⊤ X(n) is diagonal, which allows reordering to obtain
                                                h                 ∗ i
                                 D(n) = X(n) C − C∗ diag ww             X(n) ⊤ X(n) w.

Vectorizing (using vec(A X B) = (B⊤ ⊗ A) vec(X)) yields
                                                    h          ∗ i
                                   D(n) = M(n) vec C − C∗ diag ww .

Stacking over n produces D = M vec C − C∗ diag(w∗ /w) . Thus, Eq. 22 can be written as
                                                     

dLMSE (C, w)    4η              4η    h            ∗ i⊤             h            ∗ i
             ≤ − 2 D⊤ M M⊤ D = − 2 vec C − C∗ diag ww     M⊤ M M⊤ Mvec C − C∗ diag ww
    dt          B               B
Using the Lemma C.3, the same inequality can be written as

          dLMSE (C, w)           4η                        h                  ∗ i 2       4η
                           ≤ − 2 λmin M⊤ M Mvec C − C∗ diag ww                         = − 2 λmin M⊤ M ∥D∥2 ,
                                                                                                          
                 dt              B                                                          B
where λmin M⊤ M           is the minimum eigenvalue of M⊤ M. Thus, if there exists a constant ψ such that
                        
           ⊤
                      
λmin M (t)M(t) ≥ ψ > 0, ∀t, then the training loss stops decreasing only when D reaches to all zero vector,
i.e, training loss stops decreasing only when it reaches to zero, which is stated more rigorously in Lemma C.4.
Lower Bound on the Eigenvalues of M⊤ M. We can show that

                           λmin M⊤ M = σmin M⊤ M =                                                 ∥M⊤ Mu∥2 ,
                                                      
                                                                                         min                                                (23)
                                                                                       u:∥u∥2 =1

where the first equality follow because M⊤ M is symmetric and positive semi definite. We also know
                                        X                               
                               M⊤ M =       X(n) ⊤ X(n) ww⊤ X(n) ⊤ X(n) ⊗ X(n) ⊤ X(n) .
                                               n

Defining                                                                X
                                                                   u=         uµ ⊗ eµ ,
                                                                        µ∈S


                                                                          30
                         A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

where each uµ ∈ Rd , so                                            X
                                                        ∥u∥22 =              ∥uµ ∥22 = 1.                                       (24)
                                                                   µ∈S

Recalling
                                                           ..
                                                                  
                                                        . 
                                                X(n) = 
                                                       eX (i) 
                                                                        ,
                                                            ..
                                                             .    i∈[L]
  (n) ⊤ (n)
                                                        
X      X     acts as a projection matrix onto the space eX (0) , eX (1) , . . . , eX (L−1) . Thus, using the mixed-product
property of Kronecker product, we can write
                                      X X h                                         i               2
                      ∥M⊤ Mu∥22 =                X(n) ⊤ X(n) ww⊤ X(n) ⊤ X(n) uX (i) ⊗ eX (i)                          (25)
                                          n∈B i∈[L]
                                           X X h                                   i          2
                     ∥M⊤ Mu∥22 =                         X(n) ⊤ X(n) ww⊤ X(n) ⊤ X(n) uµ ⊗ s(n)
                                                                                           µ eµ
                                          n∈B µ∈S
                             
Recall the definition Bµ = n ∈ B : µ ∈ X (n) , so
                                     X X            h                           i       2
                       ∥M⊤ Mu∥22 =              s(n)
                                                 µ    X (n) ⊤ (n)
                                                             X    ww ⊤ (n) ⊤ (n)
                                                                      X     X     uµ ⊗ eµ                                       (26)
                                                                                                                            2
                                           µ∈S n∈Bµ
                                          X X                h                           i    2
                                                                (n) ⊤ (n)    ⊤ (n) ⊤ (n)
                                      =                 s(n)
                                                         µ    X      X    ww  X     X      uµ
                                                                                                                2
                                          µ∈S n∈Bµ
                                          X X                h                    i  2
                                      =                 s(n)
                                                         µ    diag s(n) ww⊤ diag s(n) uµ
                                                                                                                2
                                          µ∈S n∈Bµ
                                          X X                h                            i   2
                                      =                 s(n)
                                                         µ    diag (w) s(n) s(n)⊤ diag (w) uµ
                                                                                                            2
                                          µ∈S n∈Bµ
                                                                                                   
                                          X                    X                                                2
                                      =         diag (w)                   s(n)
                                                                             µ s
                                                                                 (n) (n)⊤ 
                                                                                    s       diag (w) uµ             .           (27)
                                                                                                                2
                                          µ∈S                  n∈Bµ

                                       ⊤
Recall the SBµ = . . .     s(n)    . . . n∈B , and define
                                           µ


                                                                   ..
                                                                                               
                                                                        .
                                                                                 (n)
                                                                                               
                                                diag (sµ ) = 
                                                                             sµ                
                                                                                                       .
                                                                                       ..
                                                                                            .
                                                                                                n∈Bµ

Thus, we reach to
                                                  X                                                                 2
                                 ∥M⊤ Mu∥22 =             diag (w) S⊤
                                                                   Bµ diag (sµ ) SBµ diag (w) uµ                        .
                                                                                                                    2
                                                  µ∈S

Repeatedly applying the identity ∥Az∥2 ≥ σmin (A)∥z∥2 , where A and z are any matrix and vectors with suitable shapes,
                                      X
                       ∥M⊤ Mu∥22 ≥        4                2                 4
                                                                                 SBµ ∥uµ ∥22
                                                                                     
                                         σmin  {diag (w)} σmin {diag (sµ )} σmin
                                           µ∈S

                      2
                                                                                                               
Due to Lemma C.2, σmin                                        2
                         {diag (w)} ≥ b2 > 0. By definition, σmin                                       2
                                                                  {diag (sµ )} ≥ 1. By Assumption 4.2, σmin SBµ ≥
ζ 2 > 0. Because of the Equations 23 and 24, we reach to
                                              λmin M⊤ M ≥ b2 ζ 2 > 0.
                                                          




                                                                            31
                       A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

Lemma C.3. For any matrix M, and any vector x such that Mx is defined, then

                                x⊤ M⊤ M M⊤ Mx ≥ λmin M⊤ M ∥Mx∥2 ,
                                                                    
                                                                                                                      (28)

where λmin M⊤ M corresponds to minimum eigenvalue of M⊤ M matrix.
                


Proof. Obviously A = M⊤ M is a symmetric and positive semi definite matrix, so it can be diagonalized as A = QΛQT
                                
                          1   1                    1      1
and its square root A = A 2 A 2 defined uniquely A 2 = QΛ 2 Q⊤ . It follows that
                                                1       1
                               x ⊤ A2 x = x ⊤ A 2 A A 2 x
                                                1              1
                                       = x⊤ A 2 ⊤ QΛQ⊤ A 2 x
                                               1
                                                   ⊤       1
                                                               
                                       = Q⊤ A 2 x Λ Q⊤ A 2 x
                                                        1
                                       ≥ λmin ∥Q⊤ A 2 x∥2 = λmin x⊤ Ax = λmin ∥Mx∥2 .


Lemma C.4 (Convergence Lemma). Consider the equation

                                                     ẋ(t) = −ηA(t)x(t).                                              (29)

Assume the following conditions hold

 (i) A(t) is symmetric for all t.
(ii) The eigenvalues of A(t) are lower bounded by a positive constant, i.e., λmin (A(t)) ≥ ψ > 0 for all t, for some ψ > 0.

Then, x(t) → 0 as t → ∞.

D. Generalization Analysis of Linear Self-Attention
Let’s denote the parameters we get from training as Ĉ and ŴV . Also, to simplify the notation, just for this section, we
define

                                                    Cµν = x⊤ (µ) Cx (ν) ,
                                                    Wνk = x⊤ (ν) W:,k ,

D.1. Proof of Theorem 4.6: Generalization
Remember that B is the domain embedding matrix seen in (6). Also, remember that {WV † , C† } represent a set of
parameters that generalize to population distribution.

Proof of Theorem 4.6. Let Ĉ and ŴV be the parameters we get from the training. The zero training error condition
corresponds to ∀ n ∈ B
                                X(n) ĈX(n) ⊤ X(n) ŴV = X(n) C† X(n) ⊤ X(n) WV † ,
writing the same equation for each column separately, we get

                                    X(n) ĈX(n) ⊤ X(n) ŵk = X(n) C† X(n) ⊤ X(n) wk† ,

where wk† is defined as k-th column of WV † . Using B⊤ B = I, we write it in the domain embedding base

                  X(n) B⊤ BĈB⊤ BX(n) ⊤ X(n) B⊤ Bŵk = X(n) B⊤ BC† B⊤ BX(n) ⊤ X(n) B⊤ Bwk†

By Lemma C.1,                                                                     
                                                                       (n)
                                        BX(n) ⊤ X(n) B⊤ = diag s(n)
                                                                α   , sβ   , . . .

                                                             32
                        A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

Remembering the definition Ĉµν = x(µ)⊤ Ĉx(ν) and ŵα = x(α)⊤ ŵ and similar definitions for C† and WV † , for any
µ, ν, α ∈ S,
                            X                 X
                                                  † (n) k†
                                Ĉµν s(n) k
                                      ν ŵν =   Cµν  sν wν ,
                                   ν∈S                                       ν∈S
                                       X                                                 
                                                                       †
                                            s(n)
                                             ν            Ĉµν ŵνk − Cµν wνk†                = 0 , ∀ µ ∈ X (n) and ∀ n ∈ B       (30)
                                   ν∈S

For each specific µ and k, the terms in the last equation in parentheses can be construed as a vector with indices over ν.
Denoting that vector as aµk and remembering SBµ definition (from Appendix A), Eq. 30 can be written as

                                                                                      SBµ aµk = 0

Thanks to the Assumption 4.2, SBµ is full column rank so only solution to last equation is aµk = 0, which corresponds to
             †
Ĉµν ŵνk = Cµν wνk† ∀ µ, ν ∈ S, k ∈ [d]. Consequently, for any X which is embedding of a corresponding X ∼ D

                                                          XĈX⊤ XŴV = XC† X⊤ XWV † = Y

Thus the learned parameters generalizes to all population, that is,
                                                h                   i
                                       EDX ×Y Y − XĈX⊤ XŴV            =0




From the above proof, we can see that Assumption 4.2 not just plays a critical role in ensuring zero training error, but also
leads to generalization to the entire population distribution. Specifically, this assumption ensures that any set of parameters
achieving zero training error must also yield zero population error, meaning there exists no parameter set that perfectly fits
the training data while still incurring some error at the population level.

D.2. Length Generalization
In the preceding analysis, we showed that under some mild assumptions, achieving zero training error leads to robust
population-level generalization for the specific length L from which training data is sampled. However, many of our
interaction-based experiments naturally suggest length generalization: the outputs of these models are not inherently tied
to a fixed sequence length, nor did our experimental design depend on a specific number of entities. That brings us to the
Assumption 4.7. Despite this, our test-time generalization results do not formally guarantee out-of-distribution generalization
                                                                              ∗
to unseen sequence lengths. In this section, we analyze the conditions on DL under which the parameters that generalize to
                   ∗
the distribution DL generalize to D∀L .
Remember that we denote (C∀L , WV,∀L ) as the set of parameters that generalize to any length for the task of interest Also,
we denote k-th column of the matrix WV,∀L as wk,∀L Let us first look at possibility of parameters that has zero error for
   ∗       ∗
X L ∼ DL but does not generalize to any other length L. Writing them in terms of a specific length generalizing parameters
                                                                           ∗                            ∗
and C∆ , w∆ -defined accordingly to satisfy the following equalities-, CL = C∀L + C∆ and          wk,L = wk,∀L + w∆ ,
         ∗                                                                   ∗         ∗      ∗
∀ µ ∈ X L and denoting k-th column of the true output for the input tuple X L as yk,L X L .
                               ∗
                                           ∗
                                                         X
                                                                      ∀L
                       yµk,L           XL                                   ∆
                                                                                               wνk,∀L + wνk∆
                                                                                                              
                                                    =                Cµν + Cµν
                                                        ν∈X L∗
                                                          X
                                                                      ∀L k,∀L    ∀L k,∆   ∆ k, ∀L    ∆ k, ∀L
                                                                                                                              
                                                    =                Cµν wν   + Cµν wν + Cµν wν   + Cµν wν                        (31)
                                                        ν∈X L∗

             ∗
                ∀L k,∆    ∆ k, ∀L    ∆ k, ∀L
Defining ∆L
          µν = Cµν wν  + Cµν wν   + Cµν wν , and combining the effect of biasses on the output,
                                                            ∗
                                                                        ∗
                                                                                     X                     X         ∗
                                                                                               ∀L k,∀L
                                                    yµk,L           XL           =            Cµν wν   +            ∆L
                                                                                                                     µν
                                                                                     ν∈X L∗                ν∈X L∗


                                                                                              33
                        A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

We can write the bias on the function output that does not change the function output for the inputs such that |X | = L∗ , but
may change the output for inputs with other L, as        X       ∗
                                                              ∆L
                                                               µν .
                                                           ν∈X

To illustrate this point, consider ∆µ,µ = a and ∆µ,ν = L−a
                                                        ∗ −1 ∀ ν ̸= µ, seeing that Eq. 31 is written ∀ µ ∈ X ,


                                X         ∗       ∗      X            ∗              X      a
                                        ∆L     L
                                         µν = ∆µν +              ∆L
                                                                  µν = a −                 ∗−1
                                                                                               = 0.
                                                                                          L
                               ν∈X L∗                   ν∈X L
                                                             ∗
                                                                                 ν∈X   L∗
                                                         ν̸=µ                     ν̸=µ


However, when we feed an input X L ∼ DL that L ̸= L∗ , we get
                                        ∗         X                 X   ∗
                                                          ∀L k,∀L
                                   yµk,L X L =                        ∆L
                                             
                                                        Cµν wν    +    µν
                                                         ν∈X L                       ν∈X L
                                                                 X           ∗
                                                       = yµk +            ∆L
                                                                           µν
                                                                 ν∈X L
                                                                  ∗         X          ∗
                                                       = yµk + ∆L
                                                                µν +                 ∆L
                                                                                      µν
                                                                           ν∈X L
                                                                            ν̸=µ
                                                                          X     a
                                                       = yµk + a −             ∗−1
                                                                            L
                                                                              L
                                                                        ν∈X
                                                                         ν̸=µ
                                                                   L∗ − L
                                                       = yµk + a
                                                                   L∗ − 1

                                                                                                                       L∗ − L
In particular, the last equation shows that an unseen sequence of length L ̸= L∗ incurs an additive deviation of a
                                                                                                                       L∗ − 1
                          k,L∗
from the desired target yµ , so the model generalizes to every length if and only if this bias term vanishes, i.e., a = 0. This
will be useful in the following proof.

Proof of Theorem 4.8. To generalize to any length we should make sure that the population distribution for any length L∗
                                        ∗
does not allow such a bias, that is, ∆L
                                      µν = 0 , ∀ µ, ν. From the previous discussion, for the set of parameters that generalize
                              ∗
to population distribution DL we know that,
                                                         ∗
                                                                     L∗       ∗
                                               X
                                                     ∆Lµν = 0 , ∀ X     ∼ DL                                              (32)
                                              ν∈X L∗

                                                                                 ∗  ∗                  ∗     ∗         ⊤
For each µ, we can think of Eq. 32 as a linear system of equations. Defining, δµL = ∆L
                                                                                     µα               ∆L
                                                                                                       µβ   ∆L
                                                                                                             µγ   ...        ∈ R|S| ,
and an infinite sample extension of SBµ that is
                                                  ∗                   ∗         ⊤
                                               SL
                                                    
                                                 ∞ = ...
                                                Bµ                 sL      . . . s ̸=0 ,                                        (33)
                                                                                 ν

          ∗
                                                        ∗
where SL∞ is such a matrix that each row of it sums to L , Eq. 32 can be written as
       Bµ


                                                   SBµ∞ δ µ = 0, ∀ µ ∈ S.

If SBµ∞ is full column rank for all µ, which is satisfied by Assumption 4.2, then ∆ = 0. Thus, it generalizes to any
length.

Seeing that Assumption 4.2 inherently encompasses “SBµ∞ is full column rank”, it may seem that test generalization would
always lead to length generalization, without any assumption. However, it is important to note that Assumption 4.2 is not
the minimal requirement for ensuring test generalization.

                                                                 34
                        A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions
                                                                                         ∗
Remark D.1. For clarity, let us look at an example class of tasks that for which SL∞ is not full column rank. If there is a
                                                                                  Bµ
                                         ∗                                                           ∗
constraint on the distribution X ∼ DL that the elements within X tuple are unique, than SL∞ is not full rank since the
                                                                                         Bµ
              ∗
column of SL∞ that corresponds to element µ will be all 1 vector. Which is means, that there are some possible parameters
           Bµ
                              ∗
that ensure zero error on DL but does not generalize to DL for any L.
Remark D.2. Under the realizability assumption, skip connections do not affect the values of the residues D(n) , allowing
the same proof on generalization to apply in the skip-connected scenario.
Corollary D.3. Defining

                                                     Cµν = x⊤ (µ) Cx (ν) ,
                                                    Wνk = x⊤ (ν) W:,k ,

it follows from the proof of Theorem 4.8 that any C, WV that generalizes ∀L satisfies
                                                         V     ∀L  V,∀L
                                                    Cµν Wνk = Cµν Wνk   .

Consequently, if you apply a nontrivial transformation to the parameters, all of the length generalizing parameters lead to a
specific matrix that depends on the task at hand.

If two sets of parameters for linear self-attention lead to the functionally equivalent self-attentions, i.e. they will lead to the
same outputs for the same inputs for any input output pairs, then under this kind of nontrivial transformation they lead to
the same matrix. Thus with this transformation we simply show that although the parameters we get after training are the
different than the length generalizing parameters we designed they are functionally equivalent to the length generalizing
parameters we have.

E. Justification for Data Versatility Assumption
In this section we justify Assumption 4.2, by showing it holds under an even milder assumption shown below.
                                                                                   |S|
Assumption E.1 (Positive-Definite Covariance and Bounded Norm). Let {s(n) }B
                                                                           n=1 ⊂ R     be i.i.d. random row vectors.
Suppose there exist constants ζmin > 0 and M > 0 such that:

(A1) Positive-Definite Covariance: The covariance matrix

                     Σ := Cov(s(n) ) = E (s(n) − E[s(n) ])(s(n) − E[s(n) ])⊤ satisfies Σ ⪰ ζmin
                                                                                            2
                                                                           
                                                                                                I.
                          2
     That is, λmin (Σ) ≥ ζmin > 0.

(A2) Bounded Norm: The centered vectors satisfy

                                             ∥s(n) − E[s(n) ]∥2 ≤ M         almost surely.                                    (34)

Theorem E.2 (Full Column Rank with High Probability). Under Assumption E.1, let
                                                  (n) 
                                                   s1
                                                  (n) 
                                                 s2        B×|S|
                                          S =    ..  ∈ R        .
                                                       
                                                  . 
                                                             (n)
                                                           sB

Then there exist positive constant γ > 0 (depending on M , ζmin , and |S|) such that for all sufficiently large B,
                                              h               i
                                             P rank(S) < |S| ≤ e− γ B .

Equivalently, A is full column rank with probability at least 1 − e−γB .

                                                                   35
                       A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

Proof. Step 1: Center the rows. Define an := s(n) − E[s(n) ], so that E[an ] = 0 and
                                                 Cov(an ) = E[an a⊤
                                                                  n ] = Σ.

Stack these centered rows into                         ⊤
                                                       a1
                                                      a⊤  
                                                       2
                                                  X =  .  ∈ RB×|S| .
                                                       .. 
                                                           a⊤
                                                            B
Since each row of S differs from X by a constant shift, rank(S) = rank(X). Hence it suffices to show X is full column
rank with high probability.

Step 2: Expected Gram matrix lower bound. We have
                                                                  B
                                                                  X
                                                       A⊤ A =             an a⊤
                                                                              n
                                                                 n=1

Taking expectation,
                                                           B
                                                           X
                                              E[A⊤ A] =          E[an a⊤
                                                                       n ] = B Σ.
                                                           n=1
                            2
By Assumption E.1(A1), Σ ⪰ ζmin I, hence
                                                   E[A⊤ A] ⪰ B ζmin
                                                                2
                                                                    I.

Step 3: Concentration via Matrix Bernstein. Define the centered matrix
                                                       Zn := an a⊤
                                                                 n − Σ.

Note E[Zn ] = 0. Summing,
                                                            B
                                                            X                          B
                                                                                       X
                                      ⊤            ⊤
                                    A A − E[A A] =             (an a⊤
                                                                    n − Σ)         =         Zn .
                                                            n=1                        n=1
Each Zn is bounded in operator norm since
                                 ∥an a⊤            2    2
                                      n ∥op = ∥an ∥2 ≤ M ,                ∥Σ∥op ≤ ∥Σ∥F (finite).
Thus for a constant R ∈ R,
                                              ∥Zn ∥op ≤ ∥an a⊤
                                                             n ∥op + ∥Σ∥op = R.
In addition,
                                                  ∥Z2n ∥op ≤ ∥Zn ∥2op ≤ R2 ,
                                                    B
                                                    X
                                                          E Z2n           ≤ BR2
                                                            
                                                    n=1              op
Hence by a standard matrix Bernstein inequality (self-adjoint version) from (Tropp, 2015), there exist constant γ > 0 such
that                                                                                     
                                                                  XB
                P ∥A A − E[A⊤ A]∥op ≥ 12 B ζmin
                   ⊤                                2                                 2 
                                                                              ≥ 21 B ζmin     ≤ e−γ B .
                                                        
                                                          = P        Zn
                                                                          n=1     op
                                          ⊤
In other words, with high probability, A A stays within half its expected value in spectral norm.

Step 4: Weyl’s inequality implies strict positivity. On this high-probability event,
        λmin (A⊤ A) ≥ λmin E[A⊤ A] − A⊤ A − E[A⊤ A] op ≥ B ζmin                   2          2
                                                                                     − 12 B ζmin         2
                                                                                                 = 12 B ζmin
                                          
                                                                                                             .

Hence A⊤ A is strictly positive-definite, implying rank(A) = |S|. Consequently, A is full column rank with probability at
least 1 − e−γ B .

                                                                36
                       A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

Remark E.3 (Justification for Assumption E.1). In many natural data-generation processes, these assumptions hold:

   • Count Vectors from a Dictionary. Suppose each sample X (n) is a tuple of L elements drawn from a vocabulary S.
                                                (n) (n)
     The row vector s(n) may represent counts (sα , sβ , . . . ) of how many times each element α, β, . . . appears. If we
                                                             (n)
     focus on the subset Bµ of samples that contain µ, then sµ ≥ 1, while the other L − 1 slots of the sequence are drawn
     from S \ {µ} according to some distribution.
   • Positive-Definite Covariance. When these (L − 1) “remaining” elements are distributed in a non-degenerate way
     (e.g., at least some variability in how the other vocabulary items appear), the resulting count vectors s(n) will have
     a covariance Σ whose minimum eigenvalue is strictly positive. For instance, under a uniform choice of the L − 1
     positions among the |S| − 1 possible elements, straightforward calculations show each coordinate has nonzero variance
     and λmin (Σ) > 0.
                                     (n)                                                                         p
   • Bounded Norm. Since 0 ≤ sν ≤ L forp         each element ν ∈ S, the count vector an is trivially bounded by |S| L in
     Euclidean norm. Thus we can take M = |S| L, satisfying Assumption E.1(A2).
   • General Distributions. Even more general scenarios (e.g., non-uniform sampling, correlated draws) satisfy the same
     assumptions, provided negative correlations are not too extreme to force Σ to have a zero eigenvalue. In practice,
     real-world data tends to have enough variability so that Cov(s(n) ) is well-conditioned, meeting the requirement
                 2
     λmin (Σ) ≥ ζmin  for some ζmin > 0.

F. HyperFeatureAttention
F.1. Motivation
The preceding discussions in Appendix B.1on value functions that depend on single coordinates, both coordinates, and
both coordinates with nonidentical agents reveal a fundamental pattern: as the number of features describing agents
increases, the embedding dimension sufficient to fully capture pairwise interactions grows exponentially. As a quick recap
of representations:

   • For a single coordinate (e.g., x), the embedding dimension is proportional to |Sx | = N , the number of possible
     positions along the x-axis.
   • When extending to two coordinates (x and y), the domain becomes S = Sx × Sy , resulting in an embedding dimension
     of |S| = N 2 , reflecting all possible 2D positions.
   • Adding agent-specific policies (e.g., Sq = {R, U}) introduces an additional multiplicative factor, so the domain
     expands to S = Sq × Sx × Sy , with |S| = 2N 2 .
   • We can even add a new feature called “species”, from a different nature, such as species ∈ {H, P}, which would make
     the domain size even larger.

Now let us look at the colliding agents environments from Appendix B.1 and Appendix B.1.3, with a slightly more complex
example, to motivate the novel HyperFeatureAttention.

Non-Identical    Agents Revisited. Consider L agents on a Sr = [N ] × [N ] grid, each with initial coordinates ri =
 ni nyi ∈ [N ]2 . The agents have identities from ℓi ∈ Sspcs = {H, P}. The Hs get +1 reward if they catch (collide with)
 x       

a P, but the Ps get −1 reward when they are caught. The agents also have fixed policies qi ∈ Sq = {R, U}, that agents with
policy R always moves to right and policy U always moves to up. From our earlier step by step results in Appendix B.1.3
the value functions for the agents can be written as
                                         X
                                              f nxi , nyi , qi , ℓi , nxj , nyj , qj , ℓj wnxj ,nyj ,qj ,ℓj .
                                                                                         
                                  Vi =                                                                                (35)
                                        j∈[L]
                                         j̸=i

With our earlier discussion (Appendix B), we know that a linear self-attention needs O(|S|2 |Sspcs |2 |Sq |2 ) parameters to
represent such functions, which is exponential in the number of features.

                                                            37
                          A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

However, after careful thinking on each case in our experiment, one can write the value functions as
                   X n
                            I {ℓi = P, ℓj = H} I {qi = R, qj = U} I nxi − nxj ≈ nyi − nyj
                                                                     
         Vi =
                   j∈[L]: j̸=i

                             +I {ℓi = H, ℓj = P} I {qi = R, qj = U} I nxi − nxj ≈ nyi − nyj
                                                                     

                             +I {ℓi = P, ℓj = H} I {qi = U, qj = R} I nxi − nxj ≈ nyi − nyj
                                                                     

                             +I {ℓi = H, ℓj = P} I {qi = U, qj = R} I nxi − nxj ≈ nyi − nyj
                                                                     

                             +I {ℓi = P, ℓj = H} I {qi = R, qj = R} I nyi ≈ nyj
                                                                     

                             +I {ℓi = H, ℓj = P} I {qi = R, qj = R} I nyi ≈ nyj
                                                                     

                             +I {ℓi = P, ℓj = H} I {qi = U, qj = U} I nxi ≈ nxj
                                                                     
                                                                                 o
                             +I {ℓi = H, ℓj = P} I {qi = U, qj = U} I nxi ≈ nxj
                                                                     
                                                                                   (I {ℓj = P} − I {ℓj = H}) .

Defining
                                    fah11 (ℓi , ℓj ) = I {ℓi = P, ℓj = H} + I {ℓi = H, ℓj = P} ,
                                   fah21 (qi , qj ) = I {qi = R, qj = U} + I {qi = U, qj = R} ,
                                   fah31 (ri , rj ) = I nxi − nxj ≈ nyi − nyj ,
                                                        

                                    fah12 (ℓi , ℓj ) = I {ℓi = P, ℓj = H} + I {ℓi = H, ℓj = P} ,
                                    fah22 (qi , qj ) = I {qi = R, qj = R} ,
                                  fah32 nyi , nyj = I nyi ≈ nyj ,
                                                        

                                    fah13 (ℓi , ℓj ) = I {ℓi = P, ℓj = H} + I {ℓi = H, ℓj = P} ,
                                    fah23 (qi , qj ) = I {qi = U, qj = U} ,
                                  fah33 nxi , nxj = I nxi ≈ nxj ,
                                                        

                                       wahji (ℓj ) = I {ℓj = P} − I {ℓj = H} ,
and H = {h1 , h2 , h3 }, H = {a1 , a2 , a3 } the same equation can be organized into
                                                                           !              !
                                       X X Y                                  Y
                                                                      h
                                                         fah ϕha,i , θa,j            h
                                                                                wah γa,j
                                                                                        
                              Vi =                                                         ,                                     (36)
                                        h∈H    j∈[L]   a∈A                       a∈A

               h
where ϕha,i , θa,j  h
                   γa,j are the corresponding features picked by the corresponding functions.10 Owing to our discussion
from Appendix B, we can easily conclude that the functions fah1 can be represented exactly with an attention score matrix
of Cha1 ∈ R|Sspcs |×|Sspcs | similarly for fah2 we need Cha2 ∈ R|Sq |×|Sq | and for fah3 we need Cha3 ∈ R|Sr |×|Sr | . As a result
total number of parameters required is O(|Sspcs |2 + |Sq |2 + |Sr |2 ) which is linear in the number of features, much better
than linear self-attention which was exponential. We can calculate the exact number of parameters instead of the big-O
versions. For N = 360, approximately 106 parameters is sufficient for HyperFeatureAttention, while self-attention requires
approximately 107 parameters.
Implications for Attention Mechanisms. While the linear self-attention mechanism discussed in Theorem 3.1 can represent
pairwise interactions exactly, its parameter requirements also scale with the embedding dimension d. This limits its
applicability in cases where the number of features (or their cardinality) is very large. For instance, in scenarios with
additional discrete features such as temporal information, behavioral categories, or hierarchical roles, the exponential growth
in |S| quickly becomes a bottleneck.
The exponential growth observed here highlights the need for alternative attention mechanisms that can efficiently handle
high-dimensional domains without explicitly embedding all feature combinations. This sets the stage for the introduction of
  10
     Equation 36 is more general than the toy example discussed above: in that example a single (a, h) pair selects the same feature for
its keys and queries, whereas the equation is written to accommodate cases where the selected features may differ. Therefore, we used
different symbols ϕ, θ

                                                                  38
                          A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

a novel attention module HyperFeatureAttention, designed specifically to address exponential embedding growth while
preserving the ability to model complex interactions across diverse features.
Also, one may concern that in practice we use layers of multi-head attention, which may possibly express Eq. 3, without
exponential embedding dimension. However, we briefly go over in Theorem F.6 and the following justification that
even two layer multihead linear self-attention cannot express (3) (which is easily expressed by a single layer single head
HyperFeatureAttention).11

F.2. HyperFeatureAttention Definition
The non-identical agents revised discussion was just a toy example for setting the stage for our novel HyperFeatureAttention
model. Let us first generalize the discussion. We have Φ as the set of all features and M = |Φ| as total number of features
in our setting that are distinct in nature. For feature ϕ, denote its domain Sϕ , domain size |Sϕ |, and allocated embedding
size dϕ . From the previous discussion, to represent any function of the form Eq (36) the total embeddingdimension for       
                                                                                                                            2
                                                   Q                                                            Q
linear self-attention grows exponentially as d = ϕ∈Φ |Sϕ | and the corresponding number of parameters O            ϕ∈Φ |Sϕ |   .
However, using a function of the form,

                                                             ⊙                              ⊙
                                                         "                              !                        !#
                                                   X         Y                              Y
                                     lin                                (h,a)       ⊤                  V,(h,a)
                               HFA         (X) =                   XC           X                 XW                  ,
                                                   h∈H       a∈A                            a∈A

                                               P
we only need embedding dimension of d = ϕ∈Φ |Sϕ | and the corresponding number of parameters grows linearly in the
number of features O(M ).
Remark F.1 (Note on Approximate Embeddings). Although the following discussion is somewhat perpendicular to our main
focus on how entities (or features) interact, we include it briefly for completeness. In principle, self-attention may require an
embedding dimension exponential in the number of features, but in practice, one often leverages the Johnson–Lindenstrauss
lemma: in high-dimensional spaces, random projections yield vectors that are approximately orthonormal with embedding
dimension only linear in the number of features. Concretely, each feature ϕ typically contributes O(log |Sϕ |) dimensions
rather than O(|Sϕ |), so total embedding dimension becomes d = O(|Φ|).12 However, in HyperFeatureAttention module,
this same Johnson-Lindenstrauss argument implies a dimension requirement of O(log |Φ|) (rather than O(|Φ|)). Hence,
even though both methods rely on approximate embeddings, the exponential gap remains: standard self-attention requires
dimension linear in the number of features, whereas our module reduces it to logarithmic.

After all these motivations, we can now formally define the Multihead HyperFeature Attention. First, we provide the
definition of Multihead Self Attention in (Vaswani et al., 2023) here for comparison.
Definition F.2 (Multihead Self-Attention). Let X ∈ RT ×d denote the input sequence of T tokens, where d is the embedding
dimension. Multihead self-attention computes a sequence of contextualized embeddings as follows:

                                      SAh = Softmax Qh (Kh )⊤ Vh ,
                                                             
                                                                                        ∀h ∈ {1, . . . , H},                           (37)
                                                                   1                H       O
                                      MHA(X) = Concat(SA , . . . , SA )W ,                                                             (38)

where:
   11
      In this comparison, we deliberately bias the setup toward standard self-attention by pitting a two-layer, multi-head SA model against
a single-layer, single-head HFA.
   12
      Of course, some features are more crucial than others and thus allocated more dimensions. In addition, while simpler or ordered
features (e.g. spatial coordinates) can often be embedded in far fewer dimensions. For example, spatial x-coordinates, are intrinsically
one-dimensional, allowing them to be embedded into a much lower-dimensional vector space than |Sx |. This is because x-coordinates
form an ordered set with a linear relationship between positions. Conversely, features like the nucleotide bases A, G, T , and C lack such
linear relationships —there is no linear relationship between ”adenineness” or ”guanineness”— and therefore, these features tend to
occupy a 4-dimensional vector space. Some features, such as color, lie somewhere in between. Scientifically, a single frequency (e.g.,
400–484 THz) is sufficient to specify the color ”rose red,” but in practical encodings like RGB, it is represented by three integers (e.g.,
[255, 3, 62]). However, in the language it is even more complex. As explained in (Jensen, 2022), the qualities of the color red, such as its
warmth or contrast with green, cannot be deduced solely from its frequency as an electromagnetic wave. Even less can its emotional
associations —such as romance or warmth— be reduced to a property of the wave. Instead, these properties emerge from the collective
processes generated by light absorbed through the eyes, which trigger a hierarchy of neural processes in the brain. These processes
ultimately lead to thoughts and emotions that we experience as color perception.

                                                                       39
                          A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions
                     h                       h                             h
  • Qh = XWQ , Kh = XWK , and Vh = XWV                                          are the query, key, and value matrices for the h-th head,
    respectively.
         d
  • dh = H is the dimension of each attention head.
         h       h           h
  • WQ , WK , WV ∈ Rd×dh and WO ∈ Rd×d are learnable weight matrices.

  • Softmax(·) is applied along the last dimension.

Definition F.3 (Multihead HyperFeatureAttention). We define two versions of Multihead HyperFeatureAttention, “value-
product” and “non-value-product” respectively. Let X ∈ RT ×d denote the input sequence of T tokens, where d is the
embedding dimension.
                                 Q                            Q
                                      ⊙         (h,a)   (h,a) ⊤   ⊙         (h,a)
                        Softmax              Q       (K      )     a∈[A] V       , if value product,
                HFAh =            Q a∈[A]                                                                     (39)
                                      ⊙
                        Softmax
                                        a∈[A] Q
                                                (h,a)
                                                      (K(h,a) )⊤ V(h) , otherwise,
                 MHFA(X) = Concat(HFA1 , . . . , HFAH )WO ,                                                                         (40)

where:

                         (h,a)                           (h,a)                          (h,a)
  • Q(h,a) = XWQ          , K(h,a) = XWK         , and V(h,a) = XWV     are the query, key, and value matrices for the
                                                                (h)
    h-th head a-th attention score, respectively (V(h) = XWV for no value product case).

  • For each head we specify dh such that h dh = d and the attention size for that head is dha = dh /A.
                                            P

         (h,a)       (h,a)         h             (h,a)           (h)
  • WQ     , WK      ∈ Rd×da , WV     , WV      ∈ Rd×dh and WO ∈ Rd×d are learnable weight matrices.
    Q⊙
  •    represents Hadamard product of matrices and [A] = {1, . . . , A}

  • Softmax(·) is applied along the last dimension.

Remark F.4. In the above definition the no value product HFA has the same number of parameters as SA (assuming same d),
yet value product version has slightly more parameters depending on the orders.
Remark F.5 (Rotary Positional Embedding). One can easily incorporate rotary positional embedding into this module by
applying the corresponding rotation matrices R as RQ(h,a) and RK(h,a) to keys and queries just as they are explained in
(Su et al., 2023).

Lastly, one may concern that in practice we use layers of multi-head attention, which may possibly express Eq. 3, without
exponential embedding dimension. However, we show in the following remark that even two layer multihead linear
self-attention cannot express (3) (which is easily expressed by a single layer single head HyperFeatureAttention). In this
comparison, we deliberately bias the setup toward standard self-attention by pitting a two-layer, multi-head SA model
against a single-layer, single-head HFA.
Remark F.6 (Limitations of Two-Layer Multihead Linear Self-Attention). Two-layer multihead linear self-attention cannot
represent factorized cross-feature interaction functions of the form
                   X                                         X
                        f (1) (ai , aj )f (2) (bi , bj ), or   f (1) (ai , bj )f (2) (bi , aj ), or similar variants, (41)
                     j                                                 j


where the token embedding is defined as xi = concat(ai , bi ).

Brief justification of Remark F.6. Consider a two-layer multihead linear self-attention model. Each layer consists of H
attention heads, where the output of each head is computed as:
                                                     L
                                       (h)
                                                     X
                                                           x⊤  (h)
                                                                   xj w(h) (xj ),
                                                                     
                                  SAi            =          i C                         for m = 1, . . . , H,
                                                     j=1


                                                                           40
                         A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

with C(h) ∈ Rd×d as the attention matrix for head h, and w(h) (·) as a linear map. The outputs of the heads are concatenated
and optionally projected using a weight matrix WO . For a single-layer multihead attention, the overall output for token i is
a linear combination of bilinear terms of the form:
                                                               L
                                                             H X
                                                             X
                                                                            x⊤  (h)
                                                                                    xj w(h) (xj ).
                                                                                      
                                             MHAi =                          i C
                                                             h=1 j=1


In a two-layer model, the first layer computes:
                                                L
                                               nX                                         o
                                                  x⊤  (h)
                                                          xj w(h) (xj ), h = 1, . . . , H1 ,
                                                            
                             hi = LinearCombine    i C
                                                             j=1

and passes {hi }i∈[T ] as input to the second layer. The second layer then computes:
                                                  L
                                       (p)
                                                  X
                                                        h⊤  (p)
                                                                hk v(p) (hk ),
                                                                  
                                  SAi        =           i C                                 for p = 1, . . . , H2 .
                                                  k=1


By definition, hi is a linear combination of sums of bilinear terms in xi and xj . Therefore, hi remains a sum of bilinear
expressions across {xi , xj }.
The second layer operates on hi and computes terms of the form h⊤                i C
                                                                                     (p)
                                                                                         hk . Since hi itself is bilinear, this results
in expressions that are multi-bilinear in xi , xj , xk . However, it does not introduce multiplicative interactions between
independent subsets of features (e.g., ai , aj vs. bi , bj ).
Factorization is absent: The target function j f (1) (ai , aj )f (2) (bi , bj ) requires the output to be a product of two independent
                                             P
terms: one depending solely on (ai , aj ) and the other on (bi , bj ). Multihead attention combines bilinear terms additively,
not multiplicatively, so it cannot achieve this factorization.
Suppose f (1) and f (2) are chosen such that f (1) (ai , aj ) is orthogonal to f (2) (bi , bj ). In this case, any additive combination
of bilinear terms cannot approximate the product f (1) (ai , aj )f (2) (bi , bj ), regardless of how many layers or heads are used.
Even with two layers of multihead linear self-attention, the mechanism remains additive and cannot express functions
requiring multiplicative factorization of independent feature interactions. This limitation highlights the inability of 2 layer
multihead self-attention to represent cross-feature factorized interactions such as j f (1) (ai , aj )f (2) (bi , bj ) or its variants.
                                                                                   P


G. HyperAttention
G.1. Defining HyperAttention
Generalizing the Definition 6.1 to order n,
                                                       d
                                                       X
                             Aij1 j2 ...jn−1 =                     Cαζ1 ζ2 ...ζn−1 Xiα Xj1 ζ1 Xj2 ζ2 ...Xjn−1 ζn−1
                                                  αζ1 ζ2 ...ζn−1
                                                      d
                                                      X
                             Vj1 j2 ...jn−1 τ =                   Xj1 ξ1 Xj2 ξ2 ...Xjn−1 ξn−1 WξV1 ξ2 ...ξn−1 τ
                                                  ξ1 ξ2 ...ξn−1
                                                        L
                                                        X
                               HAlin
                                 iτ (X) =                              Aij1 j2 ...jn−1 Vj1 j2 ...jn−1 τ ,
                                                  j1 ≤j2 ≤...jn−1

                       ×n
where C, WV ∈ Rd and we denote (i, j1 , j2 , . . . )-th entry of a tensor T as Tij1 j2 ... . Similar to how self-attention
implements low rank approximation for efficiency, i.e,
                                                                                              R
                                                                  ⊤                          X
                                        C = WQ WK                         and      Cαβ =            Q
                                                                                                   Wασ  K
                                                                                                       Wβσ
                                                                                               σ

                                                                            41
                         A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

where WQ and WK ∈ Rd×R are chosen low rank R < d, where d is the maximum rank can a d × d matrix have, we can
have low rank approximation of HyperAttention as
                                                                     R
                                                                     X                         1     2         n−1
                                                                               Q
                                              Cαζ1 ζ2 ...ζn−1 =               Wασ WζK1 σ WζK2 σ ...WζKn−1 σ
                                                                         σ
                                                                   R
                                                                   X                1      2             n−1    n
                                         WξV1 ξ2 ...ξn−1 τ =                 WξV1 σ WξV2 σ ...WξVn−1 σ WτVσ ,
                                                                     σ

                         i      i
where each WQ , WK , WV ∈ Rd×R . Similarly, we choose R less than the maximum rank can an n dimensional tensor
have. Finally adding the non-linearity, the full definition becomes the following.
Definition G.1 (HyperAttention with parameter sharing). Let X ∈ RT ×d be the input sequence of T tokens, where d is the
embedding dimension. For the n-th order HyperAttention, define:

                                                              Q = XWQ ∈ RT ×R ,
                                                             K = XWK ∈ RT ×R ,
                                                                                    1
                                                            V1 = XWV ∈ RT ×R ,
                                                                               2
                                                            V2 = WV ∈ Rd×R .
                                                    ×n
We also define permutation mask M ∈ RT                   such that,

                                       Mi,j1 ,...,jn−1 = −∞ (1 − I [j1 ≥ j2 ≥ · · · ≥ jn−1 ]) ,

where I is the indicator function that is equal to 1 if the condition satisfied, 0 otherwise. Then, for each token index i and
output dimension τ ,
                                                                           R
                                                                                                              !
                                                                           X
                  Ai,j1 ,...,jn−1 = Softmax(j1 ,...,jn−1 ) Mi,j1 ,...,jn−1   Qi,σ Kj1 ,σ Kj2 ,σ . . . Kjn−1 ,σ ,
                                                                                               σ=1
                                       R
                                       X
                  Vj1 ,...,jn−1 ,τ =                                           2
                                             Vj11 ,σ Vj12 ,σ . . . Vj1n−1 ,σ Vτ,σ .
                                       σ=1


The HyperAttention output is computed as:
                                                                  T
                                                                  X
                                        HAi,τ (X) =                                Ai,j1 ,...,jn−1 Vj1 ,...,jn−1 ,τ ,
                                                             j1 ,...,jn−1 =1

which is equivalent to
                                                                  T
                                                                  X
                                        HAi,τ (X) =                                Ai,j1 ,...,jn−1 Vj1 ,...,jn−1 ,τ .
                                                             j1 ≥···≥jn−1

For multihead HyperAttention, we compute multiple heads indexed by h ∈ {1, . . . , H}, each with independent learnable
            h     h      h,1        h,2
weights WQ , WK , WV , and WV . The multihead HyperAttention output is given by:

                             MutiHeadHA(X) = Concat HA1 (X), . . . , HAH (X) WO ,
                                                                                   


where HAh (X) ∈ RT ×dh , dh = d/H, and WO ∈ Rd×d is a learnable projection matrix.

We also have another version which is very similar to the previous definition but the parameters corresponding to different
keys and values are not shared.
Remark G.2. To increase the implicit bias one could use Mi,j1 ,...,jn−1 = −∞ (1 − I [j1 > j2 > · · · > jn−1 ]) instead of the
mask stated in the definition. In this version the block would be more specialized to learning n-way interactions instead of
lower order interactions.

                                                                               42
                         A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

Definition G.3 (HyperAttention without parameter sharing). Let X ∈ RT ×d be the input sequence of T tokens, where d is
the embedding dimension. For the n-th order HyperAttention, define:

                                           Q = XWQ ∈ RT ×R ,
                                                               m
                                         Km = XWK                  ∈ RT ×R ,       ∀m ∈ {1, . . . , n − 1},
                                                               m
                                         Vm = XWV                  ∈ RT ×R ,       ∀m ∈ {1, . . . , n − 1},
                                                           n
                                              n        V            d×R
                                         V =W                  ∈R         .

Then, for each token index i and output dimension τ ,
                                                                                        R
                                                                                                                                     !
                                                                                        X
                   Ai,j1 ,...,jn−1 = Softmax(j1 ,...,jn−1 )           Mi,j1 ,...,jn−1         Qi,σ Kj11 ,σ Kj22 ,σ . . . Kjn−1
                                                                                                                            n−1 ,σ
                                                                                                                                         ,
                                                                                        σ=1
                                        R
                                        X
                   Vj1 ,...,jn−1 ,τ =         Vj11 ,σ Vj22 ,σ . . . Vjn−1   Vn .
                                                                      n−1 ,σ τ,σ
                                        σ=1

The rest of the definition is the same as the previous definition G.1.

G.2. Representation Abilities of HyperAttention
Theorem G.4. A single layer of order n linear HyperAttention (without parameter sharing), with embedding dimension
d = |S|, can represent any function of the form
                                X
                    Fi =                   f (X (i) , X (j1 ) , X (j2 ) , ..., X (jn−1 )) ws(j1 ),s(j2 ),s(jn−1 )
                             j1 ,j2 ,...,jn−1 ∈[L]


for all elements in the sequence, i.e, i ∈ [L]. The parameter–sharing variant of HyperAttention can express the same class
of functions provided that (i) the weight tensor w is fully symmetric, i.e. invariant under any permutation of its indices, and
(ii) the kernel f is symmetric in its last n − 1 arguments, X (j1 ) , . . . , X (jn−1 ).

Proof. Seeing that d = |S|, the embeddings can be orthonormal. Consequently, the same arguments of the Proof of
Theorem 3.1 in Appendix B follows.

G.2.1. S KIP -T RIGRAM B UG
Let us now illustrate how higher-order dependencies may arise with a more practical example on skip-trigrams.
Next-Token Prediction A common strategy        for training language models is next-token prediction: given a sequence of
tokens X (0) , X (1) , . . . , X (L − 1) , the model learns to predict the next token. In our setting, the label for training is
X (L − 1). For simplicity, we focus on the final row of the softmax self-attention output (corresponding to X (L − 1)).
Concretely, the model produces a probability distribution l over the vocabulary, defined as:
                                                P                           
                                                  j∈[L] exp f X (i) , X (j)    wX (j)
                                          l =      P                            .
                                                      j∈[L] exp f X (i) , X (j)


During inference, the next token ŷ is then sampled from this distribution.
As shown by (Elhage et al., 2021), self-attention can learn skip-trigrams. For example, in a sentence fragment such as
“. . . keep . . . in [ ],” the model might predict the next token “mind,” completing the phrase as “. . . keep . . . in mind.” In the
context of our work, we can interpret this phenomenon in two steps: (1) self-attention identifies that “in” is influenced by
“keep” (i.e., f (in, keep) is large), and (2) it leverages that influence to generate the token “mind.”
However, as shown in (Elhage et al., 2021), the same mechanism that raises the probabilities of the correct skip-trigrams
“. . . keep . . . in mind” and “. . . keep . . . at bay” also inadvertently increases the probabilities of the erroneous skip-trigrams
“. . . keep . . . in bay” and “. . . keep . . . at mind.” This phenomenon, known as the “skip-trigram bug,” arises from how

                                                                              43
                        A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

attention influences these completions. From our interaction perspective, increasing the probability of “. . . keep . . . in mind”
can be done in two ways (1) Increasing f (in, keep), which unfortunately also boosts the probability of “. . . keep . . . in bay.”
(2) Modifying wkeep to bias the model more strongly towards “mind,” which reduces the probability of “. . . keep . . . at bay.”
Either approach makes it challenging for the model to consistently prefer the correct completions without also amplifying
incorrect ones, thereby explaining the skip-trigram bug.
Hyper-Attention for Avoiding Skip-Trigram Bugs. The crux of the skip-trigram bug is that a single self-attention
head (or pairwise interaction) tries to capture the entire phrase “. . . keep . . . in mind” by boosting f (in, keep) alone. This
inadvertently increases the probability of other completions like “. . . keep . . . in bay” whenever wkeep also points toward
“bay.” However, many real-world contexts contain additional tokens that disambiguate the correct completion. For instance,
the sentence “...keep the deadline in [ ]” strongly suggests “mind” over “bay”.
In our framework of hyper-attention, one can introduce a ternary interaction term
                                                                       
                                                  f in, keep, deadline

that focuses specifically on the triplet {“in”, “keep”, “deadline”}, allowing the model to favor “mind” without simultaneously
boosting “bay.” Concretely, if we let
                                                                  
                                           f X (i) , X (j) , X (k) and wX (j),X (k)

govern three-way effects (rather than just pairwise f (in, keep)), the probability of “mind” can be increased via a higher-order
interaction f (in, keep, the deadline) specifically tailored to that context. In doing so, we need not raise all completions of
“. . . keep . . . in [ ],” and thus avoid inadvertently increasing “. . . keep . . . in bay.”
Hence, by modeling triplet or higher-order interactions, hyper-attention more flexibly captures context-specific phrases like
“keep the deadline in mind,” while suppressing incorrect ones like “keep the deadline in bay,” mitigating the skip-trigram
bug highlighted.

G.3. Efficient Strategy to Mitigate O(Ln ) Computation Complexity
For simplicity, we focus on third order HyperAttention but the same arguments generalize to any order. Let’s first look at
linear version with recalling the definition of third order linear HyperAttention (Definition 6.1) in the tensor decomposition
format of Definition G.1.
                                                                    R
                                                                    X
                                                     Ai,j1 ,j2 =            Qi,σ Kj11 ,σ Kj22 ,σ ,
                                                                    σ=1
                                                                    R
                                                                    X
                                                     Vj1 ,j2 ,τ =                             3
                                                                            Vj11 ,σ Vj22 ,σ Vτ,σ ,
                                                                    σ=1
                                                                    L
                                                                    X
                                              HAlin
                                                iτ (X) =                    Aij1 j2 Vj1 j2 τ .
                                                                    j1 j2


Here, each equation has O(L3 R) computational complexity, so the total calculation has O(L3 R) complexity. We can write
the same expression as
                                        XL nX  R                    onX R                     o
                           HAlin
                               iτ (X) =          Qi,σ K 1
                                                             K 2
                                                        j1 ,σ j2 ,σ        V 1
                                                                                  V
                                                                            j1 ,σ̃ j2 ,σ̃ τ,σ̃ .
                                                                                    2
                                                                                         V 3
                                                                                                                   (42)
                                             j1 j2    σ=1                                 σ̃=1

Changing the order of summations (take the summations over js first),
                                            R
                                          R X
                                          X                    L
                                                              nX                           L
                                                                                         onX                         o
                            HAlin
                              iτ (X) =                 Qi,σ           Kj11 ,σ Vj11 ,σ̃                                  3
                                                                                                     Kj22 ,σ Vj22 ,σ̃ Vτ,σ̃ ,   (43)
                                          σ̃=1 σ̃=1             j1                            j2


its computational complexity can is reduced to O(LR2 ). Generally R ≪ L because R simply corresponds to attention head
dimension. Thus, computational complexity reduces significantly.

                                                                       44
                       A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

As for the softmax or general nonlinear version, we use techniques similar to those in (Katharopoulos et al., 2020;
Choromanski et al., 2022). For general nonlinear case Eq.42 can be written as,
                                       PL                                    nP                          o
                                                                                  R
                                         j 1 j 2
                                                 sim Qi,: , Kj11 ,: , Kj22 ,:     σ=1
                                                                                                        3
                                                                                      Vj11 ,σ Vj22 ,σ Vτ,σ
                         HAlin
                             iτ (X) =                 PL                                                   ,
                                                                                1     2
                                                        j1 j2 sim Qi,: , Kj1 ,: , Kj2 ,:

where sim(.) is classical non-linearities (for softmax it is exponentiation of the attention scores). This can be approximated
with a function of the form
                                  PL PR2                       1         2
                                                                                 nP
                                                                                      R       1    2      3
                                                                                                             o
                        lin          j1 j2    σ=1 ϕ(Qi: )σ ϕ(Kj1 : )σ ϕ(Kj2 : )σ      σ=1 Vj1 ,σ Vj2 ,σ Vτ,σ
                    diτ (X) =
                    HA                           PL PR2                                                      ,
                                                                               1        2
                                                   j1 j2    σ=1 ϕ(Qi: )σ ϕ(Kj1 : )σ ϕ(Kj2 : )σ


where ϕ : RR → RR2 is a nonlinear transformation chosen accordingly   √ to the sim and R2 ∈ Z+ is O(R). (Alman & Song,
                                                                      3
2023) show that if entries of the input matrices Q, K are less than o( log L) than for ϵ = 1/poly(L)
                                                                                  lin
                                                         max HAlin
                                                               iτ − HAiτ ≤ ϵ
                                                                    d
                                                         i,τ

Consequently, the same summation order change trick (43) applies for nonlinear HyperAttentions, too.

G.4. HyperAttention Learning
For simplicity we prove the convergence of order three linear HyperAttention. However, after this proof, extension to any
order is trivial. Recall Definition 6.1, which is copied here.
Definition G.5 (Third order Linear HyperAttention).
                                                                d
                                                                X
                                              Aij1 j2 =                 Cαζ1 ζ2 Xiα Xj1 ζ1 Xj2 ζ2
                                                               αν1 ν2
                                                               d
                                                               X
                                              V j1 j2 τ =              Xj1 ξ1 Xj2 ξ2 WξV1 ξ2 τ
                                                               ξ1 ξ2
                                                                L
                                                                X
                                           HAlin
                                             iτ (X) =                   Aij1 j2 Vj1 j2 τ ,
                                                               j1 ≤j2

where we denote (i, j, k)-th entry of a tensor T as Tijk and C ∈ Rd×d×d , WV ∈ Rd×d×d2 .

Seeing that our main aim is understanding the attention scores, the core mechanism defining self-attention, we choose
d2 = 1 to simplify the convergence analysis. Thus, WV is two dimensional tensor which we denote as w in this subsection.
Assumption G.6 (Weak Realizability). The task is realizable, i.e, there exist C∗ and w∗ that perfectly fits the training data.
Theorem G.7 (Convergence of HyperAttention to Zero Training Error). Let the dimensions d = |S| and d2 = 1. Also, let
                                  2
the initial parameters C(t) = 0, wαβ (0) ≥ b > 0, ∀i. Then, under the assumptions G.10 and G.6, gradient flow on
                                                                   B                   2
                                                           1 X
                                    MSE          V
                                                                 HAlin    (n)
                                                                                − Y(n) ,
                                                                             
                                L         C, W           =         C,WV X
                                                           B n=1

converges to zero training error.

Before proving the theorem we will derive the gradients and state some lemmas that are going to be useful in the proof.

Gradients with Respect to C and w.
                                            B                    ⊤ ∂HAlin X(n)                     
                          ∂LMSE (C, w)   2 X           
                                       =       HAlin X(n) − y(n)
                             ∂Cµνσ       B n=1                        ∂Cµνσ

                                                                         45
                        A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions


                             ∂HAlin
                                         
                                i   X(n)     X X X X (n) (n) (n) (n) (n)
                                           =        Xiµ Xjν Xjγ Xkσ Xkθ wγθ
                               ∂Cµνσ         γ σ               k j≤k
                                                               
                    ∂LMSE (C, w)   2 XX      X X (n) (n) (n) (n)      ⊤
                                 =      wγθ    Xjν Xjγ Xkσ Xjθ  X(n)      D(n)
                       ∂Cµνσ       B n                                  µ,:
                                               γθ              k j≤k

Similarly we can find the gradient with respect to w.
                                             B                    ⊤ ∂HAlin X(n)                                   
                           ∂LMSE (C, w)   2 X           
                                        =       HAlin X(n) − y(n)
                              ∂wγθ        B n=1                         ∂wγθ

                                  ∂HAlin X(n)
                                              
                                                  XX
                                                =    (Xiµ Xjν Xkσ Cµνσ ) Xjγ Xkθ
                                     ∂wγθ
                                                            k j≤k
                                                                 
                  ∂LMSE (C, w)   2 XX          X X (n) (n) (n) (n)        
                               =         Cµνσ    Xjν Xjγ Xkσ Xjθ  X(n) ⊤       D(n)
                     ∂wγθ        B n µνσ                                     µ,:
                                                              k j≤k


In this subsection, we will change our perspective and prove the things in the one hot encoding basis, similarly to what we
did in Section C. That is, we define
                                            (n) one−hot
                                                          X (n)
                                          Xiµ           =      Xik Bµk ,
                                                                     k
                                                                   X
                                                one−hot
                                               Cµνσ     =                 Bµi Bνj Bσk Cijk ,
                                                                   ijk
                                                                   X
                                                one−hot
                                               wγθ      =                 Bγi Bθj wij ,
                                                                    ij

and use the one − hot encoded versions. However, again, we abuse the notation and omit the subscript in this subsection,
e.g. we write C but we mean the one − hot version C one−hot , in the rest of this subsection. Lastly, in this section, we
denote eµ ∈ R|S| as unique one-hot encoded vector for all µ ∈ S, i.e. the base vector.
Now we state some lemmas which are anologous to Lemmas C.1 and C.2.
                                  P P          (n) (n) (n) (n)
Lemma G.8. In the embedding base, k j≤k Xjν Xjγ Xkσ Xjθ is diagonal in the sense that it can be written as

                                                      (n)   (n)      (n)    (n)
                                        XX
                                                  Xjν Xjγ Xkσ Xjθ = Γ(n)
                                                                     νσ δνγ δσθ ,
                                          k j≤k

where                                                  XX
                                              Γ(n)
                                               νσ =                δX (n) (j),ν δX (n) (k),σ ,
                                                        k j≤k

and δ is kronocker delta function, that is,                 (
                                                             1,            if ν = γ
                                                      δνγ =
                                                             0,            if ν ̸= γ

Proof. Seeing that we are in the embedding base,
                X X (n) (n) (n) (n) X X                                                    
                        Xjν Xjγ Xkσ Xjθ =        eX (n) (k) σ eX (n) (k) θ eX (n) (j) ν eX (n) (j) γ
                   k j≤k                               k j<k
                                                      XX
                                                  =               δX (n) (j),ν δX (n) (j),γ δX (n) (k),σ δX (n) (k),θ
                                                       k j≤k


                                                                     46
                          A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions
                                                                                
                                                    XX
                                                  =   δX (n) (j),ν δX (n) (k),σ  δνγ δσθ
                                                         k j≤k

the last equality follows from the identity δij δik = δij δjk .
Lemma G.9. If we choose initial parameters as C(0) = 0 and wαβ (0) ≥ b > 0, then wαβ (t) ≥ b > 0, ∀α, β and ∀t ≥ 0.

Proof. Firstly, we will show that wα (t)2 ≥ wα (0)2 , ∀t and ∀i, than the statement in the lemma will follow similar to the
proof of Lemma C.2. Using the previous gradient derivations and Lemma G.8,
                                                                                            
        dCµνσ          ∂LMSE (C, w)          2 XX              X X (n) (n) (n) (n)                 ⊤
                 = −η                  = −η             wγθ            Xjν Xjγ Xkσ Xjθ  X(n)            D(n) ,
          dt               ∂Cµνσ            B n                                                       µ,:
                                                        γθ             k j≤k

                    2 XX                                   ⊤
                                  (n) (n)
               = −η         wγθ Xkσ Xjθ Γνσ δνγ δσθ X(n)         D(n) ,
                    B n                                      µ,:
                         γθ
                                                                                 
          dwγθ      ∂LMSE (C, w)       2 XX               X X (n) (n) (n) (n)             
               = −η              = −η           Cµνσ             Xjν Xjγ Xkσ Xjθ  X(n) ⊤       D(n) ,
           dt          ∂wγθ            B n µνσ                                               µ,:
                                                           k j≤k
                    2 XX                           
               = −η         Cµνσ Γνσ δνγ δσθ X(n) ⊤       D(n) .
                    B n µνσ                           µ,:




Let Λa and Λb be matrices that are diagonal in the embedding base B. However, we again abuse the notation. We do not
rewrite the one − hot in Λa,b one−hot = BCB⊤ and denote it just as Λa,b in the rest of the proof. We can now write
             X         dCµνσ a b            2 XX                      X                      
                                                                                                  (n) ⊤
                                                                                                        
                 Cµνσ         Λνν Λσσ = −η             Cµνσ Λaνν Λbσσ     wγθ Γ(n)
                                                                                νσ δνγ δσθ X                  D(n) ,
             µνσ
                         dt                 B   n µνσ
                                                                                                          µ,:
                                                                      γθ
                                            2  X   X                           
                                                                                   (n) ⊤
                                                                                          
                                      = −η             Cµνσ wνθ Λaνν Λbσσ Γ(n)
                                                                           νσ    X              D(n) ,
                                            B n µνσ                                         µ,:

                X       dwγθ a b            2 XX a b                X                        
                                                                                                  (n) ⊤
                                                                                                        
                   wγθ        Λνν Λσσ = −η             Λγγ Λθθ wγθ      Cµνσ Γ(n)
                                                                                νσ δ νγ δ σθ    X             D(n) ,
                          dt                B n                     µνσ
                                                                                                          µ,:
                γθ                                  γθ
                                            2 XX                               
                                                                                   (n) ⊤
                                                                                          
                                      = −η             Cµνσ wνθ Λaνν Λbσσ Γ(n)
                                                                           νσ    X              D(n) .
                                            B n µνσ                                         µ,:


Consequently we have
               X          dwγθ a b      X        dCµνσ a b
                    wγθ       Λνν Λσσ =     Cµνσ      Λνν Λσσ ,
                           dt           µνσ
                                                   dt
               γθ
                    d X 2 a b              d X 2
                           wγθ Λνν Λσσ =          C Λa Λb ,
                    dt                     dt µνσ µνσ νν σσ
                       γθ
                    X                      X                      X                     X
                          2
                       wγθ  (t)Λaνν Λbσσ =      2
                                               wγθ (0)Λaνν Λbσσ +    2
                                                                    Cµνσ (t)Λaνν Λbσσ −    2
                                                                                          Cµνσ (0)Λaνν Λbσσ .
                    γθ                     γθ                          µνσ                 µνσ




Letting Λa = diag (eα ) and Λb = diag (eβ ),
                           2         2
                          wαβ (t) = wαβ                                        2
                                        (0) + ∥C:,α,β (t)∥2 − ∥C:,α,β (0)∥2 = wαβ (0) + ∥C:,α,β (t)∥2
where the last equality follows because C(0) = 0. As a result we reach to
                                                      2         2
                                                     wαβ (t) ≥ wαβ (0) ≥ b2                                           (44)

                                                                  47
                        A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions
            dw
Seeing that dtαβ is finite ∀t, wαβ (t) is continuous. As a result if wα (0) ≥ b > 0, then wαβ (t) ≥ b, ∀t which can be proven
by contradiction. Assume ∃t∗ > 0 such that wαβ (t∗ ) ≤ b. By Equation 44, wαβ (t∗ ) ≤ −b < 0. By intermediate value
theorem ∃τ ∈ (0, t∗ ) such that wαβ (τ ) = 0, so wαβ2
                                                       (τ ) = 0 < wαβ 2
                                                                        (0) ≥ b2 , which contradicts with (44)

Proof of Theorem G.7. Seeing that d2 = 1 we denote two dimensional reduction of the three dimensional tensor WV as w.
Thus the HyperAttention formula becomes,
                                                                                                
                                   XL     Xd                                d
                                                                            X
                    HAlin
                        i (X) =
                                             Cαζ1 ζ2 Xiα Xj1 ζ1 Xj2 ζ2     Xj1 ξ1 Xj2 ξ2 wξ1 ξ2 
                                          j1 ≤j2        αζ1 ζ2                                           ξ1 ξ2


Gradient Flow for the Residuals and the Loss
                                        dC      ∂LMSE (C, w)                       dw      ∂LMSE (C, w)
                                           = −η              ,                        = −η
                                        dt          ∂C                             dt          ∂w
Following similar steps as in the proof of Theorem 4.4,
                          (m)
                       dDi                     X           (m)
                                                                 XX          (m)       (m)       (m)     (m)       ∂LMSE (C, w)
                                =−η                     Xiµ               Xjν Xkσ Xjγ Xkθ wγθ
                         dt                                                                                           ∂Cµνσ
                                           µνσγθ                 k j≤k
                                                                                                                       MSE
                                                           (m)               (m)       (m)              (m)      (m) ∂L    (C, w)
                                               X               XX
                                    −η                  Xiµ               Xjν Xkσ Cµνσ Xjγ Xkθ
                                                                                                                         ∂wγθ
                                           νµσγθ                 k j≤k

Substituting the gradients
                                                                
      (m)
  dDi          2η X n (m)              X X (m) (m) (m) (m)
            =−            Xiµ wγ ′ θ′        Xjν Xkσ Xjγ ′ Xkθ′ 
    dt         B     ′  ′
                 µνσγ θ                 k j≤k
                                                                  
                             XX            X X (n) (n) (n) (n)         ⊤      o
                           ×          wγθ       Xjν Xjγ Xkσ Xjθ  X(n)    D(n)
                                                                                                                   µ,:
                                    n     γθ                  k j≤k
                                                                                         
                                    2η X n (m)                  X X (m) (m) (m) (m)
                                  −            Xiµ′ Cµ′ ν ′ σ′        Xjν ′ Xkσ′ Xjγ Xkθ 
                                    B ′ ′ ′
                                      µ ν σ γθ                   k j≤k
                                                                                              
                                                      XX                X X (n) (n) (n) (n)                                                                 o
                                                    ×            Cµνσ         Xjν Xjγ Xkσ Xjθ  X(n) ⊤                                                D(n)
                                                                                                                                                 µ,:
                                                                         n µνσ                   k j≤k


By Lemma G.8,
                 (m)                                                                                                   ⊤
             dDi              2     X               (m)
                                                                                   XX                           
                       =−η                     Xiµ wγ ′ θ′ Γ(m)
                                                            νσ δνγ ′ δσθ ′                       wγθ Γ(n)
                                                                                                      νσ δνγ δσθ X
                                                                                                                   (n)
                                                                                                                          D(n)
               dt             B                                                                                             µ,:
                                  µνσγ ′ θ ′                                        n       γθ
                              2      X               (m)              (m)
                                                                                         XX                            
                                                                                                                          (n) ⊤
                                                                                                                                
                        −η                        Xiµ′ Cµ′ ν ′ σ′ Γν ′ σ′ δν ′ γ δσ′ θ                 Cµνσ Γ(n)
                                                                                                             νσ δνγ δσθ X                 D(n)
                              B                                                                                                     µ,:
                                  µ′ ν ′ σ ′ γθ                                             n µνσ

                                  2 X                                                            ⊤
                                                  (m)
                                                                    X
                        = −η                Xiµ wνσ Γ(m)
                                                     νσ              D(n) wνσ Γ(n)
                                                                               νσ X
                                                                                    (n)
                            B µνσ                n
                                                                 µ,:

                           2 X (m)           (m)
                                                 XX        (n)
                                                                     
                        −η      Xiµ′ Cµ′ γθ Γγθ      Cµγθ Γγθ X(n) ⊤        D(n)
                           B ′                   n µ
                                                                        µ,:
                                  µ γθ

Now let us define,
                                                                   (n)           (n)
                                                                 Miµνσ = Xiµ wνσ Γ(n)
                                                                                  νσ


                                                                              48
                       A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

                          (n)
Also define matrixize Miµνσ as M such that first dimension of M is vectorization of n and i the second dimension is
                                         3
vectorization of µ, ν, σ, so M ∈ RBL×d . There exists a similar matrix M2 such that
                                                 dD       2 
                                                              MM⊤ + M2 M⊤
                                                                          
                                                     = −η               2
                                                  dt      B
Similar to what we in the proof of Theorem 4.4, it follows that

                                             dLMSE (C, w)    4η
                                                          ≤ − 2 D⊤ MM⊤ D                                                (45)
                                                 dt          B
Now, we will write Eq. 45 differently, reexpressing D. Thanks to Assumption G.6, i.e. the realizability, we can write
              (n)
                     X (n) (n) (n)                 (n) (n)
                                                                  X (n) (n) (n)                (n) (n) ∗
                                                                                         ∗
            Di =           Xiµ Xjν Xkσ Cµνσ Xjγ Xkσ wγσ −             Xiµ Xjν Xkσ Cµνσ       Xjγ Xkσ wγθ     .
                      µνσγθ                                           µνσγθ

By Lemma G.8,
                                                                                      
                                      (n)
                                                 X
                                                                           ∗    (n) ∗
                                    Di       =         Xiµ Cµνσ Γ(n)
                                                                 νσ wνσ − Cµνσ Γνσ wνσ
                                                 µνσ

By Lemma G.9, 1/wνσ is defined, so we can write
                                                    ∗                            ∗
                                                       X                         
                (n)
                       X
                                 (n)            ∗  wνσ         (n)          ∗   wνσ
               Di =        Xiµ Γνσ wνσ Cµνσ − Cµνσ      =     Miµνσ Cµνσ − Cµνσ       .
                       µνσ
                                                   wνσ    µνσ
                                                                                wνσ

Now again we can vectorize along n, i and vectorize along µ, ν, σ which leads to
                                                                      ∗
                                                                       
                                                                   ∗w
                                             D = Mvec C − C ∗ .
                                                                    w

Following the same steps as in the proof of Theorem 4.4,

dLMSE (C, w)    4η              4η    h            ∗ i⊤             h            ∗ i
             ≤ − 2 D⊤ M M⊤ D = − 2 vec C − C∗ diag ww     M⊤ M M⊤ Mvec C − C∗ diag ww
    dt          B               B
Using the Lemma C.3, the same inequality can be written as

          dLMSE (C, w)           4η                        h                  ∗ i 2       4η
                           ≤ − 2 λmin M⊤ M Mvec C − C∗ diag ww                         = − 2 λmin M⊤ M ∥D∥2 ,
                                                                                                          
                 dt              B                                                          B
where λmin M⊤ M           is the minimum eigenvalue of M⊤ M. Thus, if there exists a constant ψ such that
                        

λmin M⊤ (t)M(t) ≥ ψ > 0, ∀t, then the training loss stops decreasing only when D reaches to all zero vector,
                      

i.e, training loss stops decreasing only when it reaches to zero, which is stated more rigorously in Lemma C.4.
Lower Bound on the Eigenvalues of M⊤ M.

                           λmin M⊤ M = σmin M⊤ M =                                  ∥M⊤ Mu∥2 ,
                                               
                                                                          min                                           (46)
                                                                        u:∥u∥2 =1

                                                                                                    3
where the first equality follow because M⊤ M is symmetric and positive semi definite and u ∈ Rd . We also know
                                 ⊤                X X (n)               (n)
                                 M M µνσµ′ ν ′ σ′ =        Xiµ Γnνσ wνσ Xiµ′ Γnν′ σ′ wν ′ σ′ .
                                                           n i∈[L]


For ease of notation we can tensorize the things back to the µ, ν, σ. Thus,
                                                           X
                                                   ∥u∥ =       u2µνσ = 1
                                                               µνσ


                                                                 49
                        A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions

It follows that                        X X X (n)
                            ⊤                           (n) (n)
                                            Xiµ Γ(n)
                                
                            M Mu µνσ =           νσ wµν Xiµ′ Γν ′ σ ′ wν ′ σ ′ uµ′ ν ′ σ ′                           (47)
                                               n∈B i∈[L] µ′ ν ′ σ ′

Remembering                                   X                           X
                                                     Xiµ Xiµ′ =                   δX (i),µ δX (i),µ′ ,
                                             i∈[L]                        i∈[L]

Eq. 47 becomes
                                                                     
                                                                         (n)
                        ⊤         X         X   X
                                     Γ(n)
                            
                        M Mu µνσ =    νσ wνσ
                                                  δX (i),µ δX (i),µ′  Γν ′ σ′ wν ′ σ′ uµ′ ν ′ σ′
                                         n∈B                 µ′ ν ′ σ ′    i∈[L]
                                                                      (n)
                                         X XX
                                     =                       Γ(n)
                                                              νσ wνσ Γν ′ σ ′ wν ′ σ ′ uX (i)n ν ′ σ ′
                                         n∈B i∈[L] ν ′ σ ′



                              
Recalling the definition Bµ = n ∈ B : µ ∈ X (n) , we do the same trick we did when we were getting Eq. 26 form Eq. 25,
so we get                                                                             !
                                                                         (n)
                             ⊤            X X             X
                                                       (n)      (n)
                                   
                             M Mu µνσ =               sµ       Γνσ wνσ Γν ′ σ′ wν ′ σ′ uµν ′ σ′
                                                 µ∈S n∈Bµ                    ν ′ σ′
                             ′   ′
Vectorizing along ν, σ and ν , σ we reach to
                                                                                                                
                                       X                         X                                        
                           M⊤ Mu =           diag (w)                    s(n)
                                                                           µ vec Γ
                                                                                  (n)
                                                                                      vec⊤ Γ(n)  uµ,: .             (48)
                                       µ∈S                     n∈Bµ


Notice the similarity between Eq. 48 and 27. Thus, defining
                                                                            ..
                                                                                     
                                                                          .
                                                 ZBµ =    ⊤    (n)                             ,
                                                       vec Γ       
                                                             ..
                                                              .                           n∈Bµ

we follow the same steps seen after Eq. 27 and reach to

                                                      λmin M⊤ M ≥ b2 ζ 2 ,
                                                               

                                                          2
                                                                 
where we used the bound wνσ ≥ b and the Assumption G.10 -σmin ZBµ ≥ ζ 2 .
Assumption G.10 (Training Data Versatility). For all µ ∈ S,

                                                                            ..
                                                                                     
                                                                          .
                                                 ZBµ =    ⊤    (n)                             ,
                                                       vec Γ       
                                                             ..
                                                              .                           n∈Bµ

is full column rank.

H. Comparison Between the Attention Models
We have introduced two novel models (HyperFeatureAttention in Appendix F, HyperAttention in Appendix G) and
mentioned some approximations to reduce computational complexity (in Appendix G.3). In this section, letting embedding
dimension to be d, sequence length to be L, we compare those models in terms of number of parameters, computational
complexity, and abilities in Table H, too.

                                                                          50
                         A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions


                                            Table 3. Comparison Between Attention Models
                                                    Computational
                                Model                                              Captures
                                                     Complexity
                                                            
                           Self Attention              Θ L2                  Mutual interactions
                       HyperFeatureAttention           Θ L2             Couplings of mutual interactions
                          HyperAttention
                                                        Θ (Ln )                n-way interactions
                             of order n
                        Linear Self Attention            Θ (L)         Mutual interactions (approximate)
                               Linear                                        Couplings of mutual
                                                         Θ (L)
                       HyperFeatureAttention                              interactions (approximate)
                       Linear HyperAttention
                                                         Θ (L)          n-way interactions (approximate)
                             of order n


Starting with self-attention, it captures mutual interactions between entities.13 If it has multiple heads, it can capture
summation over mutual interactions between features of the entities. It has Θ(d2 ) parameters, and its computational
complexity is Θ(L2 ). In order to reduce the computational complexity to Θ(L), people came up with approximations called
“Linear Attention” (Katharopoulos et al., 2020; Wang et al., 2020). However, despite the name, the method is generally used
to approximate softmax self-attention.
HyperFeatureAttention captures couplings of mutual interactions between features.14 If it has multiple heads, it can capture
summation over couplings of mutual interactions between features. Same as self-attention, HyperFeatureAttention has
Θ(d2 ) parameters, and its computational complexity is Θ(L2 ). The same Linear Attention approximations can be applied to
HyperFeatureAttention, reducing its computational complexity to Θ(L). Seeing that the main goal of the paper is not this
approximation for HyperFeatureAttention, we did not show it explicitly.
As for HyperAttention of order n, it captures up to nth order interactions.15 If it has multiple heads, it can capture summation
over up to nth order interactions between features of the tokens. It has Θ(d2 ) parameters, and its computational complexity
is Θ(Ln ). Using similar Linear Attention approximations, in Appendix G.3, we explained how to reduce computational
complexity of HyperAttention to Θ(L).
One might contend that standard self-attention can, in principle, capture these complex interactions “in surprising ways.”
The key difference is that our modules achieve comparable expressiveness with far fewer parameters—and therefore lower
memory and compute overhead. While we do not advocate replacing conventional self-attention with HyperAttention
or HyperFeatureAttention, we propose these mechanisms as complementary enhancements. In a typical multi-head
architecture, certain heads may employ standard self-attention while others utilize HyperFeatureAttention (of varying
orders) or HyperAttention to capture richer, higher-order interactions. Depending on the computational constraints, the
HyperAttentions may leverage the linear approximations described in Appendix G.3.

I. Figures




  13
     Refer to Theorems 3.1, 4.4, 4.6, and 4.8
  14
     Refer to Section 5 and Appendix F
  15
     Refer to Section 6 and Appendix G

                                                                  51
                          A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions




                        (a) Learned C                                                        (b) Devised C L
    0                                                                     0
  50                                                        0.6          50
                                                                                                                                  0.10
 100                                                        0.4          100                                                      0.08
                                                            0.2
 150                                                                     150                                                      0.06
                                                            0.0
 200                                                          0.2        200                                                      0.04
                                                              0.4                                                                 0.02
 250                                                                     250
                                                              0.6                                                                 0.00
 300                                                                     300                                                        0.02
                                                              0.8
 350                                                                     350
        0         100          200          300                                0       100           200          300


Figure 2. Comparison of learned vs. devised parameters for sinusoidal embedding: (a) Devised matrix C∀L showing the original devised
structure, (b) Learned matrix C demonstrating the emergent but non-interpretable patterns. While visually distinct, both parameterizations
lead to equivalent model behavior through different mathematical organizations.




                                                                    52
                         A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions




                           (a) C                                                                (b) C L
    0                                                                     0
  50                                                                     50
                                                                                                                                 1.0
 100                                                        1.0          100
                                                                                                                                 0.8
 150                                                        0.5          150                                                     0.6
                                                            0.0
 200                                                                     200                                                     0.4
                                                              0.5
 250                                                                     250                                                     0.2
                                                              1.0
 300                                                                     300                                                     0.0

 350                                                                     350
        0   50    100 150 200 250 300 350                                      0   50   100 150 200 250 300 350

                          (c) C v                                                              (d) C Lv L
    0                                                                     0
  50                                                                     50
                                                            0.0                                                                  0.0
 100                                                          0.2        100
                                                                                                                                   0.2
 150                                                          0.4        150                                                       0.4
 200                                                          0.6        200                                                       0.6
                                                              0.8                                                                  0.8
 250                                                                     250
                                                              1.0                                                                  1.0
 300                                                                     300
 350                                                                     350
        0   50    100 150 200 250 300 350                                      0   50   100 150 200 250 300 350


Figure 3. Equivalence of learned parameters with one-hot embedding in domain embedding base (here the parameters are already in
the domain embedding base so we did not transfer them): (a) Cµν learned parameters in domain embedding base, (b) C ∀L devised
                                                                                                                         ∀L   ∀L
parameters in domain embedding base, (c) Cµν Wν0 the interesting matrix in domain embedding base, (d) Transformed Cµν       Wν0   using
original parameters. The mean squared difference between (c) and (d) is O(10−5 ), demonstrating functional equivalence despite different
parameter organizations.




                                                                    53
                         A Theoretical Study of (Hyper) Self-Attention through the Lens of Interactions




                           (a) C                                                                (b) C L
    0                                                                       0
  50                                                                       50
                                                                                                                                 1.0
 100                                                                       100
                                                            20                                                                   0.8
 150                                                                       150                                                   0.6
                                                            0
 200                                                                       200                                                   0.4
 250                                                            20         250                                                   0.2

 300                                                                       300                                                   0.0

 350                                                                       350
        0   50    100 150 200 250 300 350                                        0   50   100 150 200 250 300 350

                          (c) C v                                                             (d) C Lv L
    0                                                                       0
  50                                                                       50
                                                                                                                                 0.0
 100                                                            0.2        100
                                                                                                                                   0.2
 150                                                            0.4        150                                                     0.4
 200                                                            0.6        200                                                     0.6
                                                                0.8                                                                0.8
 250                                                                       250
                                                                1.0                                                                1.0
 300                                                                       300
 350                                                                       350
        0   50    100 150 200 250 300 350                                        0   50   100 150 200 250 300 350


Figure 4. Equivalence of learned parameters with sinusoidal embedding in domain embedding base: (a) Cµν learned parameters in domain
embedding base, (b) C ∀L devised parameters in domain embedding base, (c) Cµν Wν0 the interesting matrix in domain embedding base,
                     ∀L  ∀L
(d) Transformed Cµν     Wν0  using original parameters. The main squared difference between (c) and (d) is O(10−5 ), demonstrating
functional equivalence despite different parameter organizations. Additionally as a side note, comparing (b) with Fig. 2 (b), we observe
the advantage of sinusoidal embeddings in terms of their parameter efficiency within the C = WQ WK ⊤ matrix, particularly when
relative positions are more important than absolute positions.




                                                                      54
