Unit 9 of 11 · about 5 hours · derive, implement

Mixture weights, temperature sampling, repetition and effective tokens

The mixture decides how often each source is read, and small high-quality sources are the ones that get repeated. A recipe written in documents, or tuned at a small budget, can give a different realized composition and a very different number of epochs than the one you meant.

You'll be able to

  • Derive the sampling probability , the expected tokens and the expected epochs of each source, and show how the exponent moves a small source between a fraction of an epoch and dozens of epochs.
  • Implement a mixture sampler that works in tokens, caps the epochs of each source, and checks the realized token shares against the targets.
  • Separate raw tokens, processed tokens and effective tokens, convert epochs to effective tokens with a fitted repetition curve, and state where that curve does not apply.

Covers

Source mixture weights, temperature sampling and realized-token accountingCurriculum order, repetition, synthetic data and effective data diversityRaw tokens, effective tokens, data epochs and small-source oversampling
1

Read

In this order, only the parts listed

0 of 4 done

  1. CS336 2026 Lecture 14: Data II (executable trace)CS336 2026 - Data Lectures 13 and 14

    The data_mixing step: the mixture baselines, the 50-epoch example for a scarce source, UniMax, regression-based mixing, the scale-dependent effect and simulated epoching; then the summary of post_training_data for synthetic data

    Read RegMix as a method name only; fitting mixtures belongs to the scaling section.

  2. Scaling Data-Constrained Language Models (Muennighoff et al., 2023)Scaling Data-Constrained Language Models (Muennighoff et al., 2023)

    Section 3 and Section 3.1 (unique tokens, repetitions and the effective-data term of Equation 5), Section 6 with Figure 1 (return on compute when repeating), and Appendix A (the derivation and the fitted , Equation 17)

    Skip the allocation experiments of Section 5 and the code-augmentation results; read the abstract's claim about up to four epochs as that paper's result for its models and data.

  3. Modern LLM Notebook: Data EngineeringModern LLM Notebook - Data Engineering

    Section 4 'Data Mixing', 4.1 (the source table with epochs) and 4.2 (recipes A, B and C), then Exercise 3

    The 'Effective' column there is raw tokens times epochs, that is tokens processed, which is not the effective data of Muennighoff et al. The scores in 4.2 are labeled teaching simulations, not measurements.

  4. Gopher, Appendix A (Rae et al., 2021)Scaling Language Models: Methods, Analysis and Insights from Training Gopher, Appendix A

    Appendix A.1.2 step 6: sequences are drawn from the subsets according to fixed weights

2

Focus on

  • State weights in tokens of one named tokenizer. Sampling documents 50/50 from a source of 100-token documents and one of 1,000-token documents gives a token share of 9.1% and 90.9%, not 50/50.
  • The exponent interpolates: is proportional to size, is uniform. With a 1T-token budget, a 10T-token source and a 10B-token source, uniform sampling reads the large one for 0.05 epochs and the small one for 50 epochs, which the lecture flags as overfitting risk.
  • Repetition is not free and not worthless. Muennighoff et al. model effective data as where is the unique tokens and the number of repeats; with their fitted each token of a 4-epoch run is worth about 0.93 of a fresh one, and of a 40-epoch run about 0.38. That is a fit to their models, data and setup.
  • A mixture that is best for a small run is not best for a large one, because epochs scale with the budget. Cap epochs per source (UniMax) or simulate the large run's epochs at small scale. Treat synthetic text as its own source with a recorded generator, and sample it under the same cap.
Common mistakes · 3
  • Reading 'effective tokens' the same way in every source. In the notebook it means raw tokens times epochs; in Muennighoff et al. it means tokens counted by value, which is less than the tokens processed once data repeats. Write which one you mean in every table.
  • Treating the four-epoch result as a safe rule. It came from fixed-compute runs of models up to 9B parameters on subsets of C4 (with a check on OSCAR in an appendix), and the fitted curve says each repeated token is already worth a bit less. Check it for your model size and data, and check that filtering did not make your small source even smaller.
  • Tuning weights on a small run and applying them at scale. A weight of 0.9 on a 10B-token source is 0.9 epochs at a 10B-token budget and 90 epochs at 1T, so the small-run optimum silently becomes an overfitting recipe.
3

Try it yourself

Closed-book, before checking anything

