Language models, retrieval, prompting, and language adaptation · Long-context and retrieval-augmented language · LNG047 · Architecture
BigBird
Uses a combination of local, global, and random attention connections to process long sequences efficiently. Random links supplement structured neighborhoods so information can propagate across distant portions of a…
In CodeSplash
Documented in the Academy only. There's no Set up button.
- Availability
- Explained here
- Code example
- Component demo, not a trained model
- Who ran it
- CodeSplash's own run
- CodeSplash's run
- The reference's example ran in Python and R here, and they agree.
- The reference's record
- Python: The chapter's authors report running it; there is no record for this entry alone. R: Reviewed but not run: R wasn't available to the reference's authors.
Purpose
Uses a combination of local, global, and random attention connections to process long sequences efficiently. Random links supplement structured neighborhoods so information can propagate across distant portions of a document.
Question / objective
Can random links complement local/global attention for efficient long-sequence modeling?
Architecture / computational structure
A sparse attention graph combines local, global, and random block connections. Learned network projections are parameters; connectivity counts, block sizes, and random seeds are architecture/hyperparameter settings.
Assumptions
Attention-pattern randomness can affect reproducibility, and block constraints can produce dense fallback behavior for short inputs.
Formula / computational definition
Construct a sparse attention graph as the union of window edges, global-token edges, and sampled random edges. Under the paper's assumptions, this connectivity supports theoretical expressiveness results; those results are not empirical accuracy guarantees.
Parameters and notation
Learned parameters: identified in the architecture subsection. Hyperparameters, design and inference choices: Block size, local window, number of random blocks, global blocks, random seed, input length, and sparse-kernel implementation.
Fitting, fine-tuning, and adaptation
Train or fine-tune the desired task head with exact attention masks and compatible sparse kernels. Use supported adapters only after checking module targets; revalidate across seeds and lengths. Tune on held-out long documents and assess whether adaptation harms short-document performance.
How to use and calibrate
Assess long-document tasks, edge-pattern ablations, multiple seeds, memory scaling, and actual sparse-versus-dense backend behavior. Use development data for settings and an independent test set for the final estimate. Report uncertainty across examples or seeds when the evaluation design supports it; model scores and self-assessments are not automatically calibrated probabilities of correctness.
Example application
Classify very long documents while comparing random-edge and global-only attention patterns.
Interpretation / pitfalls
Watch out
Long contexts may still contain distractors that degrade task performance. The code below isolates one stated component; successful execution does not validate model quality or reproduce the cited experiment.
Python and R code examples
Full implementation route: Use documented BigBird model and configuration support in Transformers; R bridges via reticulate. The native example constructs a deterministic toy sparse-connectivity mask and does not implement block-sparse attention kernels.
Example scope: BigBird-like local/global/random-edge union with fixed illustrative edges; not its block kernel.
Dependencies: Python 3 standard library; base R; shared setup above. No model downloads or external services.
Validation: Python component executed in the combined example script; R counterpart supplied but not runtime-tested here. All numbers are synthetic.
Python and R
The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.
Component demo, not a trained model — BigBird-like local/global/random-edge union with fixed illustrative edges; not its block kernel.
Shared setup for this chapter
import math
def softmax(xs):
m = max(xs)
es = [math.exp(x-m) for x in xs]
return [e/sum(es) for e in es]
def dot(a, b):
return sum(x*y for x, y in zip(a, b))
def matvec(matrix, vector):
return [dot(row, vector) for row in matrix]
def meanvec(rows):
return [sum(row[j] for row in rows)/len(rows) for j in range(len(rows[0]))]
def sigmoid(x):
return 1/(1+math.exp(-x))
def nll(probabilities):
return -sum(math.log(p) for p in probabilities)
n, random_edges = 6, {(1,4),(2,5),(3,1),(4,2)}
mask = [[int(abs(i-j)<=1 or i==0 or j==0 or (i,j) in random_edges) for j in range(n)] for i in range(n)]
print(mask)
Component demo, not a trained model — BigBird-like local/global/random-edge union with fixed illustrative edges; not its block kernel.
Shared setup for this chapter
softmax <- function(x) {
shifted <- exp(x-max(x))
shifted/sum(shifted)
}
n <- 6L
mask <- outer(0:(n-1),0:(n-1),function(i,j) as.integer(abs(i-j)<=1 | i==0 | j==0))
mask[rbind(c(2,5),c(3,6),c(4,2),c(5,3))] <- 1L
print(mask)
Sources
- Source 1arxiv.org
From the CodeSplash reference, entry LNG047.