Skip to content

Textbook-style synthetic data: why it works, and why it may not transfer

THE ARGUMENT

The gain from textbook-style synthetic data has to be read stage by stage: phi-1 put GPT-3.5-generated textbooks into from-scratch pretraining, where knowledge really did enter the weights, then used a small set of exercises to fine-tune that ability into the shape of instruction-driven function completion [1]. Generalising from this single study to 'synthetic data only reduces format noise and cannot teach new knowledge' is overreach; acceptance should separate knowledge gain, format alignment and evaluation framing into three test sets.

On this page

(The scene below is invented, not a real project.) You spend two weeks having a strong model rewrite internal documents as a textbook: one short section per chapter, a few exercises with worked solutions. You fine-tune a small model on it and the internal test score moves up from the pass line. The team is pleased. Two weeks after launch, the support metrics have not moved at all. You conclude there was not enough data and generate several times more. The problem may not be volume: whether you bought knowledge or just a habit of expression can only be separated with the right test sets.

Start with a success that did not transfer

The scene above is invented and corresponds to no real project. The failure mode it describes is common: a model does well on a test set that shares the format of its training data and poorly on real user input. The difference is not knowledge but input shape. Textbook questions are complete, well pointed, and free of typos. Real questions are short, vague, and quote a policy that was replaced three years ago.

So the first question about this kind of data is not how many points did it add, but on which inputs. If the gain sits entirely in the tidy-format bucket while your traffic is mostly the messy bucket, the gain is not yours. The data is not bad; the acceptance test measured the wrong object.

More importantly, 'textbook-style data' is not one thing. At least three layers have to be separated: what the teacher (a strong model) generated, what the student (the small model) learned during pretraining, and what the final fine-tuning aligned that ability into. phi-1's synthetic textbooks were part of a from-scratch pretraining corpus, so one cannot say they 'taught no new knowledge'; its final fine-tuning on a small set of exercises lifted HumanEval from about 29% to 50.6%, and the paper itself explains this as 'reorganizing and consolidating the knowledge acquired during pretraining', not as new libraries being packed into the exercises [1]. Collapsing the three layers into 'the gain is only format' fits neither phi-1 nor the general claim a single paper can support.

What phi-1 actually did

Textbooks Are All You Need is not just 'filter, then generate'; it has two training stages and three datasets [1]. Data: (1) filtered web code (the deduplicated Python subset of The Stack plus StackOverflow), where GPT-4 labels about 100k samples for 'educational value for a student learning basic coding' and a random-forest classifier then filters them, about 6B tokens; (2) GPT-3.5-generated synthetic textbooks interleaving natural-language explanation with code snippets, under 1B tokens; (3) GPT-3.5-generated CodeExercises, about 880k function-completion exercises with solutions and about 180M tokens, using only basic Python libraries [1]. Training: first pretrain a 1.3B decoder-only Transformer from scratch on CodeTextbook (datasets 1+2, about 7B tokens) to get phi-1-base, then fine-tune on dataset 3 (about 7 extra hours on the same hardware) to get phi-1 [1]. In other words, the synthetic textbooks belong to pretraining, the stage that writes capability into the weights; the exercise fine-tuning is a separate, much smaller stage.

The results also have to be read stage by stage. phi-1 reaches pass@1 50.6% on HumanEval and 55.5% on MBPP, ahead of many far larger models (Table 1: StarCoder 15.5B at 33.6%, WizardCoder 16B at 57.3%, GPT-4 at 67%) [1]. But looking only at the fine-tuned phi-1 misattributes the credit: phi-1-base, pretrained without the exercise fine-tuning, already reaches about 29% HumanEval, and the 350M phi-1-small trained with the same pipeline reaches 45% [1]. Textbook-style pretraining itself built the coding ability; exercise fine-tuning added a further large jump. To rule out 'just memorising the test', the paper had a team that never saw the exercises design 50 out-of-distribution unconventional problems graded by GPT-4, where phi-1 still clearly beats StarCoder; after pruning over 40% of HumanEval-similar exercises and retraining, HumanEval stays at 45.1-50.6%, above StarCoder-Prompted's 41.5% [1].

The paper's limits are specific, not a vague 'weak on world knowledge' [1]: (1) sensitivity to prompt wording, length and grammatical errors - Appendix B attributes part of this to the exercises being mostly short prompts, so long prompts get parts ignored or misread; (2) a lack of the domain-specific knowledge larger models have, such as programming with specific APIs or less common packages; (3) specialisation in Python, with less versatility than multi-language code models. The authors add that 'none of these limitations seem fundamental', but give no estimate of the scale needed to overcome them and make no claim that the recipe generalises to other domains [1]. These three points decide whether you can copy the approach, and matter more than memorising 50.6%.

Four ingredients of the textbook genre, and the signals you failed to copy them

The paper's own four words for high-quality training data are clear, self-contained, instructive and balanced [1]. The table below is my regrouping by 'what to check during acceptance', not a list the authors gave and not a set of sufficient conditions the paper proved. Its use is to check generated data item by item, rather than vaguely asking a model to write more like a textbook.

IngredientHow phi-1 shows itHow to reproduce itSignal you failed
Self-containedSnippets avoid external libraries and run on their ownRequire every example to carry all its premises, with no reference to earlier textSamples contain as mentioned above or see chapter so and so
Graded difficultyFrom single functions to multi-step reasoning, with real stepsOrder by concept dependency, define before useEvery sample sits at one difficulty and combination is never taught
CoverageOne concept appears in several phrasings and edge casesForce counterexamples and boundary cases for each conceptThe three generated exercises are one exercise with different numbers
VerifiableExercises have answers; code passes testsAttach an executable answer, or at least an explicit criterionThe answer is prose that cannot be judged right or wrong

