# What Is SFT / Instruction Tuning?

> What supervised fine-tuning is, how one training row teaches a model, how it relates to instruction tuning, and where it stops, explained for your AI interview.

**In short:** SFT (supervised fine-tuning) trains a pretrained model on example inputs paired with the answers we want. Instruction tuning is SFT where those examples are instructions across many tasks.

AI and LLM interview question Q287, Fine-tuning and adaptation. Intermediate, very common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/what-is-supervised-fine-tuning

## Say it in 30 seconds

SFT stands for supervised fine-tuning. We take a model that already reads language well and train it on examples: an input, and the answer we want. Each example teaches it to copy that behaviour, because a loss scores how far its words are from the target. Instruction tuning is the same method, with the examples written as instructions across many tasks. SFT shapes behaviour and format. Facts that change belong in documents the model searches when it answers.

## Say it in 2 minutes

Supervised fine-tuning, or SFT, is more training on a chosen set of examples. Start with a base model that has already learned language from a huge pile of text. Then show it examples: a message on one side, the reply we want on the other. Each time the model guesses a reply, a loss measures the gap to the target words, and training nudges the weights to shrink that gap.

Instruction tuning is the same method, applied to examples written as instructions for many different tasks, such as summarising, classifying or rewriting. That is how a model learns to follow a request and answer it. OpenAI's InstructGPT paper used SFT as its first stage, then trained further on human rankings of the model's outputs.

The limits matter in a real team. SFT copies its examples, so bad examples give bad habits. Tuned weights keep old facts until you train again, so a fee change won't reach the model on its own. And too many passes over a small set make the model memorise it. So I'd write evals first, tune for format and tone, and keep facts in documents the model searches. Then check the tuned model on a test set you kept out of training, and read a sample of its answers yourself.

## What is SFT, in plain words?

SFT means supervised fine-tuning. You take a model that has already learned language from a huge pile of text, then train it a little more on your own examples: an input on one side and the reply you want on the other. Training changes the weights, the numbers inside the model that decide its answers.

Think of a new support agent who reads a stack of past tickets, each with the senior agent's reply beside it. After enough of them, the new agent writes replies in the house style without being told each rule. A tuned model learns the same way, from examples rather than a rulebook.

Picture a freight broker's support desk, a made-up case with realistic numbers. The team has 1,500 approved replies to delay questions, and wants each reply to open with the new date and state the fee rule the same way every time. SFT is how the model learns that pattern.

- **SFT:** Supervised fine-tuning: more training on example inputs and the answers we want.
- **Training row:** One example, usually a request followed by the reply we want.
- **Loss:** A score for how far the model's guess is from the target words. Training tries to lower it.
- **Instruction tuning:** SFT where the examples are instructions for many different tasks.
- **Evals:** A fixed test set of questions with good answers, plus a score, so you can check how a model does.

## How does one training row teach the model?

A training row holds a list of messages: the user's request first, then the reply we want last. OpenAI's guide asks for the chat format, with one complete JSON structure on each line of the file, so one row is one line.

*Diagram, How one training row moves the model: A request goes into the model, and its guess is set against the expert's reply. The gap between them nudges the weights a little, so the next guess is closer. Training repeats this over many batches of rows.*
1. The request goes into the model.
2. The model's guess goes to the scoring step.
3. The expert's reply is the target, and the two are compared word by word.
4. The gap becomes a small nudge to the weights, so the next guess is closer.

The loss has a standard form. Hugging Face's TRL library describes it as the token-level cross-entropy loss. In words, it measures how much probability the model gave to the right next word, and training pushes that probability up.

Not every word has to count. TRL can train on the assistant's messages only, through a setting called assistant_only_loss, and padding, the filler that makes rows the same length, is ignored in the score. Which setting is right depends on your data and your goal, so check it before a run.

Here is the idea in plain Python. It prints which words a loss would count. The prompt words get -100, the value that tells the loss to skip them.

