Free self-study · No account needed · Progress stays in this browser. Back it up before clearing site data or changing devices.

← Week 4: Training, Alignment, and Inference

Week 04 / Lesson 2

Instruction tuning, preferences, and distillation

Distinguish training objectives by the examples and feedback they use.

Section 2.1 1 of 8

Overview

Focus

Distinguish training objectives by the examples and feedback they use.

Your route through the lesson

  • 2.2 Supervised instruction examples
  • 2.3 Reinforcement learning from human feedback
  • 2.4 Direct preference optimization
  • 2.5 Distillation from a teacher model
  • 2.6 Put it into practice
  • 2.7 Guided comparison
  • 2.8 Choosing a training stage for a task

All required teaching is included here. Review selections are saved. Choose a correct answer for every question to continue; retries are unlimited. Study time and personal notes are optional.

Section 2.2 2 of 8

Supervised instruction examples

Focus

Distinguish broad predictive training from supervised instruction examples.

A pretraining text record might be a paragraph used to predict its next tokens. A supervised instruction-tuning record instead specifies an input request and a desired response. Both can use token prediction as a numerical objective, but the data organization and targeted behavior differ.

For example, instruction “Return the city from: delivery to Oslo” has desired response “Oslo.” Train on many such pairs and evaluate on reserved underlying examples. The target response guides desired behavior; it is not evidence that every supplied answer is true. Incorrect or inconsistent targets can train incorrect or inconsistent behavior.

Data formatting matters. A chat template marks roles and boundaries so training and inference agree about where the assistant response begins. When only response tokens should contribute to instruction loss, mask other positions out of the loss deliberately; a causal attention mask controls visibility and is a different mechanism. Preserve provenance, rights, and split boundaries before tuning.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. Which record directly represents supervised instruction tuning?
2. A desired training response contains a wrong city. What does its presence as a target establish?
3. What differs between a loss mask and a causal attention mask?

Section 2.3 3 of 8

Reinforcement learning from human feedback

Focus

Trace human preferences through a reward model and a policy update.

Reinforcement learning from human feedback can begin with people comparing candidate responses to the same request. A preference pair indicates which response a reviewer favors. A reward model can learn to score responses from these comparisons, and a policy optimization stage then uses that learned reward to influence generated responses.

For a refund question, one candidate may invent a policy and another may cite the actual supplied policy. A reviewer can prefer the supported response. The comparison is evidence of a preference under the review criteria, not a universal proof of factuality. Reviewers can disagree, and a reward model can favor superficial style rather than the intended quality.

The generated-response policy changes during optimization; simply sorting two saved answers by a hand-written score is not the same as training model parameters this way. A complete engineering claim must distinguish comparison collection, reward-model fitting, policy updates, and independent evaluation. Stronger reward scores alone do not establish safer or more correct behavior.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. What does a human preference pair ordinarily contain?
2. A reward model assigns a higher score to a verbose unsupported response. What risk is illustrated?
3. A script ranks two fixed responses using a rule. Has it demonstrated reinforcement training of policy weights?

Section 2.4 4 of 8

Direct preference optimization

Focus

Explain preference optimization that uses response pairs without a separate reward-model stage.

Direct preference optimization uses preferred and rejected responses to shape a policy relative to a reference policy. Its training objective changes relative response likelihoods using the comparison data. Unlike the reward-model-plus-policy sequence just described, this formulation can optimize from preference pairs without first training a separate explicit reward model.

Take one request with preferred response P and rejected response R. The signal is a relative judgment under that request; it is not two independent factual labels. The reference model supplies a stable comparison point in the formulation. Training data quality still matters: preferring a fluent fabrication teaches the wrong behavior regardless of the optimizer name.

Do not confuse preference fitting with retrieving updated facts at request time. If a policy changes weekly, keep authoritative facts in a maintained source and test whether responses use it. Preference training can influence style or choices, but a preference dataset does not automatically make embedded knowledge current.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. What distinguishes direct preference optimization in this comparison?
2. A preferred response is factually wrong. What protects against learning that mistake?
3. An application’s policy facts change every week. Which architecture preserves freshness more directly?

Section 2.5 5 of 8

Distillation from a teacher model

Focus

Describe how a student model learns from a teacher’s outputs.

Distillation trains a student to imitate information supplied by a teacher model. The teacher may provide generated target responses or probability distributions. The student may be smaller, but the defining relationship is the learning signal from the teacher rather than an identical architecture or copied parameter file.