Row four is the one most often abandoned. Code at least offers compilation and tests to decide part of the answers automatically; your domain often has no such verifier. Without one, the share of wrong answers in synthetic data can only be estimated by sampling, and that share grows as the generator is given more freedom. The paper itself concedes that GPT-3.5-generated data has a high error rate, yet phi-1 still acquired coding proficiency from that noisy data [1] - which is not a licence to skip verification. Building textbook data outside code therefore costs more to accept than to generate, which is rarely budgeted at kickoff.

Row two is also skipped. Ordering by concept dependency and building difficulty in steps is a row I added myself (the paper says balanced, not explicitly graded difficulty); if every generated sample sits at one difficulty, the model is more likely learning 'how to answer this class of question' than 'how to decompose this kind of problem'. Only the second transfers.

Acceptance: watch transfer, not a single score

  • 1. Prepare three test sets, not one: a synthetic-distribution set (same format and source as the generated data), a real in-domain set (production logs for the target task, unrewritten, typos intact), and a real cross-domain set (same capability but a different input shape or business domain). Report all three; missing one lets you mistake format alignment for a capability gain.
  • 2. Read them in a fixed order: real in-domain first, then real cross-domain, then synthetic-distribution last. If only the synthetic set improves and neither real set does, what you trained is format alignment rather than capability. That is not a failure, but you need to know what you bought.
  • 3. Run a paraphrase perturbation: rewrite the real in-domain questions in different words, add common typos and stale phrasing, and see how far the score falls. The paper itself reports phi-1 is sensitive to stylistic variation and grammatical errors in the prompt [1], so this is not an optional extra.
  • 4. Test one unrelated task to see whether it was damaged in passing: synthetic data tends to homogenise output style, an asset on the target task and a regression elsewhere.
  • 5. If you do recursive generation (a model trained on synthetic data generating more synthetic data), watch both real test sets and output diversity, not just the score inside the synthetic distribution. There is no universal threshold for when to stop; measure it with your own real sets instead of copying any 'stop after N rounds' rule.

Step three carries the most information per unit of cost: a small paraphrase sample separates 'the model learned the task' from 'the model memorised the template', and those two behave very differently after launch. How many items to draw and how much time to spend depend on your own log volume; I give no universal figure here. This step blocks most work that looks impressive but does not improve real inputs.

Why it may not transfer

  • 1. The paper chose Python code: this domain at least offers compilation and tests to decide part of the answers automatically, so bad samples surface relatively easily. In contracts, medicine, or support, no such automatic verifier exists and errors enter silently; the paper itself says GPT-3.5-generated data has a high error rate, yet phi-1 still acquired coding proficiency from that noisy data [1].
  • 2. The gain has to be split by stage, not waved away as 'only form': the synthetic textbooks went into from-scratch pretraining and did write coding ability into the weights (phi-1-base already reaches about 29% HumanEval [1]); the exercise fine-tuning is closer to aligning existing ability to the task shape (the paper's words are 'reorganizing and consolidating the knowledge acquired during pretraining' [1]). So 'useless when the knowledge was never in the weights' does not hold - phi-1's weights started randomly initialised. The real question is whether your model lacks knowledge or alignment, and only separated tests can tell.
  • 3. The filtering step depends on judgement: the paper has GPT-4 label about 100k samples for educational value and trains a random-forest classifier to filter them [1], which is more than 'picking nice-looking snippets'. Most teams reproduce only the rewriting and skip the filter, so they rewrite junk into attractive junk.
  • 4. Freedom to choose the task. The paper picked function completion from a docstring, where inputs and outputs are unambiguous. If your task cannot even settle what counts as a correct answer, the textbook genre will not help and defining the metric is the better spend.

None of this refutes the method; it draws its applicability region: some verification is possible, task boundaries are clear, and you can tell whether the model lacks knowledge or alignment. But there is no universal threshold of 'meet N of these and it is worth a trial' - these are items to check one by one, not a scorecard. Copying a count usually ends with a gain on the internal test set and none on real inputs.

Limits, and one sentence you can use today

The second limit is an underestimated cost structure: generation is cheap and verification expensive, which is structural rather than a matter of one unit price. Roughly, verification cost is about item count times per-item review cost, generation cost about item count times per-item generation cost, so the ratio is set by the per-item costs and does not shrink as the sample grows - do not expect 'generate more' to amortise verification. Substitute your own labour costs for the unit prices, counts and multiples; I will not quote them for you. Skip that spend and you are training on an unverified dataset, and the training loss will never tell you an answer was wrong.

The third limit is a side effect of the genre. Textbook prose sounds certain about everything, which is a liability wherever the product must express uncertainty, decline to answer, or say it depends. If you handle complaints or medical questions, that matters more than a few points.

One thing to do now: draw a batch of real inputs from production logs, feed them to the current model unchanged, and have a human mark each one right or wrong. That number is your baseline. Any synthetic data plan has to improve that number, otherwise it improved a different one. How many items and how much time depend on your own log volume; this step blocks most work that looks impressive yet does not improve real inputs.

References

  1. Textbooks Are All You Need

Read next

All articles

Sign in to Padda

A code in your inbox. No password to remember.

Connecting to sign-in…