Attention Mechanisms  · July 2020

BigBird

intermediate

long-contextefficiency

Combine three structured sparse-attention patterns (random, window, global) so the model preserves universal-approximation properties while running in O(N) attention. The first theoretically-grounded sparse attention with a Turing-completeness proof.

§ 1 · Premise

Sparse attention without theoretical guarantees

Full self-attention costs Θ(N2dh)\Theta(N^2 \cdot d_h) compute and stores an N×NN \times N logit matrix per head per layer. At N=4096N = 4096 with dh=64d_h = 64 and 12 heads per layer, that is ~200M float multiplies per head per layer for the logit step alone and a 256 MB activation per layer before the softmax — both quadratic in the sequence length. By mid-2020 several sparse-attention designs had reduced this cost to subquadratic, but each had a different asymptotic guarantee and none had a formal expressivity result. The two relevant predecessors:

The open question both left: are these sparse patterns fundamentally limited compared to full attention? Are there sequence-to-sequence functions that full attention can represent but sparse-attention models provably cannot?

BigBird (Zaheer et al. 2020, arXiv 2007.14062) is the first sparse attention with a positive answer. Its construction combines three patterns — local window + global tokens + random — and the paper proves that with these three patterns the layer is (a) a universal approximator of sequence-to-sequence functions in the same sense as full attention (Yun et al. 2019, arXiv 1912.10077), and (b) Turing complete given unbounded depth and precision (Pérez et al. 2019, arXiv 1901.03429 prove this for full attention; BigBird extends the result). The construction is also O(N)O(N) in attention compute, the lowest asymptotic in any well-defined sparse-attention design at the time of publication.

The contribution in one sentence: a sparse-attention design whose three-pattern union has both proven theoretical guarantees and O(N)O(N) asymptotic cost — closing the “sparse-attention-but-is-it-as-expressive?” gap that prior designs had left open.

§ 2 · Derivation

Window + global + random as a sparse-graph attention

Standard self-attention defines an attention graph G[N]×[N]G \subseteq [N] \times [N] where edge (i,j)G(i, j) \in G means query ii attends to key jj. Dense attention uses the complete graph Gfull=[N]2G_{\mathrm{full}} = [N]^2. Sparse attention parameterizes a subset GsparseGfullG_{\mathrm{sparse}} \subseteq G_{\mathrm{full}}:

Attni=j:(i,j)Gsparsesoftmaxj ⁣(qikjdh)vj.\mathrm{Attn}_i = \sum_{j: (i, j) \in G_{\mathrm{sparse}}} \mathrm{softmax}_j\!\left(\frac{\mathbf{q}_i \cdot \mathbf{k}_j}{\sqrt{d_h}}\right) \mathbf{v}_j.

The cost per layer is O(Gsparsedh)O(|G_{\mathrm{sparse}}| \cdot d_h), vs O(N2dh)O(N^2 \cdot d_h) for full attention. The question is what structure GsparseG_{\mathrm{sparse}} must have to preserve full- attention expressivity.

BigBird’s GBBG_{\mathrm{BB}} is the union of three sub-graphs (Zaheer et al. 2020, §2):

  1. Window attention GWG_W: each query attends to ww consecutive keys centered (or left-windowed in the causal case) on its position. GW=Nw|G_W| = N \cdot w. The same pattern as SWA.
  2. Global attention GGG_G: a designated set G[N]\mathcal{G} \subseteq [N] of g=Gg = |\mathcal{G}| indices, where every query attends to every jGj \in \mathcal{G} and every iGi \in \mathcal{G} attends to every key. GG=2gNg2|G_G| = 2 g N - g^2.
  3. Random attention GRG_R: each query is assigned rr independently and uniformly sampled key indices. GR=Nr|G_R| = N \cdot r.

The total edge count is GBB=N(w+r)+2gNg2=O(N)|G_{\mathrm{BB}}| = N(w + r) + 2 g N - g^2 = O(N) when w,g,rw, g, r are constants in NN. The Zaheer et al. defaults are w=256w = 256, g=32g = 32, r=32r = 32, giving 300\sim 300 key slots per query at any NN — a 13× reduction at N=4096N = 4096 and an 85× reduction at N=16384N = 16384.

Why all three patterns? The proof of universal approximation needs the attention graph to satisfy three properties simultaneously (Zaheer et al. 2020, Theorem 1 and Appendix A):

(i) GsparseG_{\mathrm{sparse}} must be connected — there must be a path between every pair of nodes. The window alone gives O(N/w)O(N / w)-diameter connectivity (a chain); not enough for any O(logN)O(\log N)-depth construction.

(ii) The graph must have small effective diameter — bounded by a small constant independent of NN, so that information from any token reaches any other within a fixed number of hops. Window alone fails; the strided pattern from Sparse Transformer achieves O(logN)O(\log N) diameter; BigBird needs O(1)O(1).

