Foundations to Frontier
Tests
E. Deep Learning › E12 Transformer Architectures

BigBird

BigBird (Zaheer and colleagues, NeurIPS 2020) is a sparse attention pattern with linear cost. Each query attends to a sliding window of neighbours, a few random keys and a few global tokens, computed in blocks for GPU efficiency. The authors proved that this pattern, unlike a window alone, keeps the theoretical power of full attention (universal approximation and Turing completeness), and used it for sequences 8 times longer than BERT, including genomics. This page covers the three attention components, block sparsity, graph intuition and theory. In the exercises you build BigBird masks and count pairs, then measure exactly how many attention layers information needs to travel between tokens. With a window alone the average path grows linearly (29.5 hops at 256 tokens, 448 at 4096). Three random keys per token make it about logarithmic (3.0 to 4.5 hops), and global tokens make it 2.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Neighbours, strangers and hubs

BigBird gives each word three kinds of contacts:

  • its neighbours (a window);
  • a few random words anywhere in the document;
  • a few hub words that talk to everyone.

The random contacts work like a social network’s “six degrees of separation”: with only a few long-range links, any two words are connected in a handful of steps instead of hundreds. Hubs make it two steps. The cost stays linear in the length. Compare the window and BigBird patterns in the demo.

Transformer lab
Computed pairs: 136 of 256 for 16 tokens. Sparse patterns grow linearly with length instead of quadratically.
Why engineers care

Long sequences (genomes, long documents, long telemetry) need attention that scales. Knowing how information travels through a sparse pattern tells you how many layers a model needs.

📝 Quick check (Level 0)
0/3 answered
  1. 1. BigBird's three kinds of attention:
  2. 2. Random links make paths between tokens…
  3. 3. BigBird's cost grows…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Attention per query:
    • a window of ±w, plus r random keys, plus g global tokens: 2w + 1 + r + g keys;
    • with w = 3, r = 3 and g = 2 that is 12;
    • global tokens attend to everything.
  • Blocks:
    • BigBird groups tokens into blocks of b = 64;
    • each query block attends to 3 window blocks, 3 random blocks and 2 global blocks, about L·b·8 pairs;
    • at L = 4096 that is 2.1 M pairs, 12.5% of full attention.
  • Paths as a graph: draw an edge j → i when query i attends to key j. Information needs as many layers as the length of the shortest path.
    • Window only: the diameter is ⌈(L − 1)/w⌉, 1365 hops for L = 4096 and w = 3, linear in L.
    • Random links: the graph becomes a small world, with typical paths of about ln L / ln k for k links per node (6 for L = 4096, k = 4).
    • Any global token: at most 2 hops.
  • Models: BigBird-ITC uses existing tokens as global; BigBird-ETC adds extra global tokens. Both handle up to 4096 tokens.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Keys per query for w = 3, r = 3, g = 2:
  2. 2. Window-only diameter for L = 4096, w = 3:
  3. 3. Max hops with a global token:

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

BigBird in code

Exercise 1.

  • The mask combined window, random and global attention: every row of a global token was full.
  • Non-global rows had at most 9 keys.
  • The block-pair count for L = 4096 and b = 64 was 2,097,152.

Practice.

  • Hugging Face BigBirdModel with attention_type="block_sparse", block_size=64 and num_random_blocks=3. For short inputs it falls back to full attention.
  • Block sparsity matters: computing 64 × 64 dense blocks runs efficiently on GPUs, while scattered single keys do not.
  • BigBird-Pegasus applies it to long-document summarisation. In genomics, BigBird read longer DNA contexts for tasks such as promoter prediction.
from transformers import BigBirdModel, BigBirdConfig
cfg = BigBirdConfig(attention_type="block_sparse", block_size=64, num_random_blocks=3, max_position_embeddings=4096)
model = BigBirdModel(cfg)
out = model(input_ids=torch.randint(0, cfg.vocab_size, (1, 4096)))
🐍 Exercise 1: BigBird masks
Build a BigBird mask with window, random and global attention and count block-sparse pairs.
📝 Quick check (Level 2)
0/3 answered
  1. 1. BigBird's block size:
  2. 2. Blocks matter because…
  3. 3. BigBird found use in…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Why random edges.

  • Random graphs with a few links per node are expanders: paths are O(log L) long, and information mixes quickly.
  • A window graph is a path-like lattice, with paths O(L/w).
  • Adding a handful of random links per node turns the lattice into a small world (Watts and Strogatz), keeping locality while shortening paths.

What BigBird proved.

  • Zaheer et al. showed that sparse attention including global tokens (O(1) per sequence) is a universal approximator of sequence-to-sequence functions and, like full attention, Turing complete.
  • They also showed limits: some tasks (such as finding the farthest vector) need about L layers with sparse attention, against one with full attention.
  • Sparse is not free in every case.

Cost. Each query attends to a constant number of keys, so time and memory are O(L), with dense blocks keeping GPUs efficient.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Random graphs with few links per node have paths of length…
  2. 2. BigBird proved sparse attention with global tokens is…
  3. 3. Some tasks need, with sparse attention,…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

How many layers does information need?

History.

  • M. Zaheer, G. Guruganesh, A. Dubey, J. Ainslie, C. Alberti, S. Ontañón, P. Pham, A. Ravula, Q. Wang, L. Yang and A. Ahmed, “Big Bird: Transformers for longer sequences” (NeurIPS 2020).
  • D. Watts and S. Strogatz described small-world networks (Nature, 1998).

Exercise 2.

  • Graphs: BigBird’s attention graph (edge j → i when i attends to j) for 256, 1024 and 4096 tokens, with window ±3, 3 random keys per query and 2 global tokens.
  • Measurement: the exact number of attention layers information needs to travel between tokens, by breadth-first search from 32 sources.
tokens window: mean / max hops + 3 random + 2 global BigBird
256 29.5 / 85 3.0 / 5 2.0 / 2 2.0 / 2
1024 116.1 / 329 3.7 / 6 2.0 / 2 2.0 / 2
4096 447.8 / 1334 4.5 / 6 2.0 / 2 2.0 / 2
  • A window alone needs depth proportional to length: 1334 layers to connect the most distant tokens at 4096, far more than any model has.
  • Three random keys per token make paths roughly logarithmic. The mean grows by only about 0.75 hops each time the length quadruples, the small-world effect.
  • Global tokens cap every path at 2 hops. Paths are about information routes only: a 2-hop route through one global token must squeeze all of the sequence through it, which is why BigBird also keeps windows and random links.
🐍 Exercise 2 (research): how many layers does information need?
Build BigBird-style attention graphs and measure exact path lengths with breadth-first search.

BigBird in AI, robotics and aerospace

  • Genomics and biology: long-sequence attention reads DNA and protein contexts.
  • Long telemetry and logs: sparse attention covers hours of data at linear cost; choose random and global components so information can mix within the model’s depth.
  • Design check: compute path lengths of a sparse pattern to see whether its depth suffices.

References

  1. M. Zaheer et al. (2020). “Big Bird: Transformers for longer sequences.” Proc. NeurIPS.
  2. D. J. Watts, S. H. Strogatz (1998). “Collective dynamics of ‘small-world’ networks.” Nature 393.