BART Pre-training › Document Rotation
Language AI HandbookAll chapters 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 , we uniformly sample a position and rotate:
where:
- : the rotated (corrupted) document
- : the original document with tokens
- : the randomly chosen rotation point (sampled uniformly from 1 to )
- : tokens from position to the end become the new beginning
- : tokens before position 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 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.
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, tokensrandom.seed(123)
original = "The quick brown fox jumps over the lazy dog".split()
corrupted, _ = document_rotation(original)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.