7 routes42 sections324 units

Unit 1.7 · about 5 h

296 / 324

Filtering, mixtures and deterministic shards

Filter and mixture choices determine which text the model repeatedly sees. A reproducible recipe also needs stable shard contents and restart state, not just a random seed.

  • explain
  • implement

You can now

  • Implement versioned filter decisions and quantify retained documents, bytes and tokens by source and representative slice.
  • Distinguish document sampling probabilities from token exposure and defend a small source mixture.
  • Publish deterministic, checksummed local shards and resume without omitted or duplicated records under a fixed configuration.
  • Use synthetic examples to distinguish PII redaction, toxicity review and quality filtering without claiming production safety.

Covers

  • Filtering reasons, yield and representative slices
  • Mixture weights, sampling units and token exposure
  • Deterministic sharding, manifests and restart behavior
  • Small PII, toxicity and quality-filter policy exercise

Study, in this order

3 steps

  1. Filter decisions and source mixtures
    Modern LLM Notebook - tokenization and data experiments

    Section 2.1 with quality_check; Section 2.3, PII and Safety Filtering, with redact_or_drop; Sections 4.1 and 4.2 with source effective-token amounts and Recipe A/B; Exercises 1 and 3

    Depth · Skip Section 2.2 and Sections 4.3 onward. The rules and recipe scores are teaching examples, not validated quality thresholds or measured model results. Use only synthetic sensitive-data examples.

  2. Shard ownership, mixture sampling and iterator state
    Hugging Face Datasets - streaming, sharding and resume

    Shard under Split dataset; Interleave, including probabilities and stopping_strategy; Save a dataset checkpoint and resume iteration, including its shuffle-buffer warning; Export

    Depth · Use tiny local records and the six-record checkpoint example. Skip remote corpus downloads, the training loop and Save to the Hub. Library resume is a comparison, not a substitute for testing your own exact-resume contract.

  3. Auditable recipes and local shard publication
    Tokenizer and Corpus Pipeline - reduced foundation slice

    Core requirements: mixture weights, deterministic sample/pack construction, checksums, atomic manifests and resume; Architecture constraints: manifests instead of directory discovery; Milestone B: per-stage counts and filter samples; Correctness requirements: complete nonoverlapping shards

    Depth · Keep one process and a few local shards. Leave distributed storage, production classifiers and internet-scale processing for later.

Focus on

  • Log keep, redact, reject or review with a reason and policy version. Report yields by source/language/code slice and by documents, bytes and tokens; a smaller corpus is not automatically better.
  • For source document probability \(p_s\) and mean retained length \(L_s\), expected token share is \(p_s L_s / \sum_j p_j L_j\), before truncation and exhaustion effects. Declare the sampling unit and replacement policy.
  • A manifest fixes ordered shard paths, checksums, counts, split, tokenizer identity and recipe version. Publish only complete shards and reject resume under a changed configuration.
  • Exact resume needs input/shard cursor, sampling RNG, any shuffle buffer and the unfinished pack. HF's documented iterable resume loses buffered shuffle examples; a seed alone does not restore them.

Reproduce closed-book

Build a tiny local recipe that records filter reasons, samples two unequal-length sources and writes ordered shards plus a checksummed manifest. Save the cursor, RNG and partial-pack state, interrupt mid-shard, and compare the resumed record IDs, token exposure and artifact bytes with an uninterrupted run.

Traps

  • Applying English word-length and punctuation rules to code or languages without spaces. Inspect false rejections by slice before choosing thresholds.
  • Treating email regex redaction or a toxic-word hit as a safety guarantee. Names, context and obfuscation can escape it; benign quotations can be flagged.
  • Rebuilding shard order from a directory listing or restarting from only a seed. Either can change the next record, duplicate work or lose a partially built pack.

Practice

The section mini-project covers this: reason-coded filters on representative slices, a synthetic PII/toxicity/quality policy table, source token-exposure accounting, deterministic shard manifests and interruption/resume equivalence.

Self-test

  1. Sources A and B are sampled equally by document, with mean lengths 100 and 900 tokens. What token share is expected?

  2. What should you report if a filter retains 80% of documents but only 30% of tokens?

  3. Why does HF's iterable state checkpoint not guarantee exact shuffled continuation?

  4. A crash leaves a shard file but no manifest entry. Should the reader consume it?

  5. What does a synthetic toxicity-policy test demonstrate?

Completion criterion

Stop when

An interrupted and uninterrupted small run produce identical ordered IDs and artifact checksums, changed-config resume is rejected, and your audit explains filter yields and observed document versus token shares.

Mark passed, then open 2.1 Only mark this when you can do it without notes.

Leads to

Comes after

Resources for this unit

  • Modern LLM Notebook - tokenization and data experiments
    Walking Labssupportimplementation
    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 slice
    Roadmap-Finalsupportproject
    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.
  • Hugging Face Datasets - streaming, sharding and resume
    Hugging Facereferencereference
    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.

Also in this section

  • LLMs from Scratch companion - tokenization and data loading
    Sebastian Raschkaprimaryimplementation
    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 contract
    Stanford Universityrequiredassessment
    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 translation
    Hugging Faceoptionalreference
    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 forms
    Python Software Foundationreferencereference
    Read unicodedata.normalize for canonical and compatibility equivalence, and unidata_version for recording the normalization database version.

Quick find

Search Michi

Type to search every route, section, unit, topic and resource.

Enter opens the first result Esc closes

Reference

Keyboard shortcuts

n
Continue to the first unit not passed
j / k
Next / previous unit
1 2 3
Toggle learned, practised, passed
/
Open search
?
Show this help
Esc
Close open panels