GO TO A SECTION

↑ ↓ to navigate · Enter to openExplore all sections →
FDEInterviews logo
arXiv preprint

Textbooks Are All You Need

A 1.3B-parameter code model trained on 7B tokens of filtered and GPT-3.5-written 'textbook' data scored 50.6% on HumanEval, beating models ten times larger. Its own pruning table shows where.

Breakdown by FDE Interviews · 10 min read · Updated

About the original · 2023
AUTHORS
Gunasekar, Zhang, Aneja, Mendes et al.
FROM
Microsoft Research
PUBLISHED
Jun 2023 · arXiv preprint
CITED BY
694Semantic Scholar · Nov 2026
IN THIS BREAKDOWN · 10 SECTIONS

You can read 24% of this breakdown.

01

The paper in one minute

Following TinyStories, the same Microsoft group asked whether data quality can stand in for model size on a real task: writing Python functions from docstrings. They argue that public code datasets teach badly. Many files depend on other files, many are boilerplate, and the real logic is buried in long, undocumented functions.

So they built three datasets. Filtered code: from about 35 billion tokens of Python in The Stack and Stack Overflow, GPT-4 rated about 100,000 samples for "educational value for a student learning basic coding concepts", and a random forest on a code model's embeddings learned to predict that rating for the rest, keeping about 6B tokens. Synthetic textbooks: under 1B tokens of Python textbook text written by GPT-3.5, with topics and audiences varied to avoid repetition. CodeExercises: about 180M tokens of GPT-3.5-written function docstrings with solutions, varied by constraining function names.

phi-1-base, a 1.3B-parameter transformer, was trained on the first two (together called CodeTextbook) for about 8 passes, roughly 50B tokens, in under 4 days on 8 A100 GPUs. It scored 29% on HumanEval. Fine-tuning on CodeExercises for 7 hours produced phi-1, at 50.6% on HumanEval and 55.5% on MBPP. A 350M-parameter version reached 45%. The authors also show qualitatively that fine-tuning improved tasks absent from the exercises, such as using Pygame and Tkinter.

Because exercises written by GPT-3.5 could resemble HumanEval, Section 5 checks contamination. Few 13-gram overlaps were found. A stronger check splits HumanEval into problems with and without close matches in the exercises (by embedding and syntax-tree similarity), retrains phi-1 after pruning up to 40% of the exercises, and compares with StarCoder on each subset.

THE IDEA, VISUALLY
THE DATA (SECTION 2) web Python, 35B The Stack + Stack Overflow filtered, ~6B GPT-4 labels -> forest textbooks, <1B written by GPT-3.5 phi-1-base 1.3B, ~50B tokens: 29% exercises, ~180M docstring + solution phi-1 HumanEval 50.6% The exercises use HumanEval's own format: a function signature and a docstring to complete. The filter's showcase 'high educational value' code computes x-squared where y-squared belongs; it is right only when both inputs are the same (our test). HUMANEVAL SPLIT BY SIMILARITY TO EXERCISES (T. 3) tau = 0.95; % of problems solved 71 problems with a close match phi-1 81.7% StarCoder 57.7% 93 problems with no close match phi-1 26.9% StarCoder 29.0% Totals: phi-1 50.6%, StarCoder 41.5%. The lead lives on problems resembling the fine-tuning exercises; on the rest phi-1 trails at tau 0.95, 0.85 and 0.8, within overlapping intervals (our recomputation). Retrained after pruning similar exercises: 45-51%. arXiv 2306.11644, Microsoft Research
Left: phi-1's data, about 6B tokens of web code filtered by a GPT-4-labeled quality classifier, under 1B tokens of GPT-3.5-written Python textbooks, and about 180M tokens of GPT-3.5-written exercises for fine-tuning. Right: Table 3 splits HumanEval's 164 problems by whether each has a close match in those exercises. At the strictest similarity threshold, phi-1 solves 81.7% of the 71 matched problems against StarCoder's 57.7%, but 26.9% of the 93 unmatched ones against StarCoder's 29.0%; the overall lead comes from the matched problems.
Research notes: the problem, approach and results
50.6%

phi-1 pass@1 on HumanEval at 1.3B parameters; phi-1-base before exercises 29% (Table 1, Section 2)

26.9% vs 29.0%

phi-1 vs StarCoder on the 93 HumanEval problems with no close match in the exercises (Table 3, tau 0.95)

7B

unique training tokens, seen about 7 times (50B total) for phi-1-base (Section 2.3)

THE PROBLEM

Code models grew by scaling parameters and tokens, trained on large dumps of public code that are often not self-contained, trivial, or poorly explained. Can better data substitute for scale?

THE IDEA

Train a small model on 'textbook quality' data: web code filtered by a classifier trained on GPT-4 judgments of educational value, plus Python textbooks and exercises written by GPT-3.5 with randomized topics to keep them varied. Pretrain on the first two, fine-tune on the exercises.

THE RESULT

phi-1 (1.3B parameters, about 50B training tokens, 4 days on 8 A100s) reached 50.6% pass@1 on HumanEval and 55.5% on MBPP, ahead of much larger open models except WizardCoder on HumanEval. Fine-tuning on exercises also improved tasks not in the exercises.

02

Why it matters to an FDE

Small specialized models can be trained well on curated data. For a customer that needs a narrow capability cheaply, private or on small hardware, filtering existing data with a model-trained classifier and adding synthetic examples is a realistic recipe.

Fine-tuning data should match the task, and then you must test beyond it. CodeExercises were written in HumanEval's format, function plus docstring. That is good practice for a target task and a warning for evaluation: the benchmark lead concentrated on problems similar to the exercises.

Split the test set by similarity to training data. The paper's Table 3 is the method to copy. For each test item, find whether training data contains something close; report performance on matched and unmatched items separately. A model that only wins on matched items has learned the distribution, which may be fine, but the claim should say so.

Read the quality filter's examples. The code the paper shows as "high educational value" has a bug that our test exposes. A model-labeled filter scores what code looks like, not whether it works. When building a filter for a customer, sample what it keeps and execute or review it.

Expect brittleness outside the training style. The authors note phi-1 degrades with grammatical mistakes in prompts and lacks knowledge of less common packages.

THE FULL BREAKDOWN

Understand the mechanism. Try it on a real problem.

Unlock this breakdown and 290 more papers.

Premium opens every paper in full, plus every answer, concept, course and guide on the site. One payment for six months of access.

6 months · One payment · No auto-renewal

Get Premium · ₹2,000 / $25
  • ◇1 architecture diagram
  • </>1 runnable code experiment
  • ▦2 results tables
  • ?5 interview questions with answers
  1. 03Key takeaways

    The three datasets, results, the fine-tuning effect, contamination checks, limits

    Free account
  2. 04How it works

    Building each dataset, the architecture, training settings, and the pruning analysis

    Premium
  3. 05The numbers that matter

    Table 1 comparisons, the data ablations, unconventional problems, and Table 3 by threshold

    Premium
  4. 06Try it yourself

    Recompute Table 3 by subset, rerun the 'high educational value' example, and check token counts

    Premium
  5. 07Where it breaks

    Fine-tuning data shaped like the benchmark, model-labeled quality, withheld details, narrow scope

    Premium
  6. 08Using it on a deployment

    When a small curated model fits, building the filter and synthetic sets, and evaluating it fairly

    Premium
  7. 09Interview angles

    Five questions this paper prepares you for, with answer hints

    Premium
Back to the paper library →