Span Corruption › Span Selection Strategies
Language AI HandbookAll chapters Span Corruption › Span Selection StrategiesOne section · Sections in this chapter3 / 14 ↓
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
Now that we understand what span corruption does conceptually, we need to answer a practical question: how do we decide which parts of a sequence to corrupt? This leads us to two interconnected design choices that significantly affect what the model learns.
Think of span corruption as a controlled demolition. We want to remove enough of the building (the text) to create a meaningful reconstruction challenge, but not so much that the remaining structure provides no clues about what was removed. This balance requires careful decisions about two quantities: how much total material to remove (the corruption rate) and how to divide that material into chunks (the span length distribution).
The two parameters interact. If we fix the corruption rate at 15% and increase the average span length, we need fewer, longer spans. The model encounters fewer reconstruction tasks per sequence but each one is harder. If we reduce the mean span length, we get more, shorter spans. The model encounters more reconstruction tasks but each one is easier and more local. The right balance depends on what downstream capabilities matter most.
Corruption Rate: How Much to Remove
The corruption rate specifies what fraction of the original tokens should end up inside corrupted spans. T5 adopts , matching BERT's masking rate, but the mechanics differ substantially from token-level masking.
In standard MLM, a 15% corruption rate means we independently flip a coin for each token, with 15% probability of masking. The result: exactly 15% of tokens become [MASK], scattered throughout the sequence. With span corruption, we instead select contiguous regions totaling approximately 15% of the sequence. The key difference is that these tokens are grouped, not isolated.
This grouping creates an interesting constraint. If we want to corrupt a fixed fraction of tokens, the number of spans we create depends on how long each span is. Suppose we have a sequence of tokens and want to corrupt fraction of them. If each span contains an average of tokens, simple arithmetic tells us how many spans we need:
where:
- : the total number of tokens in the input sequence
- : the corruption rate (fraction of tokens to corrupt, e.g., 0.15 for 15%)
- : the average span length (e.g., 3 tokens per span)
The reasoning is direct: we need to "cover" tokens with our spans. If each span covers tokens on average, we need spans to achieve the target coverage.
Let's make this concrete. For a 512-token sequence with and :
- Tokens to corrupt: tokens
- Spans needed: spans
- Input length after corruption: Each span gets replaced by one sentinel token, so the corrupted input contains tokens
This calculation reveals an important property: span corruption naturally compresses the input sequence. We remove 77 tokens but add only 26 sentinels, achieving a net reduction of 51 tokens (about 10% shorter). This compression has computational benefits we'll explore later.
The T5 paper explored corruption rates between 10% and 50%. The team found that performance changed little in the 10%-25% range, with 15% consistently performing well across tasks. Rates above 30% begin to remove too much context, making reconstruction harder but also noisier as a training signal. Very high rates (40%-50%) can hurt downstream performance because the model spends most of pretraining on a task so hard that it cannot receive a clear learning signal from the context.
Span Length Distribution: The Shape of Uncertainty
The corruption rate tells us how much to remove; the span length distribution tells us how to partition that removal into individual spans. This choice significantly affects what patterns the model learns.
Consider the extremes. If all spans had length 1, span corruption would collapse to token-level masking: we'd have 77 isolated masks, each predicting a single token independently. If all spans had length 77, we'd have one massive gap containing over half the sequence. This provides almost no useful training signal.
The sweet spot lies somewhere between. We want a mix of span lengths that exposes the model to diverse reconstruction challenges: some single-token predictions (maintaining fine-grained language modeling ability), some short phrases (learning local coherence), and occasional longer spans (forcing the model to reason about larger structures).
T5 uses a geometric distribution to achieve this mix. The geometric distribution is the discrete analog of the exponential distribution, modeling a natural process: imagine flipping a biased coin at each position within a span, continuing until we get "heads" (stop) instead of "tails" (continue). The span length equals how many positions we visited before stopping.
Mathematically, if the probability of stopping at each step is , the probability of a span having exactly tokens is:
where:
- : the probability of sampling a span of exactly tokens
- : the span length (a positive integer: 1, 2, 3, ...)
- : the stopping probability at each step, controlling the distribution's shape
- : the probability of "continuing" for steps before finally "stopping"
This formula captures a simple generative process: to get a span of length , we need consecutive "continue" decisions (each with probability ) followed by one "stop" decision (with probability ).
The geometric distribution has a convenient property: its mean equals . This gives us a direct way to control the average span length. If we want spans to average tokens, we simply set:
For T5's choice of , this gives . At each step within a span, there's a 1-in-3 chance of stopping. The resulting distribution strongly favors shorter spans while maintaining a "heavy tail" of longer ones:
- (one-third of spans are single tokens)
- (about one-fifth are two tokens)
- (around one-sixth are three tokens)
- (one-tenth are four tokens)
- (about one-fifth contain five or more tokens)
This distribution creates a varied training curriculum. The model frequently encounters single-token predictions, maintaining its vocabulary knowledge. It regularly sees two and three-token spans, learning common phrases and local syntax. And it occasionally faces longer spans requiring compositional reasoning.
Why is the geometric distribution a natural choice here, rather than some other distribution with a similar mean? The geometric distribution has the "memoryless" property: the probability of stopping at the next step does not depend on how far we have already traveled within a span. This means there is no "target length" that spans tend toward. Each step within a span is a fresh, independent decision, which mirrors the structure of natural language to some extent: clauses do not have a predetermined length, and there is no linguistic pressure to end a phrase at exactly step three versus step four. The memoryless property keeps the sampling process simple and avoids introducing artificial length preferences.
Let's visualize this distribution by sampling 10,000 span lengths and plotting the empirical frequencies. This will confirm our theoretical calculations and reveal the characteristic exponential decay.
import matplotlib.pyplot as plt # noqa: F401
import numpy as np
# Geometric distribution parameters
mean_span_length = 3
p = 1 / mean_span_length
# Sample 10000 span lengths
span_lengths = np.random.geometric(p, size=10000)
# Calculate distribution statistics
unique, counts = np.unique(span_lengths, return_counts=True)
probabilities = counts / len(span_lengths)
The empirical distribution matches our theoretical expectations. Notice the characteristic exponential decay: each bar is roughly two-thirds the height of the previous one (since ). The red dashed line marks the mean at 3, which falls slightly to the right of the mode (1). This reflects the distribution's right skew.
Why does this shape work well for pretraining? The geometric distribution provides a natural curriculum:
- High-frequency short spans maintain the model's ability to predict individual tokens accurately, preserving fine-grained vocabulary knowledge
- Medium-length spans teach local coherence and common phrases, the bread-and-butter of fluent text generation
- The heavy tail occasionally challenges the model with longer reconstructions, forcing it to reason about how syntax and entities contribute to discourse structure
This is more effective than a uniform distribution, which would waste equal capacity on trivially short spans and overwhelmingly long ones. The geometric decay concentrates learning where it's most useful while still providing exposure to diverse span lengths.
Another way to understand the distribution is through the cumulative perspective: what fraction of spans have length at most ? This cumulative distribution function (CDF) answers practical questions like "what percentage of spans are single tokens?" or "how often do we see spans longer than 5 tokens?"

The CDF reveals that roughly half of all spans have length 2 or less, and about 80% have length 4 or less. Only the remaining 20% challenge the model with longer reconstructions. This steep rise followed by a gradual tail perfectly balances frequent short-span practice with occasional longer challenges.