Spot the error in this description of SFT loss masking
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Click any words you think contain an error. Click again to unmark.
SFT is next-token cross-entropy over the full sequence. Masking sets prompt-token labels to -100, so only response tokens drive the gradient, not the reverse.
Imagine grading a student who copies the exam question, then writes an answer underneath. You only want to score the answer they wrote, not the question they copied. So you cross out the question with a special mark that says 'ignore this' and grade only the answer. SFT works the same way. The model reads the whole page, prompt plus answer, but you mask the prompt tokens with a -100 label so they earn no penalty. Only the answer tokens shape the model's habits. The buggy paragraph flips this: it claims you mask the answer and grade the question, which would train the model to predict prompts and learn nothing useful about responding.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
5 min: identify the contrastive-loss error, the full-sequence error, then the paired mask inversion; explain why prompt labels go to -100 and the left-shift label mechanics.
# labels: prompt tokens masked to -100, response tokens kept
labels = input_ids.clone()
labels[:prompt_len] = -100 # ignore prompt in the loss
# next-token shift handled inside the model: logits[t] predicts labels[t+1]
loss = F.cross_entropy(
logits[..., :-1, :].reshape(-1, vocab),
labels[..., 1:].reshape(-1),
ignore_index=-100,
)Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Confusing SFT with preference learning, or inverting the mask so prompt tokens drive the gradient. SFT is next-token cross-entropy with prompt labels set to ignore.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.