Loss function
A loss function is the formula that scores how wrong a model's predictions are during training, producing the single number that training works to push down.
Training a model is a loop of guessing and correcting, and the loss function is what does the marking. The model makes predictions for a batch of examples, the loss function compares each prediction with the right answer and returns a number called the loss. Google's machine learning glossary puts it simply: a good model gets a lower loss than a bad one, and the goal of training is usually to make that number as small as possible. An algorithm such as gradient descent then nudges the model's weights in whichever direction lowers the loss, and the loop repeats.
Different jobs need different loss functions, because each one decides which mistakes matter most. A model predicting house prices is often trained with squared loss, also called mean squared error, which squares each error: being 20,000 euros out costs four times as much as being 10,000 euros out, so large misses are punished hard. A model answering yes or no questions usually uses log loss, which punishes confident wrong answers heavily. Cross-entropy extends log loss to choices among many classes, and it is the standard measure for language models, comparing the probabilities a model gives to every possible next word with the word that actually came next.
The idea is far older than machine learning. Wikipedia traces it back to Laplace and notes that the statistician Abraham Wald brought it back into statistics in the middle of the 20th century. Economists use the same idea under names such as cost or regret, and insurers use it to model payouts. In each case the loss function turns a messy question about what counts as a good outcome into a single number a computer can work on.
The practical point is that a loss function is a stand-in for what people actually want. A model can drive its training loss very low and still fail on new data, which is why engineers watch loss on held-back validation data as well as on the training set. When a lab reports that a model's loss fell, that says the model got better at the exact task it was scored on; whether that carries over to useful behaviour is a separate question that needs separate tests.
A loss function measures error, so training tries to minimise it. An objective function is the broader term for whatever a system is set up to optimise: it can be a loss to minimise, or something like reward or accuracy to maximise. In practice the training objective is often the loss plus extra penalty terms such as regularisation. No. Accuracy counts how often a model is right, while loss measures how far off its predictions are, often taking confidence into account. Two models with the same accuracy can have very different losses if one is confidently wrong on its mistakes. Loss is what training optimises; accuracy is usually a reporting metric. Language models are usually trained on next-token prediction scored with cross-entropy, which compares the probability the model assigned to each possible next token with the token that actually appeared. Lower cross-entropy means the model was less surprised by real text. Perplexity, a figure often quoted in research, is calculated directly from cross-entropy. Mostly, yes. Wikipedia treats cost function and loss function as the same idea in optimisation and decision theory. Some textbooks reserve loss for the error on a single example and cost for the average over a whole dataset, but news coverage and most practitioners use the terms interchangeably.Common questions
What is the difference between a loss function and an objective function?
Is loss the same as accuracy?
Which loss function do large language models use?
Is a cost function the same as a loss function?
Search for "loss function machine learning", "mean squared error vs cross-entropy" or "training loss vs validation loss" to see how losses are chosen and read. Reliable sources include Google's Machine Learning Glossary and Crash Course, framework documentation from PyTorch and TensorFlow, and university course notes on statistical learning. Treat claims that a lower loss means a smarter model with care, since loss only measures performance on the task and data it was computed on.Finding more
Working out what this means for your business?
Aileron Shift builds the systems behind this site: AI newsrooms that research, write and publish on their own, marketing automation and WordPress hosting for companies that need to move faster than their competitors.