Vibe Engines
YouTube

Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path

Handbooks  /  Synthetic Data
Handbook~15 min readTrainingworked math + runnable code
The Synthetic Data Handbook

Data a model
writes for itself.

Need ten thousand training examples of a rare edge case? Don't collect them — generate them. LLMs can write their own training and eval data: instruction pairs, reasoning traces, test inputs, paraphrases, on demand, at scale. It's one of the most powerful tools in modern AI — and one of the easiest to misuse. Pour in unfiltered generations and you teach a model its generator's mistakes; recycle a model's own output back into it and the whole distribution quietly caves toward the average. This handbook is about generating data that helps, and the two failure modes that make it hurt.

01

Generate your data

Data is the bottleneck for most AI work — real, labelled examples are scarce, expensive, and often missing exactly where you need them (rare cases, new formats, niche domains). Synthetic data sidesteps that: use a capable model to generate the examples. Ask a strong LLM to write instruction-response pairs, produce step-by-step reasoning traces, invent tricky test inputs, or paraphrase for augmentation — as many as you want, targeted at the exact distribution you're missing.

This powers a lot of modern practice: self-instruct (a model generating its own instruction-tuning data), distillation (a big teacher model labelling data for a small student), reasoning-trace generation (as in STaR), and eval-set creation. It's cheap, fast, and controllable. But generated data has a property real data doesn't: its quality is set by the generator, and generators are imperfect. That single fact drives everything else in this handbook.

The one-sentence version

Generate data with an LLM, but filter hard — effective dataset size is generated count times pass rate — and never recursively train on unfiltered self-output, or the distribution collapses.

02

Quality beats volume

The instinct with synthetic data is to generate more. The reality is that a pile of mediocre examples can make a model worse — training on wrong, repetitive, or off-distribution generations teaches wrong, repetitive, off-distribution behavior. What matters isn't how much you generate; it's how much survives a quality filter.

So the useful quantity is the effective dataset size: generate N examples, keep only the fraction p that pass a quality check, and you have p·N good examples. A filtered set of 300 strong examples routinely beats an unfiltered 1000. This is the lesson of the Phi models: trained on small, ruthlessly-filtered, "textbook-quality" data, they punched far above their parameter count. The filter — a test suite, a judge model, an execution check, a difficulty/diversity score — is not an afterthought; it's the most important part of the pipeline.

03

Model collapse

The subtler danger appears when synthetic data feeds back into the models that made it. Train a model on data generated by models — including its own output — recursively, without enough real data, and you get model collapse: each generation loses a little of the distribution's tails, the rare and unusual, and drifts toward the average.

Each recycle narrows the distribution
Round 0Real data — full diversity, fat tails.
Round 1Train on its generations — rare cases under-sampled, variance shrinks.
Round 2Generations of generations — tails vanish, drift toward the mean.
Round NDistribution collapses — homogeneous, generic, low-variance output.

Mathematically, each round of naive self-training multiplies the distribution's spread by a factor below one, so variance decays geometrically toward zero — the model forgets how to produce anything unusual. This isn't hypothetical: as more of the web becomes model-generated, models risk training on their own exhaust. The defenses are the same ones good pipelines already use — mix in real data to anchor the distribution, filter and deduplicate to preserve diversity, and never train purely on unfiltered recursive generations.

04

The yield & collapse math

Two equations capture the whole tension. First, yield: generate N examples, keep the fraction p that pass the quality filter, and your effective, usable dataset is:

effective size  =  p · N   ⟹   raise p (better filter), not just N (more volume)

A small p can make a giant generation nearly worthless; improving the filter's pass-quality is usually worth more than generating more.

Second, collapse: naive self-training shrinks the distribution's variance by a factor s < 1 each round, so after k rounds the diversity has decayed geometrically:

Vark  =  sk · Var0   (s < 1)   ⟹   Vark → 0 as k grows

Diversity vanishes exponentially under recursive self-training — which is why real data and filtering must stay in the loop. The runnable version below computes effective size, filters by quality, and watches variance collapse round by round.

RUN IT YOURSELF

Filter, and watch collapse

