Skip to content
LiveNext 10:28:37

Definition

What is Loss function?

Loss function is a loss function is the formula that scores how wrong a model's output is, giving training a single number to push downward.

A loss function turns "how wrong was the model?" into a number. Training is the process of adjusting a model so that number gets smaller. Without one, there would be nothing to improve against.

How it works

During training, a model makes a prediction, and the loss function compares it with the right answer. A small loss means the prediction was close. A large loss means it was far off. An optimizer, usually using gradient descent, then nudges the model's parameters in the direction that would have made the loss smaller. Repeat this billions of times and the model improves.

Different jobs use different loss functions. Predicting a number, such as a price, often uses the squared difference between the guess and the truth. Choosing a category, such as "spam or not spam," uses a loss that punishes confident wrong answers heavily.

The loss behind language models

Language models are trained with cross-entropy loss. At each step the model assigns a probability to every possible next token. Cross-entropy looks at the probability it gave the token that really came next. If the model gave it a high probability, the loss is small. If it gave it a tiny probability, the loss is large.

That single choice shapes everything a large language model does. The model is never told to be helpful or truthful during pretraining. It is only rewarded for predicting text well. Later stages such as reinforcement learning and RLHF swap in different signals to steer behavior.

Loss and perplexity are two views of the same thing: perplexity is the exponential of the average cross-entropy loss.

Why it matters

The loss curve is the main dial a training team watches. If it falls smoothly, training is healthy. If it spikes or flatlines, something is wrong. Comparing loss on training text with loss on a held-out dataset reveals overfitting: a model that scores well on what it has seen and poorly on everything else.

Research on scaling laws found that loss falls in a predictable way as models get more data, compute and parameters, which is why labs can forecast a large training run from smaller ones.

What loss does not tell you

A lower loss does not guarantee a better product. It measures prediction on a particular dataset, not whether answers are correct, safe or useful. That is why teams also run evals on real tasks.

An everyday picture

Think of a golf score where lower is better, and the course is every sentence the model reads. The loss function is the scorecard. Training is practice, and each swing adjusts based on where the last ball landed.

Questions people ask

What loss function do language models use?

Large language models are trained with cross-entropy loss on the next token: the less probability they give the real next token, the higher the loss.