4.3.11 · D1Pretraining & Fine-Tuning LLMs

Foundations — Supervised fine-tuning (SFT)

2,167 words10 min readBack to topic

Before you can read the parent note SFT, you need to own every symbol it throws at you. This page builds each one from nothing, in an order where each brick rests on the one before it. Nothing here assumes you've seen probability notation, logs, or the / signs.


0. The picture everything sits on: a token stream

Everything in language modeling starts with one idea: text is chopped into little pieces called tokens (roughly words or word-fragments), and the model reads them left-to-right.

Figure — Supervised fine-tuning (SFT)

We will call the pieces before some position "the past" and the piece we're about to guess "the next token". That splitting is the heart of everything.


1. The vocabulary

The little symbol just means "is a member of" — read as "v is one of the tokens on the shelf".


2. Probability, and why appears everywhere

The model never says "the next token is definitely X". Instead it hands you a confidence for every token on the shelf.

Figure — Supervised fine-tuning (SFT)

The notation (you'll meet in a second) just means: the bar height the model gave to the token that was actually correct.


3. Naming the sequences: , , ,

Now we name the two things every SFT example contains: the question and the ideal answer.

The subscript is just a position counter, like "the 3rd bead". So = "the 3rd answer token".


4. The conditional:

This is the single most important expression in the parent note. Let's disassemble it left to right.

  • — the model itself. (Greek "pi") is just the name we give the machine; (Greek "theta") is the pile of numbers inside it (its weights) that training adjusts.
  • The bar means "given" — read it as "assuming we already know...".
  • So reads:

"The probability the model gives to the answer-token , given the prompt and all earlier answer tokens ."

Figure — Supervised fine-tuning (SFT)

5. The product sign — probability of a whole answer

To score a whole answer, we combine its per-token probabilities. The rule (the "chain rule of probability") says: multiply them.


6. The logarithm — turning multiply into add

Multiplying many numbers below gives absurdly tiny values (a 100-token answer might have probability like with 40 zeros). Computers choke on that. The logarithm rescues us.

One more fact we'll use: for any probability between and , is negative or zero (e.g. , ). Confident-and-correct → close to ; unsure → very negative.


7. The minus sign — from "score to grow" to "loss to shrink"

Optimizers are built to push numbers down. But we want to push probability up. Fix: flip the sign.

This "" is exactly the cross-entropy the parent note keeps referring to. It's the same number pretraining uses; SFT just feeds it curated data.


8. The indicator and the mask

Two look-alike symbols in the parent note that are easy to confuse.

Figure — Supervised fine-tuning (SFT)

9. The averaging symbols: , , and the


How these foundations feed the topic

Tokens on a string

Vocabulary V

Probability p_v over V

Conditional pi(y_t given x and past)

Prompt x and response y

Product over tokens

Log turns product into sum

Minus sign gives cross-entropy loss

Mask m_t keeps only answer tokens

Average over dataset D

SFT loss L


Equipment checklist

What does a token represent, in one picture?
One bead on a left-to-right string of text; the model reads and predicts one bead at a time.
What is the vocabulary ?
The fixed shelf of every token the model knows; the model's next-token choice is always picked from .
What must the numbers satisfy?
Each is between 0 and 1, and across all of they sum to exactly 1.
Read in plain words.
The probability the model (weights ) gives to answer-token , given the prompt and all earlier answer tokens.
What is , and how does it differ from and ?
= the model's internal weights (same across all examples); = the data that changes each example.
What does mean?
All response tokens before position : .
Why do we take the of the sequence probability?
To turn a product of tiny numbers into a numerically stable sum, without changing which answer is most likely.
Why the minus sign in front of ?
Optimizers minimize; flipping the sign makes "confident and correct" a small loss and "wrong" a large one.
Difference between the indicator and the mask ?
picks the correct token within one position; picks which positions (answer, not prompt) are graded.
What does do?
Divides by the number of answer tokens so loss size doesn't depend on answer length.
What does instruct you to do?
Average the bracketed quantity over training pairs sampled from the dataset .