BART Pre-training › Sentence Permutation
Language AI HandbookAll chapters BART Pre-training › Sentence PermutationOne section · Sections in this chapter6 / 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
Moving from token-level to structural corruption, sentence permutation shuffles the order of sentences within a document. This tests the model's understanding of discourse coherence and document structure.aspects of language that token-level corruptions cannot address. Well-written documents have logical flow: ideas build on each other, references point backward to established concepts, and conclusions follow from premises. Sentence permutation disrupts this flow and asks the model to restore it.
How It Works
The document is first segmented into sentences (typically using punctuation heuristics or a sentence tokenizer, as covered in Part I). These sentences are then randomly permuted:
where:
- : the corrupted document with reordered sentences
- : the original document as a sequence of sentences
- : a random permutation function that reorders the sentences
The shuffle operation creates a random permutation of the sentences, selecting uniformly from all possible orderings. For a three-sentence document, there are possible orderings, and each has equal probability of being selected. For example, a three-sentence document might be reordered from to , placing what was the middle sentence first and the original first sentence last.
What the Model Learns
Sentence permutation teaches document-level coherence in several ways:
-
Discourse relations: How does one sentence logically follow another? Causal relationships ("Because X, therefore Y"), temporal sequences ("First X, then Y"), and elaboration patterns ("X. More specifically, Y") all provide cues for ordering. The model must recognize these implicit connections even when discourse markers are absent.
-
Referential coherence: Pronouns and definite references ("the man," "this idea") typically follow their antecedents. Permuted text disrupts these chains.a sentence might use "he" before the person has been introduced, or mention "this approach" before the approach has been described. The model learns to recognize and restore proper reference chains.
-
Topic flow: Well-organized text develops ideas progressively. Opening sentences introduce topics; middle sentences elaborate; closing sentences conclude or transition. The model learns to recognize these structural roles and restore this flow.
However, sentence permutation alone proved less effective than token-level corruption in BART's experiments. The learning signal is sparse (each training example provides only a few reordering decisions), and many permutations might be equally valid for loosely connected sentences. A document with three independent observations could be reasonably ordered in any sequence. This provides ambiguous signal to the model.
import re
def sentence_permutation(
text: str, sentence_end_pattern: str = r"(?<=[.!?])\s+"
) -> Tuple[str, str]:
"""Apply sentence permutation corruption.
Returns:
Tuple of (corrupted_text, original_text)
"""
# Split into sentences
sentences = re.split(sentence_end_pattern, text.strip())
sentences = [s.strip() for s in sentences if s.strip()]
# Shuffle sentences
shuffled = sentences.copy()
random.shuffle(shuffled)
corrupted = " ".join(shuffled)
return corrupted, textrandom.seed(42)
document = """Natural language processing has advanced rapidly.
Transformers revolutionized the field in 2017.
Today, large language models can perform diverse tasks."""
corrupted, original = sentence_permutation(document)Original: Natural language processing has advanced rapidly. Transformers revolutionized the field in 2017. Today, large language models can perform diverse tasks. Corrupted (permuted): Transformers revolutionized the field in 2017. Natural language processing has advanced rapidly. Today, large language models can perform diverse tasks.
The permuted version reads awkwardly.the chronological and logical flow is disrupted. The decoder must restore proper ordering based on discourse cues.