Skip to content
ContentLora

    Tip: press / anywhere to search.

    Explainer

    Loss functions explained: cross-entropy and what AI models minimise

    A loss function turns a model's mistakes into a single number, and training is the search for the parameters that make that number as small as possible.[1][2] Models that predict numbers are usually scored with squared error; models that output probabilities use log loss or its multi-class form, cross-entropy.[3][4][5] Minimising cross-entropy is the same as maximum likelihood training, and perplexity, a common language-model score, is derived from it.[6][7]

    Editor reviewedUpdated Explainer15 claims · 20% primaryMachine learning foundations, Artificial intelligence
    Reading level: 2 passages differ; the rest is the same for everyone.

    This page is part of our machine learning foundations series. It follows probability for machine learning and how gradient descent works; the next step is how neural networks work.

    Gradient descent needs something to go downhill on. That something is the loss: a number that describes how wrong a model’s predictions are, calculated by a loss function.[1] Stanford’s CS231n notes describe it as a measure of our unhappiness with a model’s outcomes, and say it is sometimes called the cost function or the objective.[8]

    Squared error: for predicting numbers

    For a model that predicts a number, such as a house price or a car’s fuel use, the simplest idea is to measure how far off each prediction is. Mean squared error (MSE) squares each miss and averages them.[3]

    Squaring means big misses count far more than small ones. That makes MSE punish outliers much more than mean absolute error, which just averages the size of the misses. So a model trained with MSE gets pulled toward outliers.[3] Which to use depends on how you want the model to treat unusual cases.

    Squared (L2) loss sums the squared differences between predicted and actual values; MSE is its average over N examples.[3] Because the penalty grows quadratically, L2 loss penalises outliers much more heavily than L1 loss, and MSE moves the model toward outliers while mean absolute error does not.[3] The deep learning textbook notes that MSE is itself a cross-entropy, between the empirical distribution of the data and a Gaussian model.[9] See linear regression for the classic case.

    Log loss and cross-entropy: for predicting probabilities

    When a model outputs probabilities, such as the chance an email is spam, a different loss is used: logistic regression models are trained with log loss instead of squared loss.[4] Cross-entropy extends log loss to problems with more than two classes, and quantifies the difference between two probability distributions.[5]

    Picture an image classifier that says “cat 70%, dog 20%, fox 10%” for a photo of a cat. Cross-entropy compares that guess with the right answer, “cat 100%”. The more probability the model puts on “cat”, the lower the loss. In CS231n’s words, the cross-entropy objective wants the predicted distribution to have all of its mass on the correct answer.[10]

    A softmax classifier is trained by minimising the cross-entropy between its estimated class probabilities and a target distribution with all its mass on the correct class.[10] Minimising that cross-entropy is equivalent to minimising the negative log-likelihood of the correct labels, which is maximum likelihood estimation.[6] The deep learning textbook adds a caution on terms: many authors use “cross-entropy” to mean only the negative log-likelihood of a Bernoulli or softmax distribution, which it calls a misnomer.[9]

    Perplexity: the language-model score

    Perplexity measures how well a model is doing its task and is related to cross-entropy.[7] Google’s glossary gives an intuitive reading: for a phone keyboard that suggests word completions, perplexity is roughly the number of guesses the list must contain to include the word the user is typing.[7] Fewer guesses means a better model. See how large language models work.

    Watching the loss and adding a penalty

    Plotting the loss against training steps gives a loss curve, which shows whether a model is converging or overfitting.[11] A falling loss on the training data alone is not enough: models are tested on examples kept apart from training, because the goal is correct predictions on new data. That is the subject of overfitting and generalization.[12][13]

    To discourage overly complex models, the training objective can add a penalty. With regularisation, training minimises a combination of loss and complexity, and a regularisation rate sets how much the complexity term counts.[14]

    Why the choice matters

    Gradient descent adjusts a model’s weights to lower whatever loss it is given.[2] A related risk is well documented in reinforcement learning, where the training signal is a reward rather than a loss: DeepMind said in 2020 that it had collected around 60 examples of agents finding a shortcut to lots of reward without completing the task as the designer intended.[15] Reward hacking explained covers that problem.

    Next in the crash course

    Questions readers ask

    What is a loss function?

    A function that measures how far a model's predictions are from the correct answers and returns a single number, the loss. It is also called a cost function or objective.[1][8]

    What is cross-entropy loss?

    A measure of the difference between two probability distributions, used to train models that output probabilities over several classes. It generalises log loss to more than two classes, and it pushes the model to put all its probability on the correct answer.[5][10]

    Why use mean squared error?

    It averages the squared differences between predictions and real values. Squaring makes it punish large misses, including outliers, much more than absolute error does, so it pulls the model toward outliers.[3]

    What is perplexity?

    A score related to cross-entropy that measures how well a model does its task. For a phone keyboard suggesting completions, it is roughly how many guesses the list needs to include the word being typed.[7]

    Sources

    · 15 claims from 4 publishers

    Each numbered claim is a statement we checked against the sources listed with it. Tap a number in the text to see its sources in place.

    1. [1]

      Loss is a number that describes how wrong a model's predictions are, a measure of how far a prediction is from its label, and a loss function calculates it. reportedas of 2026-11-22

    2. [2]

      Google's course describes gradient descent as a mathematical technique that iteratively finds the weights and bias producing the lowest loss, repeating a fixed cycle for a number of user-defined iterations. reportedas of 2026-11-22

    3. [3]

      Mean squared error (MSE) is the average of the squared differences between predicted and actual values across a set of examples; squared (L2) loss penalises outliers much more heavily than absolute (L1) loss, so MSE pulls a model more toward outliers than mean absolute error does. reportedas of 2026-11-22

    4. [4]

      Logistic regression models, which output probabilities, are trained with Log Loss instead of the squared loss used for linear regression. reportedas of 2026-11-22

    5. [5]

      Cross-entropy generalises Log Loss to problems with more than two classes and quantifies the difference between two probability distributions. reportedas of 2026-11-22

    6. [6]

      Training a model by maximum likelihood, choosing parameters that make the training data most probable, amounts to minimising the negative log-likelihood, or equivalently the cross-entropy. confirmedas of 2026-11-22

    7. [7]

      Perplexity is a measure of how well a model is doing its task that is related to cross-entropy; for a phone keyboard suggesting word completions, it is roughly the number of guesses the list must contain to include the word the user is typing. reportedas of 2026-11-22

    8. [8]

      Stanford's CS231n notes describe the loss function as measuring our unhappiness with a model's outcomes and say it is sometimes also called the cost function or the objective. reportedas of 2026-11-22

    9. [9]

      The deep learning textbook notes that many authors use "cross-entropy" to mean specifically the negative log-likelihood of a Bernoulli or softmax distribution, calls that a misnomer, and points out that mean squared error is also a cross-entropy, between the empirical distribution and a Gaussian model. confirmedas of 2026-11-22

    10. [10]

      A softmax classifier is trained with a cross-entropy loss between its estimated class probabilities and a "true" distribution with all its probability on the correct class, so the objective pushes the model to put all of its probability mass on the correct answer. reportedas of 2026-11-22

    11. [11]

      A loss curve plots loss against the number of training iterations and helps show whether a model is converging or overfitting. reportedas of 2026-11-22

    12. [12]

      Models should be tested on different examples from those used to train them; datasets are traditionally split, and Google's course recommends separate training, validation and test sets. reportedas of 2026-11-07

    13. [13]

      Generalization is a model's ability to make correct predictions on new, previously unseen data, the opposite of overfitting. reportedas of 2026-11-22

    14. [14]

      With regularisation, training minimises a combination of loss and model complexity, with a regularisation rate (lambda) setting how much the complexity term counts. reportedas of 2026-11-22

    15. [15]

      In 2020 DeepMind said it had collected around 60 examples of specification gaming, and that a reinforcement learning agent can find a shortcut to lots of reward without completing the task as the designer intended, much as a student rewarded for right answers might copy them instead of learning the material. confirmedas of 2020-04-21

    Revision history (1)
    1. Page created.

    Created Nov 22, 2026. Last reviewed by an editor on Nov 22, 2026. Next scheduled review: Jun 28, 2027.

    Cite this page

    "Loss functions explained: cross-entropy and what AI models minimise." ContentLora, updated Nov 22, 2026. https://contentlora.com/explain/loss-functions-explained

    Spotted an error? Suggest a correction or emailcorrections@contentlora.com.