Corpus provenance, mixtures, and decontamination
Corpus quality is governed by provenance, realized sampling, and auditable exclusions—not merely by token count.
A private support assistant must answer from evidence and resist manipulation.
This chapter moves from create a source ledger to quarantine evaluation overlap. We will make the idea concrete in a small code example before placing it back inside a production system with a declared latency, cost, and operator-capacity budget.
Hash normalized text, run near-duplicate search against protected evals, review suspicious matches, and version both exclusions and the detector thresholds.
Verify the behavior illustrated in decontaminate.sql, then measure decision utility, slice reliability, and system latency.
Evaluation contamination and feedback only from successful chats hide refusals, unsupported languages, and hallucinated citations. An unsafe release must degrade to a named baseline or the last known-good version.
Build the idea one layer at a time.
A training corpus is not “the internet.” It is a versioned mixture of sources, permissions, transformations, exclusions, and sampling decisions.
Provenance answers where each document came from, when it was collected, what license or consent applies, and which transformations produced the final text. Mixture weights determine how often a source appears during training; raw volume is not neutral because duplicated or high-resource domains can overwhelm smaller but important slices.
Decontamination protects evaluation validity by removing exact and near-duplicate training examples derived from held-out tests. It must happen before release decisions and leave an auditable report. Exact hashes catch byte- or normalized-text matches; approximate matching is needed for reformatted questions, translated items, and answer-bearing fragments.
- RAG vs tuning
- provenance
- decontamination
- tokenizer fertility
Follow the reasoning before touching the code.
- 01
Create a source ledger
Assign every document a source, collection time, license basis, language, transformation chain, content hash, and deletion policy before mixing.
- 02
Design sampling intentionally
Set caps or temperatures by source and language, then inspect the realized token mixture after filtering and deduplication rather than trusting requested weights.
- 03
Quarantine evaluation overlap
Hash normalized text, run near-duplicate search against protected evals, review suspicious matches, and version both exclusions and the detector thresholds.
WITH eligible AS (
SELECT document_id, source_id, license, normalized_sha256, token_count
FROM corpus_documents
WHERE license IN ('owned', 'permissive', 'consented')
), clean AS (
SELECT e.*
FROM eligible AS e
LEFT JOIN protected_eval_hashes AS p
ON e.normalized_sha256 = p.normalized_sha256
WHERE p.normalized_sha256 IS NULL
)
SELECT source_id, COUNT(*) AS documents, SUM(token_count) AS tokens
FROM clean
GROUP BY source_id
ORDER BY tokens DESC;Exclude exact normalized-text overlaps while preserving provenance fields.
What to notice
- The query filters permission status before counting the realized source mixture.
- A left anti-join removes exact normalized matches, but a separate approximate detector is still required for paraphrases and fragments.
YOUR TURN Pause and predict before revealing the answer.
Why is deleting only the final evaluation answer string an inadequate decontamination policy?
Need a hint?
A training example can reveal the problem, solution path, or reformatted pair without containing that exact string.
Check your reasoning
The model may still see the question, a paraphrase, a rationale, or an answer-bearing excerpt. Decontamination should compare full examples and meaningful fragments with exact and near-duplicate methods.
Lessons 1 in this course.
Connect the chapter to the course’s quantitative spine.
Corpus quality is governed by provenance, realized sampling, and auditable exclusions—not merely by token count. The autoregressive next-token loss below is the shared course-level lens that helps quantify the surrounding system. Name each symbol, check its units or shape, and use only values that were available at the production cutoff.
Autoregressive next-token loss
| Symbol | Meaning / shape / unit |
|---|---|
T | sequence length |
x_t | target token |
θ | model parameters |
Open derivation and numerical substitution
Start from the production quantity being optimized, substitute the observed values with their declared units, then isolate the model-controlled term. Preserve shape annotations at each step so broadcasting or aggregation cannot silently change the result.
- Write the named inputs: T, x_t, θ.
- Substitute one small, hand-checkable batch before vectorizing.
- Calculate an independent reference value and compare within a declared tolerance.
# equation → code contract
inputs = validate_shapes_and_units(batch)
value = compute_c15(inputs)
assert is_finite(value)Change one assumption and make the tradeoff visible.
Use the worked chapter as your prediction, then change one input in the lab and explain why the output moves. The lab runs predefined TypeScript and never executes learner code, so the focus stays on the concept rather than setup.
Retrieval depth lab
Change top-k and estimate evidence recall, context cost, and distractor risk.
Assumption: Fixed retrieval curve; each passage contributes 180 tokens.
Open nonvisual data table
| Item | Computed state | Interpretation |
|---|---|---|
| passage 1 | 88.0% | 180 tokens |
| passage 2 | 79.0% | 192 tokens |
| passage 3 | 70.0% | 204 tokens |
| passage 4 | 61.0% | 216 tokens |
| passage 5 | 52.0% | 228 tokens |
Trace the complete operating path.
Carry the chapter’s central idea into the system: Corpus quality is governed by provenance, realized sampling, and auditable exclusions—not merely by token count. The path below shows where that reasoning needs an artifact, a test, an owner, or a fallback.
- 01
Turn “Create a source ledger” into a written invariant and a failing test.
- 02
Promote decontaminate.sql from illustration to a versioned implementation with representative fixtures.
- 03
Use “Quarantine evaluation overlap” as the release checkpoint: Hash normalized text, run near-duplicate search against protected evals, review suspicious matches, and version both exclusions and the detector thresholds.
- 04
Serve or materialize behind explicit a declared latency, cost, and operator-capacity budget.
- 05
Join telemetry to mature outcomes and retain a rollback path.
Observability
Join service health, input quality, prediction distributions, slice behavior, and mature outcomes by exact version.
Cost
Measure storage, preprocessing, compute, queueing, and human review under a representative arrival pattern.
Failure modes
Evaluation contamination and feedback only from successful chats hide refusals, unsupported languages, and hallucinated citations. Add a detector, owner, mitigation, and stop condition for this class of failure.
Alternatives
Compare a rule, a simpler statistical baseline, and a different system boundary before adding model complexity.
Explain the contract, not just the vocabulary.
Domain adaptation release package
Compare prompt, retrieval, and optional PEFT approaches under one provenance and evaluation contract.
- Approach decision
- Provenance ledger
- Slice evaluation
- Safety probes/model card
Read primary material with a purpose.
Return to the opening failure.
Release model, tokenizer, retrieval index, prompt, policy, datasets, eval suite, and runtime config as one bundle.
For this lesson, the release evidence is the worked code example, a hand-checked formal result, deterministic simulation output, a ≥80% checkpoint, the production rubric, and a named fallback. The course resolves when the system can produce a grounded system design spanning adaptation, rag, evaluation, and safety.