LESSON 12 · UNDERSTANDING LLMs

Instruction Tuning

Instruction tuning teaches a pre-trained language model to respond usefully to natural-language instructions. Instead of only learning to continue text, the model learns patterns such as answering questions, summarizing, extracting information, and following requested formats.

25 min readBeginnerGenerative AI

By the end of this lesson, you will be able to:

  • Explain why instruction tuning is added after broad pre-training.
  • Read an instruction–response training example and identify its teaching signal.
  • Understand how many task types can be combined into one instruction-tuning dataset.
  • Distinguish instruction tuning from prompting, pre-training, and fine-tuning.
  • Run a small Python experiment that demonstrates instruction-following behavior.
1

Instruction tuning in one picture

Pre-training gives a model broad language knowledge and the ability to predict tokens. Instruction tuning then uses curated examples that show an instruction, useful context when needed, and a desired response.

1Pre-trained modellearned broad language patterns from large-scale text
2Instruction examplesshow requests and high-quality responses
3Train on examplesadjust the model toward useful instruction-following behavior
4Evaluatetest new instructions and response quality
Simple idea: pre-training teaches the model about language; instruction tuning teaches it how to use those capabilities when a person asks it to do something.
2

Before and after instruction tuning

A base language model is trained to predict what text is likely to come next. That objective does not automatically mean it will behave like a helpful assistant. Instruction examples add a clearer target: understand the request and produce an appropriate answer.

BASE MODEL BEHAVIORPrompt: “Explain photosynthesis in two sentences.”

It may continue the text in a statistically plausible way, but it is not specifically optimized to satisfy the user's instruction.

INSTRUCTION-TUNED BEHAVIORPrompt: “Explain photosynthesis in two sentences.”

It is trained on examples where instructions are followed, making concise answers, explanations, summaries, and other requested behaviors more reliable.

Key point: instruction tuning does not replace pre-training. It builds on the capabilities that pre-training already created.

3

Step 1: build instruction–response examples

Each example should make the intended task and desired response clear. A dataset can contain many different tasks as long as the responses consistently demonstrate useful instruction following.

EXAMPLE A · CLEAR TEACHING SIGNALInstruction: Summarize this paragraph in one sentence.

Response: “The system reduces support time by routing common requests to the right team automatically.”

EXAMPLE B · WEAK TEACHING SIGNALInstruction: Summarize this paragraph in one sentence.

Response: “There are many things to say about this topic.”

Dataset rule: the response should demonstrate the behavior you want the model to learn. If examples are vague, inconsistent, or low quality, the model receives a weak teaching signal.
4

Step 2: teach many kinds of instructions

Instruction tuning datasets often combine several task families. This helps a model learn a general pattern: read the request, infer the requested operation, and produce the expected kind of response.

Question answeringAnswer a factual or conceptual question clearly.
SummarizationCompress provided information while preserving important meaning.
TransformationRewrite, translate, classify, extract, or format supplied content.
Reasoning tasksWork through a problem and provide an appropriate result or explanation.
Code tasksGenerate, explain, or modify code according to the request.
Structured outputReturn information in a requested schema or predictable format.

Why variety matters: a single instruction pattern is not enough to create a broadly useful assistant. The dataset should cover the behaviors the model is expected to handle.

5

Step 3: represent the conversation

A common instruction-tuning example can be represented as messages with roles. The model sees the user's request and a target assistant response, then training encourages the model to produce the demonstrated response.

</> Python
instruction_example = {
    "messages": [
        {"role": "user", "content": "Summarize: The team reduced response time by 30%."},
        {"role": "assistant", "content": "The team reduced response time by 30%."}
    ]
}

print(instruction_example)

The exact data format varies by training system. The important idea is the teaching pair: instruction → high-quality response.

6

Step 4: train on the target responses

During supervised instruction tuning, the model processes the example and learns to assign higher probability to the target response tokens. The optimization process still uses loss, gradients, and parameter updates, but the dataset now focuses on instruction-following examples.

Instructionread the request
Predictionmodel predicts response tokens
Losscompare prediction with target
Updateadjust parameters
Connection to Lesson 9: the optimization mechanics are familiar. What changes is the training signal: instead of broad next-token training data, the examples are selected to demonstrate instruction-following behavior.
7

Step 5: evaluate instruction following

A model can memorize the style of training examples without becoming genuinely useful. Evaluation should include instructions that were not present in training and should vary wording, difficulty, and task type.

Instruction complianceDid the response actually perform the requested task?
QualityIs the response accurate, relevant, clear, and useful?
FormatDid it follow requested length, structure, or schema?
RobustnessDoes the behavior survive new wording and unfamiliar examples?

Practical check: hold out evaluation prompts and include realistic variations rather than testing only examples that look like the training set.

8

Instruction tuning vs other techniques

Pre-trainingBuilds broad language capabilities from very large datasets.
Instruction tuningUses curated instruction–response examples to improve general instruction following.
Fine-tuningA broader term for further training a pre-trained model on focused examples, including task or domain behavior.
PromptingChanges the request at runtime without changing model parameters.
RAGSupplies retrieved external information at runtime rather than teaching changing knowledge into parameters.
Think of the layers like this:
Pre-training“Learn language.”
Instruction tuning“Learn how to follow requests.”
Task/domain fine-tuning“Become better at this repeated behavior.”
RAG“Use this external knowledge right now.”
Prompting“Follow these instructions for this request.”
9

Run a small instruction-following experiment

You can see the core idea without training a large language model. This Python example creates a tiny instruction dataset and applies the requested operation to make the instruction → response teaching signal concrete.

</> Python
examples = [
    {"instruction": "uppercase", "input": "simple ai", "output": "SIMPLE AI"},
    {"instruction": "uppercase", "input": "learn llms", "output": "LEARN LLMS"},
]

new_input = "build with ai"
if examples[0]["instruction"] == "uppercase":
    result = new_input.upper()

print(result)
Expected outputBUILD WITH AIThe example is deliberately simple. A real instruction-tuned language model learns this kind of behavior through neural-network training rather than an explicit if statement.

Change it: add examples for another instruction and make the target responses demonstrate the new behavior.

PRACTICE

Test your understanding

1Why isn't pre-training alone enough to create a helpful assistant?Pre-training teaches broad language patterns and next-token prediction. Instruction tuning adds curated examples that demonstrate how to follow requests and produce useful responses.
2What makes an instruction-tuning example useful?The instruction should be clear and the target response should demonstrate the behavior, quality, and format you want the model to learn.
3Do you need instruction tuning when you only need today's private company policy?Usually not for the knowledge itself. Retrieval/RAG is often a better fit for changing external information; instruction tuning is about learned behavior.
QUICK QUIZ

What is the main purpose of instruction tuning?

30-SECOND RECAP

Remember these five ideas

  • Pre-training creates broad language capabilities; instruction tuning builds instruction-following behavior on top of them.
  • The core teaching signal is an instruction paired with a high-quality target response.
  • Good datasets contain varied tasks and consistent examples of useful behavior.
  • Evaluation should test new instructions, not only training-like examples.
  • Prompting, RAG, instruction tuning, and task-specific fine-tuning solve different problems.