Could you explain the concept of hierarchical attention in transformer architectures?
Answer
Hierarchical attention applies self-attention at multiple levels of granularity instead of one flat pass over all tokens: first local attention within segments (words inside a sentence, frames inside a shot), then global attention across the aggregated segment representations (sentences inside a document). This mirrors the natural structure of long inputs, cuts the quadratic cost dramatically, and yields interpretable focus at each level.
(1) Local Level (Fine-Grained): Each segment runs its own self-attention over its tokens, producing one segment embedding; cost grows with segment length, not document length.
(2) Global Level (Coarse-Grained): The segment embeddings attend over each other, producing a document-level representation.
(3) Efficiency Gain: A document of tokens split into
segments of
tokens costs
in attention entries instead of
, a large saving when
.

Figure 1: Two attention levels: local attention inside each segment, then global attention over segment embeddings to form the document representation.
Mathematical Formulation (cost for n = s × m tokens):
Where:
is the total token count, split into
segments of
tokens each (
).
- The local term runs
independent
attentions; the global term runs one
attention over segment embeddings.
Example (Document Classification): With tokens as
sentences of
words, flat attention scores
pairs, while hierarchical attention scores only
, roughly 60x fewer pairs.
Leave a Reply