Global Tokens › Global Token Count
Language AI HandbookAll chapters Global Tokens › Global Token CountOne section · Sections in this chapter6 / 15 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
How many global tokens do you need? This depends on the task and sequence length. Too few global tokens create an information bottleneck. Too many defeat the purpose of sparse attention by reintroducing quadratic interactions.
The right way to think about this trade-off is in terms of information-theoretic capacity. A single global token with embedding dimension has at most real-valued numbers to represent the global context of a sequence that may contain thousands of tokens. For a simple classification task where the label depends on one or two facts from the document, a single global token may be sufficient: it just needs to encode those facts and suppress everything else. For a complex task like multi-hop question answering, where the answer requires combining three or four facts distributed across the document, a single global token becomes a bottleneck. Each fact competes for the limited representational capacity, and some may be lost.
The operational rule of thumb is to start with one global token and add more only when task-specific evaluation metrics show that performance has plateaued. A useful diagnostic is to inspect the attention patterns of the global token after training: if it shows very diffuse, nearly uniform attention over the entire sequence, it is probably overloaded and struggling to concentrate on the most important information. If it shows sharply peaked attention at a few positions, it may have sufficient capacity and adding more tokens may not help much.
For classification tasks with a single CLS token, one global token often suffices. The CLS token aggregates a summary representation, and the classification head only needs this single vector.
For tasks requiring fine-grained outputs, such as question answering, named entity recognition, or span extraction, more global tokens help. Making all question tokens global in QA provides richer context for every answer span candidate. Each question token carries part of the question's semantics, so different context tokens can attend to whichever question token is most relevant to their local content.
def compute_attention_complexity(seq_len, window_size, num_global):
"""
Compute number of attention connections for different configurations.
"""
# Full attention: n^2 connections
full = seq_len * seq_len
# Sliding window: approximately n * window_size
local = seq_len * window_size
# Global token connections: each global attends to all (n)
# and is attended by all (n), minus overlap
# Approximately: 2 * num_global * seq_len
global_connections = 2 * num_global * seq_len - num_global * num_global
# Total sparse: local + global (with some overlap correction)
sparse = local + global_connections
return {
"full_attention": full,
"local_only": local,
"local_plus_global": sparse,
"savings_percent": 100 * (1 - sparse / full),
}
# Test with different global token counts
seq_len = 4096
window_size = 512
results = []
for num_global in [1, 4, 16, 64]:
complexity = compute_attention_complexity(seq_len, window_size, num_global)
results.append(
{
"num_global": num_global,
"connections": complexity["local_plus_global"],
"savings": complexity["savings_percent"],
}
)

Even with 64 global tokens, we maintain over 84% savings compared to full attention. The marginal cost of additional global tokens is linear in sequence length, not quadratic. This means you can afford to be generous with global tokens for complex tasks without sacrificing efficiency.
To understand why this holds, recall that the total number of connections in global-local attention is approximately:
where:
- : sequence length
- : window size
- : number of global tokens
The first term, , comes from the sliding window: each of the positions attends to neighbors. The second term, , comes from global tokens: each global token attends to all positions (adding connections) and each of the positions attends to all global tokens (adding another connections). Both terms are linear in , while full attention costs . So the savings relative to full attention are:
For , , and : savings . As grows, the savings percentage approaches 100% for any fixed and .