Exercises — Instruction tuning
Everything here builds on Instruction tuning (the parent), and touches Cross-Entropy Loss, Supervised Fine-Tuning (SFT), Pretraining Objective (Next-token prediction), RLHF and DPO, FLAN and Zero-shot Generalization, Self-Instruct and Alpaca, and Prompt Templates and Chat Formats.
Before we start, one symbol reminder so nothing appears unearned:
Level 1 — Recognition
L1.1
Which of the following is instruction-tuning data?
(a) 40 GB of raw scraped web pages.
(b) Pairs like (instruction: "Translate to French: Hello", response: "Bonjour").
(c) Rankings saying "answer A is better than answer B".
Recall Solution
Answer: (b).
- (a) is pretraining data — raw text, no task structure.
- (c) is preference data used by RLHF and DPO.
- (b) is
(instruction, desired response), exactly the format instruction tuning consumes.
L1.2
True or False: Instruction tuning computes its loss over every token in the sequence, prompt included.
Recall Solution
False. The loss is computed only over response tokens (the ones with ). The prompt is masked out because the user supplies it — we never need the model to generate it.
L1.3
Order the pipeline: RLHF, Pretraining, Instruction tuning.
Recall Solution
Pretraining → Instruction tuning → RLHF. First learn language + world facts, then learn to follow instructions, then refine preferences/tone/safety.
Level 2 — Application
L2.1
A training sequence is:
### Instruction: Add 2 and 3 ### Response: 5
The tokens are (one token each for simplicity):
["###","Instruction",":","Add","2","and","3","###","Response",":","5"]
Write the mask vector and identify exactly which term appears in the loss.
Recall Solution
There are 11 tokens. Only the final token "5" is the response.
The loss uses only the bright position:
Everything before "5" is context the model reads but is not graded on generating.
L2.2
The response is tokens; the prompt is tokens. The model assigns each response token the same probability . Using the masked, length-normalized loss compute (natural log).
Recall Solution
Only the response tokens count, so . Notice the normalizer is 4, not 24 — the prompt length is irrelevant to the averaged loss because masked terms vanish.
L2.3
Same numbers as L2.2, but a student forgets to mask. The prompt tokens each get probability , the response tokens each get . Compute the unmasked averaged loss over all tokens.
Recall Solution
Compare to the masked value : the unmasked number is dominated by the prompt tokens the model will never need to generate. Its gradient is wasted on echoing the user.
Level 3 — Analysis
L3.1
You train on 500 translation + 500 summarization + 500 QA examples, all wrapped in the same template ### Instruction … ### Response …. At test time you type ### Instruction: Write a haiku about the moon, an instruction type never seen. Explain, mechanistically, why the model switches into "obey and answer" mode.
Recall Solution
The three task families share a common surface structure (the template) even though their content differs. During training the gradient repeatedly rewards the pattern:
"whatever tokens appear right after
### Response:must satisfy the request in the instruction, then stop."
That habit is abstract — it does not depend on the task being translation vs. summarization. At test time the haiku prompt has the same surface structure, so the learned habit fires: the model produces content that satisfies the new instruction. This is the zero-shot generalization result — generalization across instruction types, driven by shared template structure.
L3.2
LIMA showed ~1,000 curated examples beat much larger noisy datasets. Someone concludes: "So instruction tuning barely needs data — bigger is basically useless." Analyze what's right and wrong.
Recall Solution
Right: for behavior tuning, quality + diversity dominate raw count. The skills already live in the pretrained weights; you are steering, not stuffing (from the parent's "80/20"). A few clean, diverse examples can flip behavior. Wrong: "bigger is useless" overgeneralizes. Scale still helps if the added data adds diversity or coverage of new instruction types. What LIMA actually shows is diminishing returns from near-duplicate, low-quality data — not that data is worthless. Ten thousand paraphrases of the same instruction add little; one thousand genuinely different tasks add a lot.
L3.3
A model is instruction-tuned on examples whose responses are frequently wrong but confidently phrased. Predict the trained behavior and name the failure mode.
Recall Solution
Because the loss makes the model imitate the given responses, it learns the style ("state an answer confidently, then stop") independent of correctness. It will produce fluent, assertive answers that are often false — the failure mode is hallucination. Instruction tuning shapes form, and here the form being taught is "sound confident regardless of truth."
Level 4 — Synthesis
L4.1
Design (in words) a minimal but diverse instruction dataset of exactly 6 examples that would teach obey-mode without teaching any single task by rote. State each example's task family and why diversity matters here.
Recall Solution
A defensible design — one example each from 6 distinct families, all in one shared template:
- Translation —
Translate to French: Hello → Bonjour - Summarization —
Summarize in one sentence: <para> → <1 sentence> - Arithmetic/QA —
What is 12 × 7? → 84 - Rewriting —
Make this polite: "give me the file" → "Could you please share the file?" - Classification —
Sentiment of "I loved it": → Positive - Generation —
Write a two-line poem about rain → <2 lines>
Why diversity matters: if all 6 were translation, the model would tie "obey-mode" to the translation content and fail to fire on a haiku. Spreading across families forces the gradient to attribute the shared behavior to the shared template, not the content — which is what enables zero-shot transfer. This is exactly the Self-Instruct philosophy of covering many instruction types cheaply.
L4.2
Write the full masked loss for a batch of 2 examples. Example A: 3 prompt tokens, 2 response tokens with probs . Example B: 5 prompt tokens, 3 response tokens with probs . Use per-example length normalization, then average over the 2 examples (natural log).
Recall Solution
Example A (): Example B (): Batch loss: Note each example is normalized by its own response length first — a long-response example does not silently dominate a short one.
Level 5 — Mastery
L5.1
A base model, on the raw prompt Translate to French: Hello, continues with more English examples instead of answering. After instruction tuning it outputs Bonjour. Using the probability factorization, explain precisely what changed in — and argue whether the French vocabulary was newly learned.
Recall Solution
Recall the autoregressive factorization from the parent: Nothing about this equation changed — the model is still a next-token predictor. What changed is the conditional distribution for the first response token after the instruction.
- Before IT: conditioned on that prompt, the highest-probability next tokens were English continuation tokens (because "list of examples" is a common web pattern from pretraining).
- After IT: the masked cross-entropy repeatedly raised and lowered the English-continuation mass, so the argmax flipped.
Was French vocabulary newly learned? No. The token Bonjour and its association with "Hello"/"French" were already in the weights from multilingual pretraining. Instruction tuning only re-weighted which continuation the prompt should trigger. It changed behavior (what to output), not knowledge (what the model knows). This is the parent's "FORM over FILL."
L5.2
You have a fixed budget of 2,000 examples and a base model that already knows a lot. Rank these three strategies for maximizing zero-shot instruction following, and justify with the mechanisms from every level above: (i) 2,000 near-duplicate high-quality translation examples; (ii) 2,000 diverse, clean examples across ~50 task families; (iii) 2,000 diverse examples where 30% of responses are confidently wrong.
Recall Solution
Ranking: (ii) > (i) > (iii).
- (ii) best. Diversity forces the shared behavior onto the template, not the content (L3.1, L4.1), maximizing zero-shot transfer — the FLAN result. Clean responses teach correct form.
- (i) middle. Clean and high-quality, so it won't teach hallucination, but the model ties obey-mode to translation; it may fail to fire on unseen task types (poor generalization). Quantity without diversity gives diminishing returns (L3.2 / LIMA).
- (iii) worst. Even though it's diverse, imitating confidently-wrong answers teaches the model to hallucinate confidently (L3.3). Bad responses actively teach bad behavior — worse than narrow-but-clean, because the damage transfers to all task types.
The unifying principle: instruction tuning imitates responses, so it copies both the good habit (obey the template) and any bad habit (be confidently wrong). Maximize diversity, guarantee response quality, then hand off to RLHF and DPO to refine preferences on top.
Figures
The masking idea is the geometric heart of these exercises:

And the effect of masking vs. not (L2.2 vs L2.3) as a bar comparison:

Recall
Recall Quick self-check — cover the answers
- L2.2 masked loss with all response probs ? :::
- Why is the normalizer 4 and not 24? ::: masked prompt terms are multiplied by and vanish
- What does IT change in ? ::: the conditional after the prompt — behavior, not the factorization
- Best 2000-example strategy? ::: diverse + clean across many task families
Connections
- Instruction tuning — parent topic these exercises drill.
- Cross-Entropy Loss — the loss every numeric exercise computes.
- Supervised Fine-Tuning (SFT) — IT is a specialized SFT.
- Pretraining Objective (Next-token prediction) — supplies the factorization in L5.1.
- RLHF and DPO — the stage after IT (L1 trap, L5.2).
- FLAN and Zero-shot Generalization — the transfer explained in L3.1/L5.2.
- Self-Instruct and Alpaca — the diversity philosophy of L4.1.
- Prompt Templates and Chat Formats — the shared template that carries the behavior.