Resources/Model training/Training methods

Method

Supervised fine-tuning (SFT)

Supervised fine-tuning teaches a model by example: it is shown a conversation and the reply you want, and its weights are nudged so that reply becomes more likely, token by token.

Chapter 75 min read5 references

What it is

Supervised fine-tuning is the most direct way to change how a model behaves: you give it examples of the conversations you want and train it to reproduce the replies. “Supervised” means every example comes with the answer attached. The model is not asked to judge or explore; it is told, for each context, what the right next words are.

A pre-trained model has already learned language and a great deal about the world from public text. What it has not seen is your product, your team's tone or the format your users expect. SFT closes that gap with a comparatively tiny dataset: hundreds to a few thousand good conversations, not the trillions of tokens used in pre-training. The LIMA study made the point sharply: a 65B-parameter model fine-tuned on only 1,000 carefully curated examples behaved like a capable assistant, which its authors read as evidence that almost all knowledge is learned in pre-training, and fine-tuning mostly teaches the format for using it.

How it works

Each training record is a conversation. The assistant replies you marked as trainable are the targets; everything before a target is its context.

One supervised record (chat format)
{"messages": [
  {"role": "system",    "content": "You are Scalata's support assistant."},
  {"role": "user",      "content": "How do I reset my password?"},
  {"role": "assistant", "content": "Open Settings → Security and choose Reset password. You'll get an email link valid for 30 minutes."}
]}

The model reads the record as one long sequence of tokens. At every position inside the target it predicts a probability for every token in its vocabulary, and the trainer checks how much probability it gave to the token that actually comes next. The penalty for one token is −ln p, the negative natural log of that probability. Averaged over the reply, that is the cross-entropy loss.

Cross-entropy, in one line
loss for one reply = average over its target tokens of  −ln p(correct next token | everything before it)

p = 0.90  →  0.11
p = 0.50  →  0.69
p = 0.05  →  3.00

Only target tokens are scored. The system message and the user's words are read, because they shape the prediction, but they are never graded. This is loss masking: the model learns to answer like your team, not to imitate your users.

systemYou are Scalata's support assistant.read · masked
userHow do I reset my password?read · masked
assistantOpen Settings → Security and choose Reset password.scored · loss counted
The model reads every token, but its error is only measured on the target reply. The context shapes the prediction; it is never itself graded.
Context (read, not scored): “How do I reset my password?”
Openp 0.20 · 1.61␣Settingsp 0.85 · 0.16␣→p 0.62 · 0.48␣Securityp 0.90 · 0.11
sum of penalties 2.364 target tokensloss ≈ 0.59
Supervised loss, one target token at a time. Each token's penalty is −ln p, where p is the probability the model gave the right token. A confident, correct guess costs almost nothing; a surprise costs a lot. The reply's loss is the average.

After each batch, back-propagation works out how every trainable weight should change to make the target tokens more likely, and the optimizer takes a small step in that direction. The learning rate sets the step size. One pass over all records is an epoch.

Scoring one reply, token by token
  1. The target reply begins “Open Settings → Security”. Suppose the model gives those four tokens probabilities of 0.20, 0.85, 0.62 and 0.90.
  2. The penalties are −ln 0.20 = 1.61, −ln 0.85 = 0.16, −ln 0.62 = 0.48 and −ln 0.90 = 0.11.
  3. Their sum is 2.36; the average over four tokens is about 0.59. Most of the penalty comes from the first word: the model did not expect the reply to start with “Open”.
  4. The update raises all four probabilities, and the surprising one the most, because the push on each token grows with how far its probability is from 1. After a few epochs on similar replies the average might fall to around 0.2.

What SFT is good at, and what it is not

GoalSFT?Why
A consistent tone and voiceYesEvery reply in the data demonstrates it.
A fixed output format (sections, JSON, length)YesFormat is easy to show and easy to score token by token.
Domain phrasing and product vocabularyYesThe model picks up the words your team uses.
Facts that change often (prices, stock, policies)RarelyTrained facts go stale; looking them up at answer time is safer.
“Better than” judgements with no single right answerPartlyPreference tuning expresses comparisons directly.
Tasks with a checkable result (a calculation, code that passes tests)PartlyReinforcement fine-tuning can reward correct outcomes rather than one fixed wording.

One property explains most SFT surprises: it imitates. If one reply in ten says “please contact support” instead of answering, the model learns to say that about one time in ten. If replies contradict each other, the model learns a blur of both. Clean, consistent targets matter more than more targets.

How to tune it

Most supervised runs need little tuning. Start from the provider's defaults (“Auto”), read the curves, then change one thing at a time.

EpochsTypical 1–3, or Auto#

How many times the model sees every training record. Too few and the replies barely change; too many and training loss keeps falling while validation loss turns upward, because the model is memorising your examples. Small datasets usually tolerate more epochs than large ones.

Learning rate multiplierTypical Provider default (×0.5–2)#

Hosted models expose a multiplier on the provider's own default learning rate rather than the raw value. Above 1 learns faster but can overshoot or erode general skills; below 1 is gentler and slower. Lower it if validation loss is noisy or rises early.

  • Both losses falling: still learning; another epoch may help.
  • Training falls, validation flattens: about right; stop here.
  • Training falls, validation rises: overfitting; use fewer epochs, a lower multiplier or more varied data.
  • Neither moves much: the data may be inconsistent, or the learning rate too low.

Common mistakes

  • Training on replies you would not want repeated. Weak, outdated or inconsistent replies are learned as faithfully as good ones.
  • Running many epochs on a small dataset and trusting the falling training loss. Watch the validation loss.
  • Using SFT to store facts that change. When the fact changes, the model keeps repeating the old one.
  • Judging the run by loss alone. A lower loss means closer imitation of your replies, not necessarily better answers: run an evaluation.
  • Leaving no validation split, so there is nothing to detect overfitting with.

References and further reading

External sources open in a new tab.

  1. 01SFT TrainerHugging Face TRL docs · huggingface.coWrites out the token-level cross-entropy loss and shows how training on completions only works.
  2. 02Supervised fine-tuningOpenAI API docs · developers.openai.comA hosted provider's walk-through: data format, hyperparameters and evaluating the result.
  3. 03LIMA: Less Is More for AlignmentZhou et al., 2023 · arXiv · arxiv.org1,000 curated examples were enough to fine-tune a 65B model into a strong assistant.
  4. 04Training language models to follow instructions with human feedbackOuyang et al., 2022 · arXiv · arxiv.orgInstructGPT: the paper that made supervised fine-tuning the first step of modern post-training.
  5. 05Finetuned Language Models Are Zero-Shot LearnersWei et al., 2021 · arXiv · arxiv.orgEarly evidence that fine-tuning on instructions helps a model follow instructions it never saw.

Turn weeks of expert work into minutes

See how Scalata fits your team, your data, and your controls.