Vetting a Large Scraped Corpus Before Fine-Tuning a 7B Model
Machine LearningModel answerLast updated
Plan how to screen, score, and test a big low-trust dataset before mixing it into SFT and preference tuning, with ablations and clear release gates to avoid regressions.
Context
You own the post-training stage (supervised fine-tuning followed by preference optimization) for a 7B-parameter model that must follow instructions and reason well. The current checkpoint was trained on a trusted, human-reviewed set of 40,000 instruction-response pairs.
Another team offers an additional 500,000 prompt-response pairs. They were harvested from developer Q&A sites, user-contributed examples, and model-generated tasks, and carry only weak labels. The extra data would broaden domain coverage, but a first look shows serious problems:
- reasoning chains containing invented or invalid steps
- code that does not run or parse
- uneven writing tone and formatting
- leaked secrets and personal data (API keys, email addresses)
- toxic or unsafe material
Your task
Propose a complete plan for deciding whether to use this data and how. Cover each of the following.
-
Auditing and filtering
- Cheap automated rules to discard junk early (length and ratio checks, reference-model perplexity, exact and near-duplicate removal, and similar).
- A model-based way to judge correctness and reasoning quality (reward model, LLM judge, self-consistency, execution checks).
- Screens for safety, toxicity, and personal or secret data.
-
Fit to the target distribution and diversity
- How you decide whether the new data complements the trusted set instead of pulling the model away from the intended distribution.
- How you use embeddings, clustering, or nearest-neighbor search against validation prompts to find over-represented and under-represented task areas.
-
Experiments and regression protection
- An ablation design that compares different ratios of trusted to curated external data.
- The set of benchmarks and checks that would reveal forgetting, style drift, an alignment tax, or safety regressions.
- Explicit go/no-go criteria that a new checkpoint must satisfy before it ships.
Explain your reasoning and trade-offs, and give concrete numbers (thresholds, yields, sample sizes) where you can.
Hints
Hint 1
Treat the 500k set as a pool of candidates, not as training data. Order the filters from cheapest to most expensive so the costly judge models only see survivors.
Hint 2
Anchor 'distribution fit' to something concrete: embed trusted data, real traffic and external prompts together, cluster them, and compare densities and nearest-neighbor distances to separate redundant, gap-filling, and out-of-scope samples.
Hint 3
Fix compute and total token budget across ablation arms, include a random-unfiltered arm to prove the filter matters, run multiple seeds, and write numeric go/no-go thresholds before seeing any results.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Framing
The core decision is whether this data should be used at all. Treat the 500k examples as a candidate pool that has to earn its way in. The plan is a cheap-to-expensive filtering funnel, a measurement of how each sample relates to the target distribution, and controlled experiments with pre-registered release criteria.
0. Clarify first
- Target distribution: define it as the trusted set plus a sample of real product traffic. "Coverage gap" is meaningless without it.
- Stage needs: SFT needs good responses. Preference tuning needs pairs, and a flawed response that was filtered out can serve as the "rejected" side.
- Compliance: decide up front whether PII means drop or redact. Credentials should always be dropped.
- Budget: a judge pass over ~150k samples at ~2k tokens is ~300M tokens. That is affordable only after cheap filters shrink the pool.
1. Filtering funnel
Stage A: rule-based (CPU, minutes)
| Check | Rule |
|---|---|
| Exact dedup | Hash of normalized prompt + response |
| Near dedup | MinHash LSH on 5-gram shingles, Jaccard ≥ 0.8, keep one per cluster |
| Decontamination | Drop anything with a 13-gram overlap with any eval benchmark or validation prompt |
| Length | Drop empty/truncated responses, very short answers to non-trivial prompts, extreme response/prompt ratios (outside 1st-99th percentile), repeated-line spam |
| Perplexity | Score with a small (~1B) reference LM tuned on trusted-like text; drop the worst ~5% and optionally the lowest ~1% (boilerplate, memorized text) |
| Format | Language ID, broken markdown, code blocks that fail to parse |
Expected yield: about 500k → 300k.
Stage B: safety and privacy
- Secrets: regexes for known key formats plus entropy detection. Drop these samples, do not redact.
- Personal data: regex plus NER for emails, phones, addresses. Replace with placeholders when the sample is otherwise valuable.
- Toxicity/harm: run a safety classifier on prompt and response. Drop harmful compliant answers. Keep harmful prompts only when paired with a proper refusal; these make good preference pairs (refusal chosen, compliance rejected).
Stage C: quality scoring (expensive)
- Verifiable first: execute code in a sandbox against tests; check math answers numerically or symbolically.
- Reward model as a fast ranking pass.
- LLM judge with a rubric (correctness, step validity, instruction adherence, tone), asking for per-step verdicts rather than one holistic score.
- Self-consistency: sample ~8 answers from a strong model; low agreement with the supplied answer flags a wrong label or ambiguous prompt.
- Calibration: humans label ~1-2k stratified samples; report Cohen's κ and precision at the chosen threshold. Favor high precision, since false positives poison training.
Expected yield: about 300k → 60-120k high-confidence samples.
2. Distribution fit and diversity
- Embed trusted, external, and traffic prompts with one encoder.
- Cluster the union (k-means, k≈300). Per cluster compute the density ratio
p_external / p_target, the trusted-sample count, and the baseline's validation loss. - Use kNN distance to the nearest trusted/traffic prompts to bucket samples:
- Redundant (near trusted data, dense cluster): downsample heavily.
- Gap-filling (near traffic but sparse in trusted data, or the baseline is weak): upweight. This is where the value is.
- Out-of-scope (far from everything): drop or cap.
- Mixture-level metrics versus target: MMD in embedding space, a two-sample classifier (AUC near 0.5 is good), and cluster-coverage entropy to make sure the mix does not collapse onto popular forum topics.
- Compare response-side statistics (length, formatting, tone). Mismatches here predict style drift.
3. Ablation study
Hold the base checkpoint, hyperparameters, and total token budget fixed so only data varies.
| Arm | Data |
|---|---|
| A | Trusted only (baseline) |
| B | Trusted + random unfiltered external (shows filtering matters) |
| C1-C3 | Trusted : curated at 1:0.5, 1:1, 1:2 by tokens |
| D | Trusted + gap-filling clusters only |
| E | Best SFT mix + preference pairs mined from the funnel |
Run 3 seeds for the leading arms so noise bars separate real gains from ~0.5-point jitter.
4. Regression suite
- Anchors: MMLU, GSM8K, MATH, BBH, HumanEval/MBPP, trusted held-out loss.
- Instruction following: IFEval plus internal format-constraint tests.
- Targeted gains: held-out prompts from gap clusters, graded by humans or calibrated judges.
- Safety: attack success rate on red-team suites; over-refusal on XSTest-style prompts to catch alignment tax in both directions.
- Style: response length distribution, tone/markdown classifier, length-controlled pairwise win rate.
- Privacy: extraction/canary probes for patterns seen in the raw data.
5. Go/no-go (fixed before training)
All must hold:
- No anchor drops by more than max(1 pt, 2σ seed noise).
- Targeted domains improve by ≥ 3 points.
- Win rate ≥ 55% vs baseline on human-graded held-out traffic.
- Attack success rate does not rise; over-refusal rises ≤ 1 pt.
- No IFEval regression.
- Median response length within ±15% of baseline.
- Zero PII/secret regurgitation in probes.
If any gate fails, do not ship; diagnose by arm and cluster (which slice caused the drop), tighten thresholds or lower the mix ratio, and rerun.
Trade-offs and common mistakes
- Skipping decontamination inflates benchmark scores and hides real regressions.
- Loose judge thresholds admit confident-sounding wrong reasoning; precision matters more than recall here.
- Using judge scores uncalibrated bakes in judge bias (e.g., preferring long answers).
- Changing compute between arms confounds data effects with training length.
- Single-seed comparisons mistake noise for signal.
- Only checking aggregate metrics hides cluster-level regressions; always slice.
- Redacting secrets rather than dropping them can leave recoverable fragments.
- Deciding thresholds after seeing results invites rationalizing a launch.
A reasonable outcome is shipping only the curated 60-120k subset, weighted toward gap-filling clusters, at roughly a 1:1 token ratio with trusted data, and keeping the rest as a pool for future iterations.