Unit 6 of 7 · about 4 hours · implement

Provenance, deduplication and contamination

Distinct files can contain the same document, and distinct documents can share an evaluation answer. Deduplication and contamination checks need traceable identities, not just a smaller output corpus.

You'll be able to

  • Implement stable raw document IDs and retain source, transformation versions and duplicate-cluster lineage.
  • Remove exact duplicates under a declared byte policy and implement a small shingle-based near-duplicate comparison.
  • Probe train/evaluation overlap, review false matches and report what the detector cannot establish.

Covers

Source and document identities, lineage and provenanceExact deduplication and near-duplicate strategyContamination probes and false-match review
1

Read

In this order, only the parts listed

0 of 2 done

  1. Exact deduplication, shingles and overlap probesModern LLM Notebook - tokenization and data experiments

    Sections 3.1 and 3.2 with Exact Dedup and MinHash approximate deduplication code; Section 3.3, Decontamination, with word_ngrams and max_overlap; Exercises, Exercise 2: Complete Jaccard similarity

    Use exact Jaccard as the small-corpus oracle. Treat the four-position MinHash as a noisy demonstration and the stated corpus-removal percentages as unverified examples, not expected results.

  2. Provenance and duplicate-cluster contractTokenizer and Corpus Pipeline - reduced foundation slice

    Core requirements: versioned schemas, source/document identities, exact/near dedup and contamination probes; Architecture constraints: raw source identity and separate versioned stages; Correctness requirements: cluster lineage; Failure-injection requirements: hash collision simulation and duplicate clusters spanning sources/splits

    Implement a tiny exact pipeline and all-pairs shingle comparison. Leave large-scale approximate search and distributed processing for later.

2

Focus on

  • Keep source ID, stable raw record ID, raw-byte hash, normalized-content hash and transform version separately. A normalization collision is not evidence that two raw records were identical.
  • Use the full digest and verify bytes within a candidate hash bucket. Choose a deterministic representative and retain every removed member's source and raw identity.
  • Define shingles, Jaccard threshold and empty-set behavior. Similarity is not transitive: connected-component clustering can join two endpoints below the pairwise threshold.
  • The notebook's contamination score is shared evaluation shingles divided by evaluation shingles, not Jaccard. Common boilerplate can trigger it, while paraphrases and non-Latin text can escape its ASCII-word regex.
Common mistakes · 3
  • Replacing a raw ID with a normalized-text hash. Different sources or byte spellings can collapse, and the audit loses their origins.
  • Hashing and splitting each record independently before handling duplicates. A duplicate cluster can span train and evaluation; fix group ownership or quarantine cross-split matches before packing.
  • Calling a no-hit report proof of no contamination. Exact and shingle probes miss transformed content, and short common matches need review.
3

Try it yourself

Closed-book, before checking anything

From a blank file, deduplicate a few documents by full SHA-256 plus byte equality, retaining cluster lineage. Compute exact word-shingle Jaccard for a copied, lightly edited and unrelated pair; plant a held-out passage in one training document and emit the matched spans and both record IDs for review.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Two records have the same NFC text but different raw bytes. Which identities should survive?Answer

    Both raw record IDs and raw hashes survive in lineage. They may share a normalized-content hash and cluster only if the declared dedup policy permits it.

  2. 2.Shingle sets have three members each and share two. What is their Jaccard score?Answer

    . The denominator is the union, not the size of the smaller set.

  3. 3.A four-word evaluation phrase appears in a long training article. Why can containment be 1 while Jaccard is small?Answer

    Every evaluation shingle is present, so the containment denominator is fully covered. Jaccard also counts the many unrelated training shingles in its union.

  4. 4.A-B and B-C exceed the near-duplicate threshold. Must A-C exceed it?Answer

    No. Threshold similarity is not transitive. A connected-component policy can group A and C anyway, so document that choice and review its removals.

You're done when

Your small pipeline retains all removed-record lineage, detects a planted overlap and survives a simulated hash collision, with reviewed false matches and explicit limits on any no-hit claim.

Only when you can do this without notes.

Leads to

Notes

Resources · 2 for this unit, 5 more in the section
  • Modern LLM Notebook - tokenization and data experimentsWalking Labs · support

    Run English notebooks 01-tokenizer-basics and 02-bpe-tokenizer. Use only the quality, deduplication and mixture examples from 15-data-engineering. Change the corpus and tie cases, then verify every quantitative claim independently.

  • Tokenizer and Corpus Pipeline - reduced foundation sliceRoadmap-Final · support

    Use the byte, identity, split, deduplication, contamination, packing, manifest and restart correctness requirements. Keep the corpus small and stop before distributed processing or internet-scale filtering.

Also in this section

  • LLMs from Scratch companion - tokenization and data loadingSebastian Raschka · primary

    Work through the ch02 main notebook, 05_bpe-from-scratch and 04_bonus_dataloader-intuition. Rebuild byte-level BPE, serialization and packed windows in blank files, then add multilingual, control, whitespace and chunk-boundary properties.

  • Stanford CS336 Assignment 1 - tokenizer contractStanford University · required

    Read the Assignment 1 tokenizer handout and use the named unicode1, unicode2, train_bpe, tokenizer and tokenizer_experiments specifications plus public tests as an acceptance contract. Implement independently in your own repository and do not copy or modify course solutions.

  • Hugging Face LLM Course - tokenizer translationHugging Face · optional

    After the blank-file tokenizer passes, use the tokenizer chapters to map vocabulary, special tokens, fast tokenizers and batching into library APIs. Do not replace the deterministic implementation gate with a pretrained tokenizer call.

  • Python unicodedata - normalization formsPython Software Foundation · reference

    Read unicodedata.normalize for canonical and compatibility equivalence, and unidata_version for recording the normalization database version.

  • Hugging Face Datasets - streaming, sharding and resumeHugging Face · reference

    Read Shard, Interleave, Save a dataset checkpoint and resume iteration, and Export. Use tiny local data and inspect the warning that shuffle buffers are lost on resume; do not download web-scale corpora or upload to the Hub.