Derive the expected epochs of source as . Then, for tokens and , compute and the epochs for , and . Expect with 0.1 epochs each; with epochs (0.097, 3.07); and with epochs (0.05, 50). Then cap each source at 4 epochs by giving the small source 4 epochs ( tokens, ) and the rest to the large one, and compute for 4 epochs with , which is 3.73.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.Two sources have 100 and 400 tokens, the budget is 1,000 tokens, and . What are the probabilities, tokens and epochs? What changes at ?Answer

    , tokens (200, 800), epochs (2, 2). At , , tokens (500, 500) and epochs (5, 1.25): the small source is repeated four times more often than the large one.

  2. 2.Source A has 1,000 documents of 100 tokens and source B has 1,000 documents of 1,000 tokens. You sample documents with probability 0.5 each. What are the token shares?Answer

    A gets and B gets tokens per draw, so the shares are 9.1% and 90.9%. To get 50/50 in tokens, weight by tokens or sample so that the expected token counts match.

  3. 3.Using the fitted repetition curve, what share of the processed tokens of a source repeated for 40 epochs counts as effective?Answer

    About 38%: against 40 tokens processed per unique token. The curve flattens at unique-token equivalents, so more epochs add almost nothing.

  4. 4.A small run finds the best weight for a scarce source is 0.9. Why might that fail at 100 times the tokens?Answer

    Epochs of the source scale with the budget, so 100 times more tokens means 100 times more epochs over the same source. What was a good weight at 0.9 epochs becomes about 90 epochs of repetition, past the point where repeats help.

5

Practice

  • TensorTonic: Compute Temperature-Based Data Mixtures

    cs336-l14-temperature-data-mixture: temperature_data_mixture(token_counts, alpha, training_budget) returning probabilities, expected tokens and expected epochs

    Free. The public cases check the proportional case, the uniform case with sizes 1 and 100, and a zero-size source that must receive zero for all three values. They do not test caps. Write your own tests for an epoch cap and for realized shares of a sampler beside the solution. The section mini-project covers the sampler and its realized-share table.

You're done when

You can derive the sampling probabilities and expected epochs without notes, your sampler's realized token shares match the targets within the sampling error you expect, and your tables say whether each 'effective' count is tokens processed or tokens by value.

Only when you can do this without notes.

Leads to

Notes

Resources · 4 for this unit, 17 more in the section
  • CS336 2026 - Data Lectures 13 and 14Stanford University · required

    Step through the Lecture 13 trace (sources: WebText, Common Crawl, CCNet, C4, The Pile, MassiveText, RefinedWeb, Dolma, DCLM, Nemotron-CC, copyright) and the Lecture 14 trace (KenLM and fastText filters, importance resampling, Bloom filters, MinHash and LSH) at cs336.stanford.edu/lectures/?trace=lecture_13 and ?trace=lecture_14. Reconcile each lecture claim with your Assignment 4 implementation.

  • Scaling Language Models: Methods, Analysis and Insights from Training Gopher, Appendix ADeepMind · support

    Read Appendix A.1 for the exact quality rules behind "Gopher-style" filters (50 to 100,000 words, mean word length 3 to 10, symbol ratios, bullet and ellipsis lines, the stop-word test) and A.5 for the datasheet. The rules are English-specific.

  • Modern LLM Notebook - Data EngineeringWalking Labs · support

    Work through notebooks-en/part2-training/15-data-engineering.ipynb (extraction, quality filtering, deduplication, mixing). Reproduce its compact examples, then compare their assumptions with the stricter CS336 tests.

  • Scaling Data-Constrained Language Models (Muennighoff et al., 2023)Hugging Face · support

    Read Section 3.1 (Equation 5, the effective-data term for repeated tokens), Section 6 with Figure 1 (return on compute when repeating data) and Appendix A (the derivation and the fitted constants). Use it to convert epochs into effective tokens and to see how far that fit reaches: models up to 9B parameters on C4 subsets.

