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.
★☆☆☆☆ 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. BigBird's three kinds of attention:
2. Random links make paths between tokens…
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. Keys per query for w = 3, r = 3, g = 2:
2. Window-only diameter for L = 4096, w = 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.
Build a BigBird mask with window, random and global attention and count block-sparse pairs.
📝 Quick check (Level 2)
0/3 answered
1. BigBird's block size:
2. Blocks matter because…
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. Random graphs with few links per node have paths of length…
2. BigBird proved sparse attention with global tokens is…
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
M. Zaheer et al. (2020). “Big Bird: Transformers for longer sequences.” Proc. NeurIPS.
D. J. Watts, S. H. Strogatz (1998). “Collective dynamics of ‘small-world’ networks.” Nature 393.
Three random keys per token cut mean paths at 4096 tokens from 448 hops to 4.5.
Practice
Show:
Level 0
Problem 1Level 0
Keys per query for w = 3, r = 3, g = 2?
12.
Problem 2Level 0
Maximum hops between tokens when a global token exists?
2.
Problem 3Level 0
Year BigBird appeared at NeurIPS?
2020.
Level 1
Problem 4Level 1
Block-sparse pairs for L = 4096, b = 64, 8 blocks per query block?
2097152.
Problem 5Level 1
Window-only diameter for L = 4096, w = 3?
1365.
Problem 6Level 1
Small-world estimate ln L / ln k for L = 4096, k = 4?
6.
Problem 7Level 1
Share of full attention computed by 512 keys per query at L = 4096?
0.125.
Level 2
Problem 8Level 2
Mean hops with a window only at L = 4096 in exercise 2?
447.8.
Problem 9Level 2
Mean hops with window + 3 random keys at L = 4096?
4.49.
Problem 10Level 2
Mean hops with window + 3 random keys at L = 256?
2.98.
Problem 11Level 2
Max hops observed with a window only at L = 4096?
1334.
Problem 12Level 2
Window-only diameter for L = 10, w = 3?
⌈9/3⌉ = 3.
Problem 13Level 2
Mean hops with a window only at L = 1024?
116.1.
Level 3
Problem 14Level 3
Show that a window of ±w needs ⌈(L − 1)/w⌉ layers to connect the ends.
Each layer lets information move at most w positions, since attention only reaches within the window. Moving from position 0 to L − 1 needs a total displacement of L − 1, hence at least ⌈(L − 1)/w⌉ layers, and moving w each layer achieves it. ∎
Problem 15Level 3
Explain why a few random links shorten paths so much.
Each random link jumps to an arbitrary position. From any token, the set reachable in h hops grows roughly by a factor of the number of links per hop, k^h, so covering L tokens takes about log_k L hops. The window keeps local structure, and the random links supply long-range shortcuts, as in small-world networks. ∎
Problem 16Level 3
Compare BigBird with Longformer.
Both use windows and global tokens at linear cost. BigBird adds random keys, which shorten paths between non-global tokens (logarithmic rather than through a single global bottleneck) and underpin its universality proof. It computes in dense blocks for efficiency. Longformer uses dilation in higher layers and custom banded kernels instead. ∎
Problem 17Level 3
Advise on a sparse attention pattern for 50,000-step telemetry with a 12-layer model.
A window alone would need thousands of layers to connect distant steps. Add random or strided keys so paths are logarithmic, well within 12 layers, plus a few global summary tokens. Compute path lengths for the chosen pattern as in exercise 2, and validate on tasks needing long-range dependencies. ∎
Level 4
Problem 18Level 4
Mean hops with window + 3 random keys at L = 1024?
3.68.
Problem 19Level 4
Mean hops with a window only at L = 256?
29.5.
Problem 20Level 4
How many times longer than BERT’s 512 tokens is BigBird’s 4096?
8.
Coding practice
🐍 Code 1 (Level 0): block pairs
L·b·(window + random + global blocks).
🐍 Code 2 (Level 0): window diameter
⌈(L − 1)/w⌉.
🐍 Code 3 (Level 1): small-world estimate
ln L / ln k.
🐍 Code 4 (Level 0): sparse share
Keys per query over L.
🐍 Code 5 (Level 0): keys per query
Window, random and global.
Topic test
A timed test drawn at random from this topic's question bank. Each attempt gets new questions. For a longer test across the whole chapter, see the chapter test, or mix topics in the question bag.
BigBird: topic test
10 questions, drawn at random from a bank of 21. Every attempt is different.
⏱ Time limit: 15 minutes. The test submits itself when time runs out.
Levels covered: 0, 1, 2, 3, 4. No hints or solutions until you submit.