# Loss Function

**TL;DR:** The single number a model is trained to minimize, which makes it the real specification of what the model is optimizing for.

A loss function reduces how wrong a prediction was to one number. For language models that number is almost always cross-entropy on next-token prediction: the model produces a probability distribution over the vocabulary, and the loss is how much probability it assigned to the token that actually came next. Low loss means the model was unsurprised. Perplexity, which you will see quoted more often, is just the exponential of that same quantity.

The important property is that the loss function is the specification. Not the design document, not the product requirements, not what anyone intended. Gradient descent optimizes exactly what the loss measures and is entirely indifferent to what you meant, so any gap between the two becomes a gap in the model. This is not a subtle effect. Pretraining loss measures the ability to predict text, which is why a pretrained model is excellent at continuing a document and useless as an assistant. The entire existence of RLHF is a response to that mismatch: a reward model is a learned loss function for the qualities cross-entropy cannot see.

Loss and metrics are different objects and confusing them causes real problems. A loss has to be differentiable, because gradients have to flow through it, which rules out most of what you actually care about. Accuracy, task success, and helpfulness are not differentiable. So training optimizes a differentiable proxy while evaluation measures the thing you want, and the relationship between them is empirical rather than guaranteed. Training loss falling while eval quality falls is a normal, diagnosable state, not a paradox: either the model is overfitting, or the proxy has come apart from the goal.

The generalization worth carrying into system design is that this is not a training-only phenomenon. Whatever your system optimizes for is whatever you measure, and your eval suite is the loss function for your application even though nothing about it is differentiable. If your evals reward answer length, your prompt engineering will drift toward long answers. If they never test refusal on unanswerable questions, nothing in your process will push toward appropriate refusal. Choosing what to measure is choosing what the system becomes, at the application layer for exactly the same reason it holds during training.

## Why it matters

The loss function is where intent gets translated into something a machine can pursue, and every mistranslation shows up later as a behavior nobody asked for. Recognizing that pattern makes a whole class of model behavior legible: sycophancy, verbosity, hedging, and over-refusal are all cases of a proxy being optimized faithfully. The same reasoning transfers directly to eval design, where the metrics you pick quietly become the objectives your team optimizes.

## Example

A team fine-tunes a summarization model and watches training loss fall steadily, so they ship. Users report the summaries read fluently but omit the one number they needed. Cross-entropy rewards predicting plausible next tokens across the whole summary, and a fluent sentence that drops a figure scores nearly as well as one that keeps it. Adding an eval that specifically checks whether every numeric claim in the source survives into the summary exposes a 40 percent omission rate that training loss had no way to reveal.

## Related terms

- [Gradient Descent](https://www.maximem.ai/glossary/gradient-descent)
- [Backpropagation](https://www.maximem.ai/glossary/backpropagation)
- [RLHF (Reinforcement Learning from Human Feedback)](https://www.maximem.ai/glossary/rlhf)
- [Evals (Evaluation Systems)](https://www.maximem.ai/glossary/evals)
- [Benchmark](https://www.maximem.ai/glossary/benchmark)
- [Fine-Tuning](https://www.maximem.ai/glossary/fine-tuning)
- [Alignment](https://www.maximem.ai/glossary/alignment)
- [LLM-as-a-Judge](https://www.maximem.ai/glossary/llm-as-a-judge)

---

Source: [https://www.maximem.ai/glossary/loss-function](https://www.maximem.ai/glossary/loss-function)
