Span Corruption › Span Selection Strategies

Michael BrenndoerferUpdated July 11, 202510 min read
Language AI HandbookAll chapters
Part 22 of 67Pre-training Objectives
Chapter 158Span Corruption › Span Selection Strategies
Reading section 3 of 14 · Span Selection Strategies · 10 minSection 3 of 14 · 10 min

Book contents

Section 3 of 14 · 10 min read

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 rr specifies what fraction of the original tokens should end up inside corrupted spans. T5 adopts r=0.15r = 0.15, 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 nn tokens and want to corrupt fraction rr of them. If each span contains an average of μ\mu tokens, simple arithmetic tells us how many spans we need:

number of spans≈r⋅nμ\text{number of spans} \approx \frac{r \cdot n}{\mu}

where:

  • nn: the total number of tokens in the input sequence
  • rr: the corruption rate (fraction of tokens to corrupt, e.g., 0.15 for 15%)
  • μ\mu: the average span length (e.g., 3 tokens per span)

The reasoning is direct: we need to "cover" r⋅nr \cdot n tokens with our spans. If each span covers μ\mu tokens on average, we need (r⋅n)/μ(r \cdot n) / \mu spans to achieve the target coverage.

Let's make this concrete. For a 512-token sequence with r=0.15r = 0.15 and μ=3\mu = 3:

  1. Tokens to corrupt: 0.15×512≈770.15 \times 512 \approx 77 tokens
  2. Spans needed: 77/3≈2677 / 3 \approx 26 spans
  3. Input length after corruption: Each span gets replaced by one sentinel token, so the corrupted input contains 512−77+26=461512 - 77 + 26 = 461 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 pp, the probability of a span having exactly ℓ\ell tokens is:

P(ℓ)=(1−p)ℓ−1⋅pP(\ell) = (1 - p)^{\ell - 1} \cdot p

where:

  • P(ℓ)P(\ell): the probability of sampling a span of exactly ℓ\ell tokens
  • ℓ\ell: the span length (a positive integer: 1, 2, 3, ...)
  • pp: the stopping probability at each step, controlling the distribution's shape
  • (1−p)ℓ−1(1 - p)^{\ell - 1}: the probability of "continuing" for ℓ−1\ell - 1 steps before finally "stopping"

This formula captures a simple generative process: to get a span of length ℓ\ell, we need ℓ−1\ell - 1 consecutive "continue" decisions (each with probability 1−p1 - p) followed by one "stop" decision (with probability pp).

The geometric distribution has a convenient property: its mean equals 1/p1/p. This gives us a direct way to control the average span length. If we want spans to average μ\mu tokens, we simply set:

p=1μp = \frac{1}{\mu}

For T5's choice of μ=3\mu = 3, this gives p=1/3p = 1/3. 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:

  • P(ℓ=1)=0.33P(\ell = 1) = 0.33 (one-third of spans are single tokens)
  • P(ℓ=2)=0.22P(\ell = 2) = 0.22 (about one-fifth are two tokens)
  • P(ℓ=3)=0.15P(\ell = 3) = 0.15 (around one-sixth are three tokens)
  • P(ℓ=4)=0.10P(\ell = 4) = 0.10 (one-tenth are four tokens)
  • P(ℓ≥5)=0.20P(\ell \geq 5) = 0.20 (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.

In[3]:
Code
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)
Out[4]:
Visualization
Bar chart showing span length probabilities decreasing exponentially from length 1 to 15.
Span length distribution following a geometric distribution with mean 3. Shorter spans dominate, with about one-third being single tokens, but the exponential tail ensures the model regularly encounters multi-token reconstruction challenges. The mean (red dashed line) falls to the right of the mode. This reflects the distribution's right skew.

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 (1−p)=2/3(1-p) = 2/3). 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:

  1. High-frequency short spans maintain the model's ability to predict individual tokens accurately, preserving fine-grained vocabulary knowledge
  2. Medium-length spans teach local coherence and common phrases, the bread-and-butter of fluent text generation
  3. 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 ℓ\ell? 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?"

Out[5]:
Visualization
Step plot showing cumulative probability increasing from 0.33 at length 1 toward 1.0 at higher lengths.
Cumulative distribution of span lengths showing what fraction of spans fall at or below each length. With mean 3, about 55% of spans are length 1 or 2, while only 20% exceed length 4. This steep initial rise followed by a gradual tail means the model practices short reconstructions frequently while still encountering longer challenges.

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.