Intuition The one core idea
A language model is just a machine that, given some text, outputs a probability for every possible next word . Supervised Fine-Tuning nudges those probabilities so that after a question , the words it wants to say next are the words of a good answer — and we measure "how wrong it currently is" with a single number called the loss.
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.
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.
A token is one small chunk of text the model treats as a single unit. The sentence "How do I bake bread?" might become the tokens ["How"," do"," I"," bake"," bread","?"].
Picture: beads on a string, read one after another. Why we need it: the whole model works one token at a time, so we must be able to count and point at individual tokens.
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.
V
V is the fixed list of every token the model knows — its entire dictionary (often ~50,000 entries).
Picture: a numbered shelf of all possible beads. Every token the model ever emits is picked off this one shelf.
Why the topic needs it: to output "the next token", the model must choose from some finite set of options. V is that set. The symbol v ∈ V means "v is one token chosen from the shelf".
The little symbol ∈ just means "is a member of" — read v ∈ V as "v is one of the tokens on the shelf" .
The model never says "the next token is definitely X". Instead it hands you a confidence for every token on the shelf .
Definition A probability distribution over the vocabulary
For a given moment, the model outputs a number p v for each token v ∈ V :
each p v is between 0 and 1 (0 = "never", 1 = "certain"),
all of them add up to exactly 1 .
Picture: a row of bars, one per shelf-slot, whose heights sum to a full 100%.
Intuition Why probabilities and not just "the answer"?
If the model committed to one word, we could never say "you were close ". Probabilities let us grade how much confidence it put on the correct word — and that graded feedback is exactly what training needs to gently improve.
The notation p y t (you'll meet y t in a second) just means: the bar height the model gave to the token that was actually correct.
Now we name the two things every SFT example contains: the question and the ideal answer.
x and response y
x = the prompt : the user's input tokens (the question). Built from chat templates in practice.
y = the response : the ideal answer's tokens.
y = ( y 1 , y 2 , … , y T ) means the response is a list of T tokens; y t is the token at position t .
T = the total number of response tokens (the length of the answer).
The subscript t is just a position counter , like "the 3rd bead". So y 3 = "the 3rd answer token".
Definition "Everything before" —
y < t
y < t is shorthand for all the response tokens that came before position t : y < t = ( y 1 , … , y t − 1 ) .
Picture: stand at bead t and look back along the string — y < t is that whole tail behind you.
Why: to guess the next token honestly, the model is only allowed to see what already happened. This is called being autoregressive .
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 π θ ( y t ∣ x , y < t ) reads:
"The probability the model gives to the answer-token y t , given the prompt x and all earlier answer tokens y < t ."
Intuition Why "given" matters
The same word "bread" is a great guess after "How do I bake ___" but a terrible guess after "The capital of France is ___". The conditional bar ∣ is the model saying: my probabilities depend on the context I've been shown. Change what's on the right of the bar, and every bar height on the left changes.
θ is data.
Why it feels right: θ sits next to x and y , so it looks like another input.
The fix: x , y are data (they change every example). θ is the machine's internal knobs (the same for the whole model, slowly tuned by training). LoRA fine-tunes only a small slice of θ .
To score a whole answer, we combine its per-token probabilities. The rule (the "chain rule of probability") says: multiply them.
Intuition Why multiply and not add?
"Get token 1 right AND token 2 right AND ..." — probabilities of independent-feeling AND-events multiply. If each step is 0.5 likely, getting a 3-token answer exactly right is 0.5 × 0.5 × 0.5 = 0.125 : rarer, hence smaller. Multiplication captures "every step must land".
Multiplying many numbers below 1 gives absurdly tiny values (a 100-token answer might have probability like 0.0000 … with 40 zeros). Computers choke on that. The logarithm rescues us.
Definition Logarithm (the "how many times" question)
log answers: "what power do I raise the base to, to get this number?" The one property we use:
log ( a × b ) = log a + log b
Picture: a machine that turns stretching (multiply) into sliding (add) on a number line.
Why the topic needs it: applying log to the big product from step 5 converts it into a friendly sum — and because log only ever grows (never dips) as its input grows, the answer that was "most probable" is still "most log-probable". We changed the scale, not the winner.
One more fact we'll use: for any probability p between 0 and 1 , log p is negative or zero (e.g. log 0.5 = − 0.693 , log 1 = 0 ). Confident-and-correct → close to 0 ; unsure → very negative.
Optimizers are built to push numbers down . But we want to push probability up . Fix: flip the sign.
Definition Negative log-likelihood (the loss)
Take the log-probability (which is negative), stick a minus in front, and now:
correct-and-confident (p ≈ 1 ) → loss ≈ 0 (good, small),
wrong-and-clueless (p ≈ 0 ) → loss huge (bad, large).
Picture: a golf score — lower is better, zero is perfect.
This "− log p y t " is exactly the cross-entropy the parent note keeps referring to. It's the same number pretraining uses; SFT just feeds it curated data.
Two look-alike symbols in the parent note that are easy to confuse.
1 [ condition ]
A tiny switch: it equals 1 if the condition inside is true, 0 otherwise. So 1 [ v = y t ] is 1 only for the slot that holds the true token, 0 for every other shelf slot. That's why − ∑ v 1 [ v = y t ] log p v collapses to just − log p y t : only one term survives.
m t
m t ∈ { 0 , 1 } decides whether position t is graded at all : m t = 1 for answer tokens, m t = 0 for prompt tokens.
Picture: a highlighter that colors only the answer part of the string; only colored tokens contribute to the score.
Why: we teach the model to write answers , not to re-predict the user's question .
1 [ ⋅ ] with m t .
The fix: 1 [ v = y t ] picks the correct token among the vocabulary (inside one position). m t picks which positions count (prompt vs answer). Different jobs, similar shape.
D and expectation E
D = {( x ( i ) , y ( i ) )} is the pile of training pairs ; the superscript ( i ) just numbers them (pair 1, pair 2, ...).
E ( x , y ) ∼ D [ ⋅ ] means "the average of the thing in brackets, taken over pairs drawn from D " . The ∼ reads "sampled from".
Picture: shuffle the deck of flashcards, compute the score on each, take the mean.
Conditional pi(y_t given x and past)
Log turns product into sum
Minus sign gives cross-entropy loss
Mask m_t keeps only answer tokens
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 V ? The fixed shelf of every token the model knows; the model's next-token choice is always picked from V .
What must the numbers p v satisfy? Each is between 0 and 1, and across all of V they sum to exactly 1.
Read π θ ( y t ∣ x , y < t ) in plain words. The probability the model (weights θ ) gives to answer-token y t , given the prompt x and all earlier answer tokens.
What is θ , and how does it differ from x and y ? θ = the model's internal weights (same across all examples); x , y = the data that changes each example.
What does y < t mean? All response tokens before position t : ( y 1 , … , y t − 1 ) .
Why do we take the log 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 log ? Optimizers minimize; flipping the sign makes "confident and correct" a small loss and "wrong" a large one.
Difference between the indicator 1 [ v = y t ] and the mask m t ? 1 picks the correct token within one position; m t picks which positions (answer, not prompt) are graded.
What does ∑ t m t 1 do? Divides by the number of answer tokens so loss size doesn't depend on answer length.
What does E ( x , y ) ∼ D instruct you to do? Average the bracketed quantity over training pairs sampled from the dataset D .