```python
import json

IGNORE = -100  # the loss skips these positions

rows = [
    {"messages": [
        {"role": "user", "content": "Shipment 4471 is two days late. What do I tell the customer?"},
        {"role": "assistant", "content": "Apologise, give the new date, offer a 5% late-fee refund."},
    ]},
    {"messages": [
        {"role": "user", "content": "Why was the truck held at the port?"},
        {"role": "assistant", "content": "Explain the customs hold and give the release time."},
    ]},
]

for row in rows:
    if row["messages"][-1]["role"] != "assistant":
        raise ValueError("each row must end with the reply we want")
    print(json.dumps(row))

def loss_mask(row):
    # Like TRL's opt-in assistant_only_loss: only the assistant's words count.
    return [(word, m["role"] == "assistant")
            for m in row["messages"] for word in m["content"].split()]

for word, counted in loss_mask(rows[0])[:3] + loss_mask(rows[0])[-3:]:
    print(f"{word:<12} {'loss' if counted else IGNORE}")
```

Output:

```text
{"messages": [{"role": "user", "content": "Shipment 4471 is two days late. What do I tell the customer?"}, {"role": "assistant", "content": "Apologise, give the new date, offer a 5% late-fee refund."}]}
{"messages": [{"role": "user", "content": "Why was the truck held at the port?"}, {"role": "assistant", "content": "Explain the customs hold and give the release time."}]}
Shipment     -100
4471         -100
is           -100
5%           loss
late-fee     loss
refund.      loss
```

## How is instruction tuning different from SFT?

- **SFT: The method.** Training on pairs of input and the output we want. The pairs can be about anything.
- **Instruction tuning: A kind of SFT.** The pairs are instructions for many tasks, such as summarise this or classify that.
- **Why it matters: Follows new requests.** The FLAN paper found instruction tuning helps models handle tasks they were not tuned on.