(iii) The graph must admit a finite-cover argument matching Yun et al.’s universal- approximation proof for full attention — every pair of close-enough function arguments must be discriminable by some attention path.

The three patterns each contribute one property:

The expander-graph result. A random graph on NN vertices where each vertex has rr uniformly random out-edges is, with probability 1o(1)1 - o(1), an ε\varepsilon-expander for ε=Ω(1)\varepsilon = \Omega(1) when r3r \geq 3 (Friedman 2003 on the Alon conjecture; Zaheer et al. 2020 invoke this as background). Concretely: the random pattern has spectral gap close to the Ramanujan bound, giving O(logN)O(\log N) random-walk mixing — meaning information from any token reaches any other in O(logN)O(\log N) hops through random edges alone.

Why not just use the strided pattern from Sparse Transformer? Strided patterns with stride \ell achieve O(logN)O(\log_\ell N) diameter via stacked layers — apparently fine. The issue is the finite-cover discrimination needed in property (iii): strided patterns are periodic, so two tokens at the same residue class mod \ell are connected by the same path structure as every other pair in the same residue class. The random pattern breaks this symmetry — each query has a different random key set, so the discrimination is position-specific. The universal-approximation proof in Sparse Transformer’s framework would have to construct a separate argument for each residue class; BigBird sidesteps this by using a single random pattern that works for all positions.

The two theorems. With GBBG_{\mathrm{BB}} as defined above:

Theorem 1:The class of BigBird sequence-to-sequence functions is a universal approximator\mathbf{Theorem\ 1}: \text{The class of BigBird sequence-to-sequence functions is a universal approximator}

(Zaheer et al. 2020, §3). For any continuous permutation-equivariant f:RN×dRN×df: \mathbb{R}^{N \times d} \to \mathbb{R}^{N \times d} and any ε>0\varepsilon > 0, there exists a BigBird transformer with depth and width poly(N,1/ε)\mathrm{poly}(N, 1/\varepsilon) that approximates ff within ε\varepsilon uniformly.

Theorem 2:BigBird is Turing complete.\mathbf{Theorem\ 2}: \text{BigBird is Turing complete.}

(Zaheer et al. 2020, §3.1). Given unbounded depth and arbitrary precision, a BigBird stack can simulate any Turing machine. Same statement as Pérez et al. 2019’s result for full attention.

Cost per layer. Total memory is O(N(w+g+r))O(N (w + g + r)) for the sparse attention matrix. Compute is O(N(w+g+r)dh)O(N (w + g + r) \cdot d_h) per head. At the defaults w=256,g=32,r=32w = 256, g = 32, r = 32 and N4096N \leq 4096, the cost is bounded by O(N320dh)O(N \cdot 320 \cdot d_h), asymptotically linear in NN but with a large constant (~320). For N1024N \leq 1024 the full N2N^2 attention is actually faster.

§ 3 · Reference implementation

Three masks unioned