Also in this section

  • CS336 Assignment 4 - DataStanford University · primary

    Implement the handout functions in Sections 2.2 to 2.7 (extract_text, language_identification, the PII masks, the harmful-content classifiers, gopher_quality_filter, classify_quality) and Section 3 (exact_deduplication, minhash_deduplication) until the 21 tests in tests/ pass on CPU. The 8-GPU leaderboard run is out of reach: replace it with one small local training comparison on a filtered sample and keep the retained-token and source-mix tables as evidence.

  • Deduplicating Training Data Makes Language Models Better (Lee et al., 2022)Google Research · required

    Read Section 4 (exact substring matching with suffix arrays, 50-token threshold justified in Appendix B, and MinHash near-duplicate removal) Section 5 (how much each dataset loses, including train-test overlap) and Section 6 (effects on perplexity and memorization). This is the method behind Assignment 4 Section 3; the 50-token threshold is tuned to English web text.

  • Dolma ToolkitAllen Institute for AI · required

    Read docs/data-format.md (stable source and id, attributes aligned row for row), docs/taggers.md, docs/deduplication.md and docs/mixer.md after your CS336 pipeline works. Its deduplication is a Bloom filter over document keys or paragraphs, with possible false positives, not MinHash; record which production concerns your smaller pipeline omits.

  • Dolma: an Open Corpus of Three Trillion Tokens for Language Model Pretraining Research (Soldaini et al., 2024)Allen Institute for AI · support

    Read Section 4.2 (data ablations) and Table 1 (the corpus card) as the template for your own data card. The token count depends on the tokenizer used to count.

  • FineWeb Paper and DataTrove PipelineHugging Face · support

    Read FineWeb Section 3 (each extraction, filtering and per-snapshot MinHash decision ablated on small models) and trace examples/fineweb.py in DataTrove at commit 1977fbb (14 bands x 8 hashes = 112 hashes, 5-gram words). LanguageFilter() with no arguments keeps every language above 0.65, so pass languages yourself; the cluster script is a reference, not a local run.

  • Resiliparse, fastText and datasketch on Four DocumentsOpen source · support

    Build one CPU exercise: extract text with Resiliparse extract_plain_text (it keeps navigation unless you pass main_content=True), identify language with fastText lid.176.bin and predict(text, k=1), and find near duplicates with datasketch MinHashLSH. Check every candidate against exact shingle Jaccard: at threshold=0.9 the index uses 5 bands x 25 rows, so it is a candidate filter, not a hard cutoff.

  • Language Model Tokenizers Introduce Unfairness Between Languages (Petrov et al., 2023)University of Oxford · support

    Read Section 3 (tokenization parity and premium) and Sections 4 and 5 (premiums on FLORES-200, cost and context consequences), then measure the premium of your own tokenizer on a parallel slice.

  • Analysing the Impact of Sequence Composition on Language Model Pre-Training (Zhao et al., 2024)University of Edinburgh · support

    Read Section 2 (random, same-source and retrieval packing; causal versus intra-document masking) and Table 1 (perplexity for each strategy). It is the source for testing cross-document attention leakage in your packed batches.

  • Documenting Large Webtext Corpora: A Case Study on the Colossal Clean Crawled Corpus (Dodge et al., 2021)Allen Institute for AI · support

    Read Sections 3 to 5: what C4 contains, what its filters removed, and how the blocklist removed text from and about minority groups. Use it to audit the trade-offs of your own PII and harm filters; it audits, it does not propose a recipe.

  • Data Cards PlaybookGoogle Research · support

    Follow the guide steps and use the templates to write the card for your filtered corpus: sources, rights, filters with removal rates, known gaps and intended use.

  • TensorTonic - Data Processing SetTensorTonic · support

    Solve Perform Stable Exact Deduplication (cs336-l14-stable-exact-deduplication), Build Deterministic MinHash Signatures (cs336-l14-minhash-signatures) and Compute Temperature-Based Data Mixtures (cs336-l14-temperature-data-mixture). Its MinHash uses SHA-256 of a seed and shingle, so outputs will not match datasketch. Public test cases check the listed edge cases, not gradients or the hidden grader, so keep your own tests beside each solution.

  • Tokenizer and Corpus PipelineRoadmap-Final · support

    Reuse the project correctness, lineage and contamination contracts. Extend the artifact instead of starting another tokenizer implementation.

  • DataComp for Language ModelsDataComp-LM Team · depth

    Read Section 4.4 and Table 4 (a fastText classifier keeping the top 10% of documents beat other filters), Figure 4 (removal at each stage) and the Section 3 compute table after the bounded data experiment. The repository dedups with a Bloom-filter tool (BFF), not MinHash, and CORE scores changed between v1 and v2, so never compare them directly.

  • Unicode Standard Annex #15: Unicode Normalization FormsUnicode Consortium · reference

    Read Sections 1.1 and 1.2: canonical versus compatibility equivalence, the four forms NFD, NFC, NFKD and NFKC, and why the compatibility forms can remove distinctions that matter. Use it to decide which form belongs to a matching key and which, if any, to stored text.

  • Tulu 3: Pushing Frontiers in Open Language Model Post-Training, Section 3.2Allen Institute for AI · support

    Read Section 3.2 'Prompt Decontamination' (p. 14 of arXiv:2411.15124v5): the comparison of full-string, n-gram and embedding matching, the 8-gram rule on prompts only, the 50% token-coverage test per instance and the 2% rule per dataset. Use it as a worked example of choosing the match unit and thresholds from the evaluation items.

  • FLORES-200 parallel sentencesMeta AI · support

    Use the devtest split (1,012 sentences, the same sentences in the same order for every language) to measure tokenizer premiums and per-language language-ID retention. The dataset card lists CC BY-SA 4.0 (page read 2026-10-16). The repository is archived and points to a successor; keep the original release for results you want to compare with Petrov et al.

  • Hugging Face Datasets: StreamHugging Face · reference

    Read Shard, Shuffle, Interleave, and Save a dataset checkpoint and resume iteration, including the tip that shuffle-buffer contents are lost when resuming. Use tiny local data and check resume by comparing document ids with an uninterrupted run; do not stream a web-scale corpus or upload to the Hub.