> "Supervised Fine-Tuning (SFT) is the simplest and most commonly used method to adapt a language model to a target dataset." (Hugging Face TRL docs)
>
> "finetuning language models on a collection of tasks described via instructions" (FLAN paper (Wei et al.))
>
> "then memorizes the dataset instead of learning generalizable knowledge" (OpenAI's SFT guide)

So instruction tuning is a particular use of SFT. InstructGPT shows one order for building a chat model: first SFT on demonstrations written by labellers of the desired behaviour, then a second stage that learns from people ranking the model's outputs.

1. **Pretrain on text:** Learn language from a huge pile of text. This step is not SFT.
2. **SFT on demonstrations:** Train on example requests with good answers, so the model follows instructions.
3. **Learn from rankings:** People rank outputs, and reinforcement learning from those rankings trains the model further (called RLHF).

## Where does SFT stop working?

SFT copies its examples, so the examples decide the behaviour. Three limits come up in almost every real project.

- **Bad examples teach bad habits:** Inconsistent replies in the data make an inconsistent model.
- **Frozen facts:** Tuned weights keep what they learned until you train again. A changed fee won't show up on its own.
- **Memorising:** Too many passes over the same small set make the model memorise it, so it stops handling new cases well.

*Diagram, Where a changed fact ends up: A fact baked into the weights stays frozen at training time, so the model can quote an old fee. A fact in a document the model searches at answer time stays current.*
1. The tuned model answers from what it learned in training, so it gives last year's fee.
2. The model reads the current sheet when asked, so it quotes the new fee.

Take the freight team. Suppose it tunes on last year's fee of 5%, and in May the fee drops to 3%. The tuned model keeps saying 5% until someone retrains it. The fix is to fetch the current fee sheet when the question is asked, so the model reads the new number.

> **Tip:** Asked what to do first? Say evals. OpenAI's guide says to set up evals before you invest in fine-tuning, so you can tell whether tuning helped at all.

### How would you start tuning for a freight support desk?

1. **Write the test first:** Collect 200 real delay questions with a good answer each. Score the current model on them so you have a baseline.
2. **Clean the training replies:** Keep only replies the senior agents approved, in one format, with the fee rule written the same way every time.
3. **Run one small tuning job:** Train on the 1,500 approved rows, then check the test score. Stop if it stops improving.
4. **Compare with the base model:** Run the same 200 questions on the base model and the tuned one, and read the answers as well as the score.
5. **Keep facts outside the weights:** Put the fee sheet in a document the model searches. A May change then needs no retraining.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: SFT trains on example inputs and the answers we want.
- [ ] The loss: a score for how far the guess is from the target words.
- [ ] Instruction tuning as SFT on instructions across many tasks.
- [ ] Where it stops: copied bad examples, frozen facts, memorising too many passes.
- [ ] Evals first, then tune for format and behaviour. Keep changing facts in documents.
- [ ] A plan that names the data, the test set and the fallback.

**Common traps**

- Trap: "SFT teaches the model the latest facts." Better: It teaches behaviour and format well. Facts that change belong in documents the model searches.
- Trap: "More passes over the data always make it better." Better: Past a point the model memorises the examples. Watch a test set you kept out of training.
- Trap: "Instruction tuning is a different method from SFT." Better: It is SFT where the examples are instructions across many tasks.

## Can you spot the weak training row?

**Spot the weak row:** A dispatch team tunes a model on these replies. Which row would most likely hurt the tuned model?

A. Why was the truck held? Customs needed a document. We expect release by 14:00 and will call you.
B. Can I change the delivery window? Yes. Tell us the window you want and we confirm it within a working day.
C. Why is my invoice short? Not sure, the system is odd. Ask again later.
D. Where is my refund? Refunds take 5 to 7 working days from approval.

**Answer:** C. The third reply is vague and blames the system. Tuning copies the replies it sees, so one bad habit in the data spreads into many answers. The others give a clear, specific answer, and most add a next step.

**Quick check:** Dispatchers need a chat model that always replies in one short format. What is the best first step?

A. Pretrain a new model on all company email
B. Write evals, then tune on reviewed examples of the format
C. Turn up the randomness setting so replies vary more
D. Copy the whole company archive into every prompt

**Answer:** B. Format is behaviour, so a set of reviewed examples can teach it, and evals show whether it worked. Pretraining from scratch costs far more, and that setting only changes how random replies are.

## Can you answer these from memory?

**Flash cards**

- **What is SFT?** Supervised fine-tuning: more training on example inputs paired with the answers we want.
- **What is one training row?** One example: the user's request first, then the reply we want last.
- **What does the loss do?** Scores how far the guess is from the target words, so training can shrink the gap.
- **Instruction tuning?** SFT where the examples are instructions for many different tasks.
- **Where does SFT stop?** Copied bad examples, frozen facts, and memorising too many passes.
- **What comes first?** Evals: a test set and a score, so you can tell whether tuning helped.

## Likely follow-up questions

- Q281 Fine-tune vs RAG vs prompting: when to use which? https://designervenkat.online/interview/ai/fine-tuning-vs-rag-vs-prompting
- Q284 What is LoRA? https://designervenkat.online/interview/ai/what-is-lora
- Q288 What is RLHF? https://designervenkat.online/interview/ai/what-is-rlhf
- Q294 How do you prepare a fine-tuning dataset? https://designervenkat.online/interview/ai/how-to-prepare-a-fine-tuning-dataset
- Q297 How do you spot overfitting during fine-tuning? https://designervenkat.online/interview/ai/how-do-you-spot-overfitting-during-fine-tuning
- Q016 Pretraining vs fine-tuning vs instruction tuning? https://designervenkat.online/interview/ai/pretraining-vs-fine-tuning-vs-instruction-tuning

## Learn it in depth

- [Fine-tuning](https://designervenkat.online/learn/ai-engineering/fine-tuning)