For two possible tokens, a teacher might assign probabilities [0.8,0.2]. A student initially assigns [0.5,0.5]. Matching the full distribution communicates more than a single hard label naming only the first token: it also conveys the teacher's relative uncertainty. A loss can encourage the student distribution toward the teacher's distribution. The teacher can remain frozen while the student is updated.

Distillation transfers both useful patterns and errors. A smaller student should be evaluated on real task requirements, latency, memory, and failure cases. A reduced file size does not prove retained quality, and matching teacher outputs does not prove that the teacher was right. Source provenance and data rights still apply to the collected training examples.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. A smaller model learns from a frozen teacher’s response probabilities. What is this relationship?
2. What additional information does [0.8,0.2] provide over a hard label for the first token?
3. A distilled student is smaller than its teacher. What still needs measurement?

Section 2.6 6 of 8

Put it into practice

Focus

Classify complete training records by the signal they supply.

Download week04.py and run python week04.py --lesson 2. The exercise records represent four distinct signals: raw next-token text, input-response targets, preferred/rejected response pairs, and teacher distributions. A dictionary makes the fields explicit so the signal can be identified without guessing from an application name.

For each record, inspect what the learner would compare against. Raw text supplies an observed next token. A response pair supplies a desired response under a request. A preference record supplies a relative ranking; the training architecture determines whether it feeds a reward model or a direct preference objective. A teacher distribution supplies soft imitation targets.

The script checks these classifications and calculates a small probability-matching loss for a teacher/student example. These are objective calculations about the formulations, not a claim to have executed every large-scale alignment method. Use the review to distinguish data signal from factual correctness and from the implementation depth of the demonstration.

Download this week’s Python lab ↓

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. A record contains prompt, preferred_response, and rejected_response. What signal is present?
2. A record has teacher_probabilities=[0.8,0.2]. Which learner comparison fits?
3. A lab classifies training records correctly. What should be claimed?

Section 2.7 7 of 8

Guided comparison

Focus

Compare what changes in pretraining, instruction tuning, preference training, and distillation.

Pretraining updates a model to predict observed corpus continuations. Instruction tuning updates it using desired responses to requests. Preference optimization updates relative behavior using comparison judgments, with or without a separate reward-model stage depending on the method. Distillation updates a student from a teacher's supplied outputs or probabilities.

These methods can share token-level arithmetic while differing in data construction and the behavior being encouraged. A raw paragraph does not become a preference pair because an engineer labels the file “preferences.” A pair of chosen and rejected answers does not establish that a separate reward model has been fitted. Examine actual fields and update steps.

The probability calculation in the lab illustrates a soft target. With teacher [0.8,0.2] and student [0.5,0.5], cross-entropy is −0.8×ln(0.5)−0.2×ln(0.5)=about 0.693. Matching the teacher gives about 0.500. The loss includes the teacher's uncertainty rather than forcing probability one on the favored token.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. A file named preferences contains only raw paragraphs and no comparison judgments. What signal actually exists?
2. Teacher probabilities are [0.8,0.2] and student probabilities [0.5,0.5]. What is their soft-target cross-entropy approximately?
3. Which statement distinguishes distillation from direct preference training?

Section 2.8 8 of 8

Choosing a training stage for a task

Focus

Choose a training intervention from a specific failure rather than a method name.

A support model uses inconsistent response formatting despite having the needed facts. Curated instruction-response examples may teach a stable format. Another model gives plausible but outdated policy details; adding more style preferences alone does not supply the current policy. A maintained retrieval source addresses that missing information more directly.

If a capable but expensive teacher already performs a narrow classification task well, a smaller student can be trained on teacher-derived targets and evaluated against actual task labels. If reviewers can reliably compare two acceptable responses but struggle to write an ideal answer, preference data may be useful. Each choice still needs source quality, a baseline, and reserved evaluation.

Specify the desired change first: format adherence, factual freshness, latency, or a preference-sensitive behavior. Then state what examples or measurements support it. Changing method names is not an experiment unless the changed training or application procedure is actually executed and compared.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. An assistant has current facts but inconsistent required output formatting. Which training data directly demonstrates the desired behavior?
2. A model returns outdated policy facts. What directly supplies current information?
3. A smaller student is proposed to reduce latency. What should the experiment compare?

Your personal notes

Optional, ungraded, and saved only in this browser. Export a backup from the Academy homepage to keep them.

References and further reading
Ask your own AI assistant

Copy this prompt into an assistant you already use. Nothing is sent automatically, and your personal notes are not included.

Next lesson: Inference, sampling, and computation →