← AI Engineering Latent Shelf · Ch.8

Book Study Guide · Chip Huyen · Chapter 8

Dataset Engineering

The best ML team in the world with infinite compute can't finetune a good model if you don't have data. Finetuning is easy; getting data for it is hard.

— the data-centric turn

The goal of dataset engineering is to create a dataset that lets you train the best model within budget. This chapter covers data curation (what data, how much, what quality), data acquisition and annotation, data synthesis (generating data with AI), and data processing — the unglamorous work that decides model quality.

data-centric AIquality · coverage · quantitysynthesisprocessing15 quiz questions
01Data curation

Data-centric AI, and what data each phase needs

As fewer companies train models from scratch, data is where teams differentiate. The shift has a name: data-centric AI (improve performance by improving the data) versus model-centric AI (improve it by improving architectures and training). Curation, generation, and processing don't follow a linear path — you'll loop between them.

Key concept · Data format follows the training phase

What data you need depends on what you're teaching. Self-supervised finetuning (continued pre-training) wants sequences of text. Supervised finetuning wants (instruction, response) pairs. Preference finetuning wants (instruction, winning response, losing response). A reward model uses that comparison format or ((instruction, response), score). Training data must exhibit the behaviors you want the model to learn — and teaching hard behaviors is harder: chain-of-thought data needs step-by-step responses (tedious to write, so CoT datasets are rarer), and tool-use data needs the action sequences an agent should take (often captured by simulation because what's efficient for a human — a browser — differs from what's efficient for a model — an API).

Key concept · Single-turn vs. multi-turn, and unlearning

For conversational apps, decide whether you need single-turn data (train the model to answer individual instructions — simpler, easier to get) or multi-turn data (teach it to accomplish a task over back-and-forth — clarify intent, take corrections; harder, often needs purpose-built scenarios). And curation isn't only about adding data to teach new behaviors — it's also about removing data to make a model unlearn bad ones.

02Quality, coverage, quantity

The three properties of a good dataset

A dataset is judged on three axes, and — a recurring theme — quality usually beats quantity: a small set of high-quality, well-chosen examples often outperforms a large noisy one (studies have finetuned strong instruction models on ~1,000 carefully curated examples).

Key concept · What makes data high-quality

High-quality data tends to be: relevant (to the task you're training for), aligned with your task requirements (e.g. factually correct for a Q&A app, creative for a story app), consistent (annotators would agree on the label; contradictory labels confuse the model), correctly formatted (matching the model's expected structure), sufficiently unique (deduplicated — duplicates waste compute and can bias the model), and compliant (with privacy, copyright, and your policies). Poor data does real damage — it can increase biases and hallucinations — so bad data is worse than less data.

Key concept · Coverage and quantity

Coverage is diversity: the data should span the range of inputs, patterns, and edge cases your model will face in production — a model only learns behaviors present in its data. Quantity — how much you need — has no single answer; it depends on the finetuning method (full finetuning needs far more than PEFT/LoRA), the task complexity, and how good the base model already is. Practical guidance: start with a small high-quality set (finetuning experiments can begin with as few as ~50–100 examples), measure, and add data while it still helps — returns diminish, and beyond a point more data barely moves the needle while quality problems keep hurting.

03Acquisition & annotation

Getting the data — and labeling it well

Data can come from application logs, public and proprietary datasets, purchased data, or fresh annotation. However you source it, the hard part is usually annotation: producing correct, consistent labels for the behavior you want.

Key concept · Why annotation is hard

Good annotation demands a clear annotation guideline — the same document that anchors evaluation (Chapter 4) — defining what a correct response looks like, with examples, so different annotators agree. It gets harder for complex behaviors: writing a single high-quality (instruction, response) pair for InstructGPT could take up to 30 minutes and needed educated labelers; CoT and tool-use examples are harder still. And human demonstrations aren't always ideal for a model — a human might use a browser where a model should call an API — so teams increasingly turn to simulation and synthetic data for behaviors humans can't demonstrate efficiently.

04Data synthesis

Generating data with programs and models

Data synthesis — creating data programmatically or with AI — has become central, because it can be faster and cheaper than human labeling and can reach places human data can't.

Key concept · Why synthesize, and how

Reasons to generate data: boost quantity cheaply, improve coverage of rare or dangerous edge cases, protect privacy (synthetic stand-ins for sensitive records), and distill a stronger model's behavior into a smaller one. Techniques span a spectrum: rule-based generation (templates, procedural generation, and augmentation — paraphrasing, back-translation, perturbations that create variants of existing data), simulation (generate tool-use/agent trajectories in a simulated environment), and AI-powered generation (have a model write instructions and responses — e.g. self-instruct, or generate from a more capable "teacher" model).

Key concept · Distillation — and the limits of synthetic data