def bigbird_attention(q, k, v, window_size, global_idx, num_random):
    # q, k, v: [B, T, d_h]      global_idx: [G] indices of global tokens
    B, T, d = q.shape
    # 1. Window mask: |i - j| <= window_size // 2
    rows = torch.arange(T).view(T, 1)
    cols = torch.arange(T).view(1, T)
    window_mask = (cols - rows).abs() <= (window_size // 2)
    # 2. Global mask: row in global_idx OR col in global_idx
    global_mask = torch.zeros(T, T, dtype=torch.bool)
    global_mask[global_idx, :] = True
    global_mask[:, global_idx] = True
    # 3. Random mask: r random columns per row
    random_mask = torch.zeros(T, T, dtype=torch.bool)
    for i in range(T):
        sampled = torch.randperm(T)[:num_random]
        random_mask[i, sampled] = True
    full_mask = window_mask | global_mask | random_mask
    scores = (q @ k.transpose(-2, -1)) / d**0.5      # [B, T, T] — still O(T^2) in this sketch
    scores = scores.masked_fill(~full_mask, float("-inf"))
    return scores.softmax(-1) @ v

This sketch computes the full T×TT \times T score matrix then masks — illustrative but asymptotically wrong. A production implementation gathers the w+g+rw + g + r keys per query into a [B,T,w+g+r,dh][B, T, w + g + r, d_h] buffer (the “block-sparse” formulation in Zaheer et al. 2020, §4) so that the attention matmul is O(N(w+g+r)dh)O(N \cdot (w + g + r) \cdot d_h).

BigBird's three structured patterns: a window of width 2W around the diagonal, R random keys per query, and G global positions visible to and from everyone. Drag sliders to see the patterns combine.Attention pattern (L = 64; sparsity = 78.1%)q=0q=63k=0k=63PatternsWindow (|q−k| ≤ W)Random (R per query)Global (first G rows/cols)Attended: 898/4096 cellsNaive dense: O(L²) = 4096BigBird: O(W + R + G)·L ≈ 960
BigBird combines three patterns. The window (blue) gives every query local context. The random picks (light gray) provide long-range connectivity and let the paper prove universal approximation properties. Theglobal set (dark gray) connects every query to a small fixed group and vice versa — the rows AND columns at indices 0..G−1 are filled. Total attended cells grow O(L), not O(L²).

§ 4 · Empirical evidence

What BigBird and follow-ups measure

Long-document QA. Zaheer et al. 2020 Table 4 reports BigBird at N=4096N = 4096 matching or beating RoBERTa-Large at N=512N = 512 on HotpotQA (F1 75.7 vs 73.5), TriviaQA (F1 81.9 vs 74.3), and WikiHop (accuracy 75.9 vs 72.4) — while running 4×\sim 4 \times less attention compute per layer at the longer context.

Genomics. BigBird’s most cited long-tail application is the genomics task in §5: training on chromosome-length DNA sequences (N=8192N = 8192 tokens) for promoter-prediction and chromatin modeling. BigBird matches the dense-attention baseline at N=512N = 512 while accessing 16× longer context, giving a meaningful real-domain win on a task where standard transformers could not even fit the data.

Ablation of the three components. Zaheer et al. 2020 Table 6 ablates the random component by training BigBird with r=0r = 0 (window + global only — i.e., Longformer). On the QA suite the no-random variant loses 0.5–1.5 F1 points but does not break catastrophically. The interpretation: the random component’s theoretical role (expander-graph mixing) gives an asymptotic guarantee, but in the finite-depth, finite-NN regime of real models, the window- plus-global pattern is empirically close to sufficient. This is the result that justified production decoders skipping the random pattern.

Random pattern in causal/decoder settings. The random pattern interacts awkwardly with autoregressive masking — a token ii randomly attending to j>ij > i would violate causality. The Zaheer et al. construction is encoder-only; the paper does not propose a decoder version. Independent work on decoder-side sparse attention (Sparse Transformer; later SWA + global) all used deterministic patterns.

Where production went. Production long-context decoder LLMs largely adopted window + occasional global without the random component. Mistral 7B (Jiang et al. 2023, arXiv 2310.06825) uses pure SWA. Gemma 2 / Gemma 3 (Gemma Team 2024, arXiv 2503.19786, §3.2) interleave SWA layers with full-global layers at a 5:1 ratio — BigBird without the random, modulated across depth rather than within each layer. Empirically these match BigBird’s long-context quality at substantially simpler implementation. See SWA for the descendant pattern that won at scale.

Independent reproduction. The BigBird paper’s reference code has been re-implemented by the Hugging Face team (BigBirdModel in transformers), and the long-document QA numbers have been independently reproduced on HotpotQA and Natural Questions. The Turing-completeness proof has been verified by subsequent work on sparse-attention expressivity (Sanford et al. 2022, arXiv 2211.05498, §4 cites BigBird’s argument directly).

Open questions / what isn’t measured. I don’t know of a public study isolating the contribution of random pattern at fixed total edge count. Zaheer et al.’s ablation drops rr to zero, but at fixed GBB|G_{\mathrm{BB}}| one could trade window size for random count and ask which choice helps more. No such sweep has been published. The theoretical argument says random is essential; the empirical evidence says window + global is sufficient — and the gap between these statements has not been closed in print.

Lineage

Cite

BibTeX entry for the original paper
@article{arxiv2007_14062,
  title  = {Big Bird: Transformers for Longer Sequences},
  author = {Manzil Zaheer and others (Google Research)},
  year   = {2020},
  eprint = {2007.14062},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2007.14062}
}

Or cite the paper directly: arXiv:2007.14062.

Export

BibTeX
@article{arxiv_2007_14062,
  title         = {Big Bird: Transformers for Longer Sequences},
  author        = {Manzil Zaheer et al. (Google Research)},
  year          = {2020},
  eprint        = {2007.14062},
  archivePrefix = {arXiv},
  url           = {https://arxiv.org/abs/2007.14062}
}
CSL JSON
{
  "id": "arxiv_2007_14062",
  "type": "article-journal",
  "title": "Big Bird: Transformers for Longer Sequences",
  "author": [
    {
      "literal": "Manzil Zaheer et al. (Google Research)"
    }
  ],
  "issued": {
    "date-parts": [
      [
        2020
      ]
    ]
  },
  "URL": "https://arxiv.org/abs/2007.14062",
  "number": "2007.14062",
  "source": "arXiv"
}
RIS
TY  - JOUR
TI  - Big Bird: Transformers for Longer Sequences
AU  - Manzil Zaheer et al. (Google Research)
PY  - 2020
JO  - arXiv
AN  - arXiv:2007.14062
UR  - https://arxiv.org/abs/2007.14062
ER  -