BART Pre-training › Document Rotation

Michael BrenndoerferOctober 19, 20253 min read
Language AI HandbookAll chapters
Part 25 of 67Encoder-Decoder Models
Chapter 181BART Pre-training › Document Rotation
Reading section 7 of 16 · Document Rotation · 3 minSection 7 of 16 · 3 min

Book contents

Section 7 of 16 · 3 min read

BART Pre-training › Document RotationOne section · Sections in this chapter7 / 16 ↓
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

Document rotation is the most aggressive structural corruption in BART's repertoire. A random token is selected as the new starting point, and the document is rotated so that it begins with that token. Unlike sentence permutation, which at least preserves sentence boundaries, document rotation can split sentences arbitrarily, placing sentence fragments at the beginning or end.

How It Works

Given a document with tokens [x1,x2,…,xn][x_1, x_2, \ldots, x_n], we uniformly sample a position k∈{1,…,n}k \in \{1, \ldots, n\} and rotate:

x~=[xk,xk+1,…,xn,x1,x2,…,xk−1]\tilde{x} = [x_k, x_{k+1}, \ldots, x_n, x_1, x_2, \ldots, x_{k-1}]

where:

  • x~\tilde{x}: the rotated (corrupted) document
  • x1,x2,…,xnx_1, x_2, \ldots, x_n: the original document with nn tokens
  • kk: the randomly chosen rotation point (sampled uniformly from 1 to nn)
  • [xk,…,xn][x_k, \ldots, x_n]: tokens from position kk to the end become the new beginning
  • [x1,…,xk−1][x_1, \ldots, x_{k-1}]: tokens before position kk are moved to the end

Think of the document as arranged in a circle. We pick a random position and "cut" the circle there, then lay it out linearly starting from that cut point. All tokens remain in their relative order, but the absolute positions shift. The original beginning might now appear in the middle or at the end.

For example, "The quick brown fox jumps" with k=3k=3 becomes "brown fox jumps The quick." The fragment "brown fox jumps" appears first, followed by "The quick".a clear violation of sentence structure that signals something is wrong.

What the Model Learns

Document rotation teaches the model to identify document boundaries, specifically where a coherent document begins. This seems like a narrow skill, but it has practical uses:

  • Document structure recognition: Real documents have clear beginnings (titles, topic sentences) and endings (conclusions, sign-offs). The model learns to recognize these structural markers (capitalized first words, sentence-initial positions, opening phrases like "In this paper" or "The purpose of") that distinguish true document starts from arbitrary mid-document positions.

  • Global coherence: Unlike sentence permutation, which preserves some local structure, rotation can place mid-sentence fragments at document boundaries. The model must recognize incomplete thoughts, such as a sentence missing its subject or a phrase without context, as evidence of artificial boundaries.

In practice, document rotation was the least effective corruption scheme when used alone. The task is difficult (many rotation points produce plausible-looking starts, especially in long documents where sentence-initial positions are common), and the learning signal is limited to identifying a single boundary per document. The model receives one bit of useful information per training example: where the true start is.

In[16]:
Code
def document_rotation(tokens: List[str]) -> Tuple[List[str], List[str]]:
    """Apply document rotation corruption.

    Returns:
        Tuple of (corrupted_tokens, original_tokens)
    """
    if len(tokens) <= 1:
        return tokens, tokens

    # Sample rotation point uniformly
    k = random.randint(1, len(tokens) - 1)

    # Rotate: move tokens before k to the end
    corrupted = tokens[k:] + tokens[:k]

    return corrupted, tokens
In[17]:
Code
random.seed(123)

original = "The quick brown fox jumps over the lazy dog".split()
corrupted, _ = document_rotation(original)
Out[18]:
Console
Original:  The quick brown fox jumps over the lazy dog
Corrupted: quick brown fox jumps over the lazy dog The
Rotation point: position 1 ('quick')

The rotated sequence maintains word order within the two fragments but loses the natural starting point. The decoder must identify "The" as the true document beginning.