Longformer: The Long-Document Transformer | Paper Notes
8/28/2025
https://arxiv.org/abs/2004.05150
Sliding window attention is a strategy designed to solve the standard Transformers' problem of efficiently processing long documents. Every token calculates an attention score with every other token, which is with sequence length .
The two main points of sliding window attention pattern are: local context is most important and computation must scale linearly. Each token pays attention to a fixed-size window () of tokens to its left and right. The complexity becomes .
In a transformer with layers, the receptive field size at the top layer is . "Receptive field" refers to the extent of the input data that a particular neuron is influenced by.
Sliding window can be dilated, which they call "dilated sliding window." The window has gaps of size dilation . Assuming a fixed and for all layers, the receptive field is . In a multi-head attention, each head can have its own , which they found improves performance because some heads focus on local context and others on longer context.
The sliding window is good for efficiently building local context, but they note that it is not flexible enough to learn task-specific representations. Certain NLP tasks require specific tokens to gather information from the entire sequence, not just their local neighborhood. "Global attention" is applied to a few task-specific tokens.
Sliding window attention is a sparse operation. It only needs to compute a few diagonals of the full attention matrix. They provide their own implementations of the kernel.
8/28/2025