Synthetic data is two numbers. Yield: generate N examples, keep the fraction p that pass a quality filter, and the effective dataset is p × N — so a better filter beats more volume, and 300 filtered examples beat 1000 unfiltered ones. Collapse: each round of naive self-training pulls the values toward the mean, shrinking variance by a factor each time, so after a few rounds the tails vanish and the distribution homogenizes. Change the pass rate, the filter threshold, or the shrink factor and watch the effective size and the diversity move.

CPython · WebAssembly
05

A safe pipeline

A production synthetic-data pipeline is a generate-then-filter loop with real data in the mix:

StageWhat it does
SeedStart from real examples to anchor the target distribution and style.
GenerateUse a strong teacher model to produce many candidates, with diversity prompts.
FilterScore for correctness, difficulty, and diversity — keep only the good (tests, judge, execution).
DeduplicateRemove near-duplicates so the set stays diverse, not padded.
MixBlend synthetic with real data rather than training purely on generations.

The filter is where the value is — verify with the strongest cheap signal you have (unit tests for code, a judge model for text, execution for math), the same verify-then-keep logic behind STaR's reasoning bootstrapping. And curate for the target: if you need hard examples, filter for difficulty; if you need coverage, filter for diversity. Anchoring on real seeds and mixing real data back in are what keep the distribution honest and stave off collapse. Then evaluate on held-out real data — synthetic data can flatter itself, so the scoreboard must be real.

06

Pitfalls

The quiet killer is distribution narrowing. Even one round of unfiltered self-generation subtly shrinks diversity — the model over-samples its favorite phrasings and under-samples the rare cases — and it compounds. So measure diversity, not just accuracy, and keep real data anchoring the set. A related trap: inheriting the generator's errors and biases. Synthetic data can only be as correct as its generator plus its filter; if the teacher is wrong in a systematic way and the filter can't catch it, the student learns the flaw at scale. Verify against ground truth wherever you can, not just against another model's opinion.

Two more. Evaluating on synthetic data is circular — a model can look great on data drawn from the same generator and fail on real inputs, so hold out real data for the scoreboard. And contamination: generated eval sets can accidentally overlap the training distribution, inflating scores. Used with discipline — strong generator, ruthless filter, real seeds and real evals — synthetic data is a superpower for covering the cases reality won't hand you. Used naively, it's a slow way to teach a model to be average.

Worth knowing

Synthetic data can only be as good as generator + filter. If the generator is systematically wrong and the filter can't detect it, you scale the error — so verify against ground truth (tests, execution, real labels), not just another model's judgment, and always evaluate on held-out real data.

By the numbers

Worked example: how many to generate for 2,000 good ones

Say you need 2,000 clean examples to fine-tune a text-to-SQL model. Every candidate has to pass three filters in turn. Illustrative pass rates: 60% of the generated queries run and return the expected rows, deduplication then removes a quarter of those, and a judge model keeps 80% of what is left. Work backwards from the target.

StageKeepsArithmeticCount
Overall yield p—0.60 × 0.75 × 0.800.36
Generate Nall2,000 ÷ 0.36, rounded up5,556
Execution check60%5,556 × 0.603,334
Deduplicate75%3,334 × 0.752,500
Judge model80%2,500 × 0.802,000
Cost per kept example—1 ÷ 0.362.78 generations
Collapse check: the page’s 5-value base, variance 2.0shrink 0.7variance × 0.7² = × 0.49 per round0.98, then 0.48, then 0.24

Two lessons. First, the filter sets the bill. Raise the execution pass rate from 60% to 80% with a better prompt or a better seed set, and the same 2,000 needs far fewer generations. That is the page’s “raise p, not N”. Second, read the shrink factor carefully. The page’s runnable code pulls each value 0.7 of the way back from the mean, which multiplies variance by 0.49. So s in the formula Var_k = s^k · Var_0 is 0.49 here, and three rounds keep only 0.24 ÷ 2.0 ≈ 12% of the original spread.

Trade-offs

Cost and trade-offs of each filter

Here Time is the cost per example, Space is what the filter can catch, and Why is its blind spot.

