TL;DR
Lee and colleagues found that large public text datasets used to train language models contain many repeated passages, some of them almost word for word. They built two tools to remove the repetition: one deletes long substrings that appear more than once, the other deletes whole documents that are near-copies of another. Models trained on the cleaned data repeated their training text about ten times less often, and they did not get worse on perplexity.
Builds on: Language Model, Suffix Array, MinHash, Edit Distance, Jaccard Index · Leads to: Overfitting (the memorization problem the paper measures)
Why it mattered
The paper measures how much duplicated text sits inside the corpora that large models are trained on. It gives concrete numbers for four datasets: C4, RealNews, LM1B and Wiki-40B. It also shows that the cleaning steps already applied to these datasets missed the kind of duplication that web text actually has. C4 removed paragraphs that collided under a hash, and RealNews removed documents whose first 100 characters collided, but neither caught near-copies that differ in a name or a date. The authors released their code, so the tools can be run on other corpora.
The history behind it is short. Earlier work had shown that large models can reproduce parts of their training data, and that some widely used datasets contain many exact duplicate documents. What was missing was a method that worked on the whole corpus and found near-copies, not only exact ones. This paper supplied one, and it measured the effects on trained models rather than only on dataset statistics.
The problem
A language model learns from a large collection of documents, called a corpus or dataset. Such corpora are too big for people to read, so their quality is hard to control. Two problems follow from duplicates.
Problem 1: the model memorizes. If one passage appears thousands of times in the training data, the model learns it as a fixed sequence and can later reproduce it when asked to generate text. Reproducing a phone number or a username is a privacy problem, and reproducing an advertisement is a quality problem.
Problem 2: the test set leaks into training. A model is judged on a validation set, a held-out collection of text it never trained on. If the same text appears in both the training set and the validation set, the score is inflated. The model looks better at predicting that text because it has seen it. Selecting models by that score then rewards models that memorize, not models that generalize (see Overfitting).
Exact string matching, comparing every document with every other one character by character, would find many of these cases. It is too slow for a corpus of hundreds of millions of documents, and it misses documents that differ in only a few words, such as a template with a different city name in it. The paper needs a method that is fast and that tolerates small differences.
How it works
The method has two parts, and each runs on the whole corpus. Here is the pipeline in order:
flowchart LR A["Raw corpus"] --> B["ExactSubstr: find repeated 50-token substrings with a suffix array"] B --> C["Remove those substrings from the documents"] A --> D["NearDup: MinHash signatures of 5-grams"] D --> E["Candidate pairs that collide in a bucket"] E --> F["Keep pairs with edit similarity above 0.8"] F --> G["Connected groups of near-duplicates; redundant examples are removed"] C --> H["Deduplicated corpus"] G --> H
Now trace one tiny instance through the exact-substring part, then through the near-duplicate part.
- Start with a small corpus. Suppose the whole corpus, with its documents joined into one sequence, is the letters "banana". The repeat we look for is "ana", which occurs twice, at positions 2 and 4. In the real method the unit is a BPE token and the threshold is 50 tokens. Here the unit is a letter and the threshold is 3, so the arithmetic fits on a page.
- Build the suffix array. A suffix is the text from some position to the end. List all suffixes of "banana" and sort them alphabetically. The sorted list stores only the starting positions. The result is (6, 4, 2, 1, 5, 3). Check: position 6 is the suffix "a", which sorts first.
- Look at neighbours in the sorted list. Two suffixes that share a long prefix sit next to each other. Positions 4 and 2 are "ana" and "anana"; they share the prefix "ana", which is 3 letters. Check: if the threshold were 4, this pair would not count.
- Mark the repeated substring and remove one copy. The shared text is removed from one of the places it occurs, so the other copy stays. The corpus is still usable, but the repeat is gone.
- Hash each document into a short signature. For near-duplicates, each document is turned into a set of 5-grams, which are runs of five consecutive words. MinHash keeps the smallest hash values of that set, so two documents with similar sets keep many of the same numbers. Check: two identical sets always produce identical signatures.
- Find candidate pairs. Signatures are split into bands. Documents whose signatures agree on at least one band become candidates. The chance of becoming a candidate rises steeply with the overlap between the two documents (see the plot below).
- Confirm with edit similarity. For each candidate pair, the method computes the edit similarity. Pairs above 0.8 are duplicates, and the duplicates form groups that are then cut down to one copy each.
- b = 20, r = 450
The math
The two tools rest on four formulas: the suffix array for exact repeats, the Jaccard index for set overlap, the candidate probability for banded MinHash, and the edit similarity used for the final decision.
Two documents and are near-duplicates when MinHash marks them as a candidate pair and their edit similarity is greater than . Each document is first treated as a sequence of tokens, , where is its length.
Step 1 in symbols: the suffix array
A suffix array of a sequence is the list of all starting positions of , sorted so that the suffixes they begin appear in alphabetical order. The paper concatenates every document into one long sequence before building it. If the same substring starts at positions and , then the two positions sit next to each other in , because their suffixes share a long prefix. A linear scan of that looks for adjacent entries with a common prefix of at least tokens therefore finds every repeated substring. The paper sets .
Step 2 in symbols: the Jaccard index
Represent each document by its set of 5-grams, and . Their overlap is
The numerator counts the 5-grams the two documents share, and the denominator counts all 5-grams that appear in either. The value lies between (no shared 5-grams) and (identical sets).
Step 3 in symbols: the candidate probability
MinHash does not compute the Jaccard index for every pair. It keeps a signature of minimum hash values per document, splits the signature into bands of values, and marks a pair as a candidate if any band matches. If the true Jaccard index is , the chance of at least one matching band is
Check the two ends. At , , so the chance is . At , , so the chance is .
Step 4 in symbols: edit similarity
For candidate pairs the method uses a stricter, slower check on the token sequences:
Here is the number of single-token insertions, deletions and substitutions that turn one sequence into the other, and is the length of . A pair is a duplicate when .
Worked examples
Take the string "banana" and build its suffix array.
- The suffixes starting at positions 1 to 6 are "banana", "anana", "nana", "ana", "na" and "a".
- Sort them alphabetically: "a" (position 6), "ana" (position 4), "anana" (position 2), "banana" (position 1), "na" (position 5), "nana" (position 3).
- Read off the positions in that order: the suffix array is (6, 4, 2, 1, 5, 3).
- Look at adjacent entries 4 and 2. Their suffixes "ana" and "anana" share the prefix "ana", which has length 3. If the threshold were 3, this would count as a repeated substring.
- Interpretation: the repeat is found by reading neighbours, not by comparing every pair of positions.
Two documents, each 6 tokens long, are compared. They differ in one token: document has "the" where document has "a".
- The edit distance is 1, because one substitution turns into .
- The longer document has length .
- Compute the edit similarity: .
- Compare with the threshold: , so the pair is a duplicate and one copy is removed.
- Now a pair of 5-token documents that also differ in one token: . This is not greater than , so the pair is kept. The threshold is strict.
- Interpretation: the rule removes documents that differ by a small share of their tokens, and keeps documents that differ by more.
The paper generated 100,000 unprompted sequences, each up to 512 tokens, from the 1.5-billion-parameter XL models trained on the original C4 and on the deduplicated C4. A token counts as memorized if it sits inside a 50-token run copied exactly from the training data. For the 2-epoch models, the table reports 1.571% for the original model, 0.264% for NearDup and 0.168% for ExactSubstr.
- Compare the original model with the ExactSubstr model: .
- Do the division: .
- Compare the original model with the NearDup model: .
- Interpretation: the ExactSubstr model emits memorized text about nine times less often, and the NearDup model about six times less often, on this measure. The 1-epoch numbers give the roughly tenfold figure: .
Try it: the 1-epoch ExactSubstr number is 0.138%. Divide the original 1-epoch figure of 1.926% by 0.138 to find the reduction factor. Answer: , so about 14 times less memorization for that model.
Results
Duplicates are common. Using NearDup, the paper finds near-duplicates in 3.04% of C4 training examples and 13.63% of RealNews training examples. For Wiki-40B the figure is 0.39%, which the authors credit to manual curation. For LM1B it is 4.86%. ExactSubstr removes 7.18% of C4 training tokens, and 19.4% of RealNews training tokens.
Train-test overlap is real. The paper finds that 4.60% of the C4 validation set has a near-duplicate in the C4 training set, and that 14.35% of the RealNews validation set does. These are the cases where the score is inflated.
Memorization drops about tenfold. On unprompted generation, over 1% of the tokens from the model trained on the original C4 are part of a memorized 50-token run. The deduplicated models drop to between 0.14% and 0.26%. The worked example in The math shows the arithmetic.
Perplexity does not get worse, and sometimes improves. For the base-size model, both deduplicated versions have higher Perplexity on validation examples with training duplicates. The authors read this as a sign that those models memorized those examples less. On the LM1B and Wiki-40B validation sets, the NearDup model had the lowest perplexity. ExactSubstr lowered the XL model's perplexity on Wiki-40B by almost 3 points.
Limits. The experiments use English datasets and models with 110 million and 1.5 billion parameters. The 50-token threshold was chosen by experiment, and the authors note that other thresholds could change the comparison between the two methods. The paper does not study the nature of the removed content, and it does not study the downside of deduplication for tasks that need memorized facts.
Common misreadings
It is tempting to think that deduplication removes only copies of the same document. In fact much of the near-duplicated text is computer-generated: pages that are identical except for a name, a date or a price. Exact matching misses those, which is why the paper adds NearDup alongside ExactSubstr.
It is tempting to think that deduplication hurts the model because it removes data. In the paper, perplexity on the original validation set and on the unique validation examples stayed similar, and on LM1B and Wiki-40B the NearDup model had the lowest perplexity. The one clear loss was on validation examples that had near-copies in training. That is the expected result: those examples were easy only because the model had memorized them.
It is tempting to think that deduplication removes all privacy risk. The authors say it does not. Some private data, such as passwords and medical records, should never be in training data, whether or not it is repeated. Deduplication also cannot tell harmful memorization from harmless memorization, and some tasks, such as closed-book question answering, need memorized facts.
When to use it: whenever the corpus is large, scraped from the web, and used for pre-training. When not to use it: when the task needs exact recall of a document, or when the duplicate text carries attribution that the model should keep. Alternatives include keeping exact-duplicate removal only (cheap, but it misses templated text), or filtering by quality rather than by repetition, a different problem that can be combined with this one.
Reading guide
The chain of ideas, in the order the paper builds it: a corpus has repeats; a suffix array finds exact repeats; MinHash and edit similarity find near-repeats; removing them lowers memorization without raising perplexity. Read next: Overfitting for why memorization inflates scores, and Perplexity for the measure the paper uses to judge models.
- Section 1, introduction. Read for the four advantages. Needs only the idea of a training corpus and a validation set.
- Section 2, related work. Skim. It needs Language Model and the idea of training data contamination.
- Section 3, datasets. Read for what C4, RealNews, LM1B and Wiki-40B are and how each was built. No new prerequisites.
- Section 4, methods. The core of the paper. It needs Suffix Array, MinHash, Jaccard Index and Edit Distance. Read Section 4.1 for ExactSubstr and Section 4.2 for NearDup.
- Section 5, results on duplicates. Read the tables. The idea of a fraction of examples is enough.
- Section 6, impact on trained models. This is where Perplexity and Overfitting matter. The models are Transformer decoders over Subword Tokenization tokens, and the generation experiment uses top-k sampling (sample from the 50 most likely next tokens).
- Section 7, discussion, and Section 8, conclusion. Read for the limits and the authors' recommendations.
- Appendices A and B. Implementation of the two methods. Appendix A needs the Hash Function idea. Appendix B explains how the suffix array is built in parallel; you can skip the merge details on a first reading.
- Appendix C and D. Training and energy numbers. These are context; the rest of the paper does not depend on them.
Check yourself
QuestionRecall: what does a suffix array store, and why does a repeated substring show up as two neighbouring entries?Show answer
It stores the starting positions of all suffixes of a sequence, sorted alphabetically by the suffix. Two positions where the same long substring starts have suffixes that share a long prefix, so when they are sorted they sit next to each other. A linear scan that looks at neighbours therefore finds every repeated substring.
QuestionComputation: two documents are each 10 tokens long and differ in 2 tokens. Are they duplicates under the paper's rule? Show the edit similarity.Show answer
The edit distance is 2, and the longer document has 10 tokens. The edit similarity is . The rule needs a value greater than , so the pair is not a duplicate and both documents are kept.
QuestionWhy: the paper chooses a band size b = 20 with r = 450 bands. What does raising b do to the candidate probability for a pair with a low Jaccard index, and why would the authors want that?Show answer
Raising makes smaller for every . Each band then matches less often for dissimilar pairs, so the probability of at least one matching band, , falls for low-overlap pairs. The authors want few false candidates, because each candidate costs an edit-similarity check, while the curve still catches pairs near the 0.8 threshold.
QuestionApplied: a team trains a model on a scraped web corpus and sees a very low validation score that is unusually high. What could explain it, and which step of this paper would address it?Show answer
A likely cause is train-test overlap: validation examples with near-copies in the training set are easy to predict, so the score is inflated. The paper's NearDup step finds those pairs, with the rule that the validation copy is kept and the training copy removed. Checking the validation set against the training set is the step that addresses it.