What Is a Loss Function? How AI Models Know They're Wrong
A model needs a precise, numeric way to measure "how wrong was that" before it can improve — that's what a loss function provides.
Turning "wrong" into a number
A loss function takes the model's output and the correct target, and computes a single number representing how far off the output was — low when the prediction was close, high when it was way off. Every part of training depends on this number existing, because gradient descent needs something concrete to minimize.
What it looks like for a language model
For next-token prediction, the loss typically compares the probability the model assigned to the actual next word against 1.0 (certainty) — the further the model's assigned probability was from confidently correct, the higher the loss for that prediction.
Loss during training vs. real-world quality
A steadily dropping loss during training is a good sign, but it's an imperfect proxy for what people actually care about — a model can have excellent (low) loss on its training objective while still producing unhelpful or unwanted responses. This is exactly why later stages like RLHF exist: they optimize for a different, more human-aligned signal than raw prediction loss.
Frequently Asked Questions
What is a loss function?
A calculation that turns the gap between a model's output and the correct target into a single number — low when the prediction is close, high when it's far off — which training then works to minimize.
Does low training loss mean the model is good?
Not entirely — low loss means the model is doing well on its specific training objective, but that doesn't automatically mean its responses are helpful or well-behaved in practice.