Deduplication, memorization and contamination
Explain why duplicated text gets memorized verbatim and wastes compute. Explain how the questions of benchmarks (standard test sets used to score models) leaking into the training data inflate evaluation scores.
Builds on: Building a pretraining corpus
What the animation says
Many continuations, or one
Training rewards one thing: predicting the token that actually came next. After 'the cat sat on the', the web offers mat, sofa, floor, roof, and many more. So the best guess is a spread over words, and spreads force the model to learn general patterns. Now take a license blurb that appears ten thousand times across the crawl. After 'free of', what will the model predict?
Copies multiply weight
Charge, at about ninety-nine percent. Every copy shows the same next word, so the model memorizes it verbatim. Here is the loss. Add up over distinct sequences, weight each by its number of copies, and divide by the total training tokens. So ten thousand copies pull ten thousand times as hard as one unique text. But once the blurb is memorized, the surprisal of each token is nearly zero. So, after memorization, which adds more to the loss: one more blurb copy, or one fresh fifty-token document?
Compute spent, nothing learned
The fresh document, by far. Here are the numbers. A memorized blurb token has probability point nine nine. Its surprisal is about one hundredth of a nat. Fifty tokens times that: half a nat for the whole copy. A fresh document, at about three nats per token, gives one hundred fifty nats. Yet both cost the same compute. Ten thousand copies are half a million tokens, mostly teaching nothing. Deduplication spends that compute on new text instead.
A leaked benchmark
Repetition has a second cost: test questions inside the training data. A benchmark has a thousand questions. The model's real skill gets sixty percent of them right. But two hundred questions, with their answers, were posted online and crawled. The model recalls those two hundred perfectly. So what score does it report?
Catching leaks by shared spans
Sixty-eight percent: eight points of recall, not skill. To catch leaks, compare long runs of words. This function collects every run of eight words in a row. Two texts are flagged if they share any run. The same check also finds duplicates in the corpus. Here is a crawled quiz page, and two versions of a test question. Tap the version this check would miss.
Trust clean items
Exact span matching catches copies, not rewordings. So add one more check. Split the benchmark into flagged items and clean items, and compare accuracy. If all two hundred leaks were flagged, that is one hundred percent against sixty. The gap is recall. So: copies add weight, repeated text gets memorized, and later copies burn compute. And trust a score only on clean, unseen items.
One continuation, repeated, means recall
Copies multiply a sequence's weight
Wasted tokens and an inflated score
Catching leaks by shared long spans
def spans(text, n=8):
w = text.lower().split()
return {tuple(w[i:i+n]) for i in range(len(w) - n + 1)}
train_doc = "quiz: if a train leaves at 3 pm going 60 mph how far by 5 pm? answer 120 miles"
test_q = "if a train leaves at 3 pm going 60 mph how far by 5 pm?"
reworded = "a train departs 3 pm at 60 mph; distance by 5 pm?"
print(len(spans(train_doc) & spans(test_q)) > 0) # True: leak found
print(len(spans(train_doc) & spans(reworded)) > 0) # False: leak missed
Remember this
On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.
Bytewise
All courses