CaseTimeSpaceWhy
Execution or unit testsCheap: run the code or check the answerWrong answers, crashes, bad syntaxOnly works where a checker exists: code, maths, SQL. Weak tests let wrong answers through.
Judge modelOne more model call per exampleOff-topic, unhelpful or badly written answersIf it is the generator, or a close relative, it shares the same blind spots and grades them as fine.
Human reviewThe slowest and most expensive per exampleSubtle errors, the real-world ground truthIt cannot cover everything. Use it on a random sample to measure how good the cheaper filters are.
Exact dedupO(n): hash each example onceCopies that match word for wordMisses paraphrases, which are the usual kind of LLM repetition.
Near-duplicate dedupPairwise is O(n²): 10,000 examples is 49,995,000 pairsParaphrases and template clonesMinHash with LSH, or an embedding index, makes it close to linear at the cost of a few misses.
Difficulty or diversity scoreA score per example, then pick a sliceToo-easy padding, crowded topicsFiltering hard for one score can remove the rare cases you generated the data to get.

Stack filters from cheapest to dearest, as in the worked example: execution first, the judge only on the survivors, humans on a sample. Each one sees fewer examples than the one before, so you pay the expensive filters least.

In the wild

Where this shows up in practice and interviews

  • Self-Instruct and Alpaca

    Self-Instruct started from 175 human-written seed tasks and had the model write new instructions and answers, filtering out near-duplicates. Alpaca used the same recipe to generate 52K instruction examples from a stronger model, and fine-tuned a 7B LLaMA model on them. It is the seed, generate, filter loop from the page.

  • Distillation and small models

    A large teacher labels or writes data and a small student trains on it. Phi-1 (“Textbooks Are All You Need”) trained on filtered web code plus synthetic textbook-style text. Before you distil, check the generator’s licence or terms: some forbid using its outputs to train competing models.

  • Evals and red-teaming

    Generated test inputs give you edge cases and adversarial prompts quickly. Keep them separate from the training data, and confirm the scores on real inputs too, because a set from the same generator flatters models that share its habits.

  • The interview version

    For “you have 200 labelled examples and need a classifier”, describe the pipeline. Use the real 200 as seeds and as a held-out test set. Generate many more, filter them in stages, dedupe, mix in the real data, and evaluate only on real data. Then mention privacy: synthetic data made from real records can still reproduce them, so it is not anonymous by default.

Self-check

Check yourself

Run A generates 10,000 examples with a 15% pass rate. Run B generates 3,000 with a 60% pass rate. Which gives more usable data?

A: 10,000 × 0.15 = 1,500. B: 3,000 × 0.60 = 1,800. B wins with less than a third of the generations, and its survivors are likely better too, because a prompt with a 15% pass rate is usually producing poor candidates.

Each round of naive self-training pulls every value 0.9 of the way back from the mean. After how many rounds is the variance below half the original?

Variance shrinks by 0.9² = 0.81 per round: 0.81, 0.656, 0.531, then 0.430. So it falls below half after 4 rounds, even though each round looks like only a 10% pull. Geometric decay is slow at first, then fast.

Your fine-tuned model scores 95% on a synthetic test set and 70% on real tickets. What happened?

The test set came from the same generator as the training data, so it shares the generator’s phrasing and blind spots. The model learned the generator’s style, not the task. Score against held-out real data. Also check the synthetic eval set for overlap with the training data (contamination).

You use the same model to generate examples and to judge them. What goes wrong, and what is the better filter?

A systematic error in the generator gets graded as correct by the same model, so the filter passes it every time and the student learns it at scale. Prefer ground truth (tests, execution, real labels). Failing that, use a different judge, and check a human-reviewed sample to measure how often it is wrong.

Frequently asked

Quick answers

What is synthetic data?

Training or eval data generated by a model rather than collected from humans — instruction pairs, reasoning traces, test inputs, paraphrases — cheap, scalable, and targetable.

Why filter over volume?

Bad generations teach bad patterns; effective size is generated count × pass rate, so a small filtered set beats a large unfiltered one.

What is model collapse?

Recursive training on model-generated data shrinks diversity round by round — variance decays toward the mean and the distribution homogenizes.

How to generate safely?

Strong generator, ruthless filter (tests/judge/execution), real seeds, deduplicate, mix in real data, and evaluate on held-out real data.

Finished this one? 0 / 209 Handbooks done
NextTest-Time Compute & Reasoning Models Next on the “Training and adaptation” ladder · rung 5 of 7

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Handbooks