Model distillation trains a smaller "student" on a larger "teacher" model's outputs, transferring capability at lower serving cost (though a provider's terms may forbid using its outputs to train competitors — check licensing). But synthetic data has real limits: quality is hard to control, so it needs verification (functional checks, AI or human judges, filtering) before use; it can propagate the generator's biases and errors; and training a model repeatedly on AI-generated data risks model collapse — quality degrades as the model learns from its own (or another model's) outputs rather than real-world signal. The rule: synthesize to augment real data, verify what you generate, and don't let synthetic data crowd out the real thing.

05Data processing

Turning raw data into training data

Once you have data, processing shapes it into something trainable. The steps aren't glamorous, but skipping them is how quality problems sneak into your model.

Key concept · Inspect, deduplicate, clean & filter, format

A practical pipeline: (1) Inspect the data first — understand its distribution, spot obvious errors and surprises before training on it (this always pays off). (2) Deduplicate — remove exact and near-duplicates, which waste compute, skew the distribution, and can leak test data into training. (3) Clean and filter — remove low-quality, malformatted, toxic, or non-compliant examples and PII; you can also filter for quality, keeping only the best examples (often more valuable than adding more). (4) Format — put the data in exactly the structure the model expects, matching its chat template (a mismatch causes the silent failures from Chapter 5). One more knob for instruction finetuning: the prompt loss weight — how much prompt tokens (vs. response tokens) contribute to the loss, commonly ~10%, so the model learns mostly from responses.

★Test yourself

Chapter 8 quiz

Fifteen questions on data curation, quality, synthesis, and processing. Answer first, then expand Show answer.

Part A · Multiple choice

Q1

Data-centric AI improves performance by:

  • A Enhancing the data (better datasets, processing)
  • B Only designing new architectures
  • C Adding GPUs
  • D Raising temperature
Show answer

A. Model-centric AI instead improves the models themselves.

Q2

Supervised finetuning data takes the format:

  • A (instruction, response) pairs
  • B (instruction, winning, losing)
  • C Raw unlabeled text only
  • D ((instruction, response), score)
Show answer

A. Preference data is (instruction, winning, losing); a reward model can use scored data.

Q3

Which is generally true about data?

  • A A small high-quality dataset often beats a large noisy one
  • B More data is always better
  • C Quality doesn't matter
  • D Duplicates help the model
Show answer

A. Poor data can increase biases and hallucinations.

Q4

"Consistent" data means:

  • A Annotators would agree on the labels (no contradictory labels)
  • B All examples are identical
  • C The data is large
  • D It uses one language
Show answer

A. Contradictory labels confuse the model.

Q5

How much data you need depends most on:

  • A The finetuning method, task complexity, and base-model quality
  • B The time of day
  • C The GPU brand
  • D Nothing — it's fixed
Show answer

A. Full finetuning needs far more than PEFT/LoRA.

Q6

A reason to synthesize data is:

  • A To improve coverage of rare/dangerous edge cases (also quantity, privacy, distillation)
  • B To reduce model size
  • C To avoid evaluation
  • D To increase latency
Show answer

A.

Q7

Model distillation trains:

  • A A smaller "student" model on a larger "teacher" model's outputs
  • B A larger model on a smaller one
  • C A retriever on documents
  • D A tokenizer
Show answer

A. Transfers capability at lower serving cost — mind the teacher's licensing.

Q8

"Model collapse" refers to:

  • A Quality degrading when a model is trained repeatedly on AI-generated data
  • B A server crash
  • C Running out of GPUs
  • D A quantization error
Show answer

A. A risk of over-relying on synthetic data.

Part B · True or false

Q9

Chain-of-thought and tool-use datasets are harder to create than plain instruction data.

Show answer

True. Writing step-by-step reasoning or action sequences is tedious, so such datasets are rarer.

Q10

Human demonstrations are always the ideal training data for an AI agent.

Show answer

False. What's efficient for a human (a browser) differs from what's efficient for a model (an API), so simulation is often used.

Q11

Deduplicating training data can prevent test data from leaking into training.

Show answer

True. Duplicates also waste compute and skew the distribution.

Q12

Synthetic data can be used directly without any verification.

Show answer

False. Its quality is hard to control, so verify (functional checks, judges, filtering) before use.

Q13

A mismatch between your data's format and the model's chat template can cause silent failures.

Show answer

True. Formatting to the expected structure is a required processing step.

Part C · Short answer

Q14

Name four characteristics of high-quality data.

Show answer

Any four: relevant, aligned with task requirements, consistent, correctly formatted, sufficiently unique (deduplicated), compliant.

Q15

Give the four steps of a data-processing pipeline.

Show answer

Inspect the data; deduplicate; clean and filter (remove low-quality/toxic/PII, filter for quality); format to the model's expected structure (chat template).