Skip to content
Query Feedz
  • News
  • Business
    • Digital Marketing
      • Marketing & Sales
      • SEO
      • Content Marketing
      • AEO and GEO
    • Startups
      • Founder Stories
      • Funding & VC
      • Product & Growth
    • Money
      • Investing
      • Markets & Economy
      • Saving & Budgeting
  • AI & Technology
    • Technology
      • Consumer Tech
      • CRM
      • Cyber Security
      • Software Engineering
      • WordPress
      • Hardware
    • Artificial IntelligenceAI Glossary
      • LLMs
      • Machine Learning
      • AI Fundamentals
      • Generative AI
      • Deep Learning
    • AI Use Cases
      • Automation
      • Content
      • Customer Support
      • Finance
      • Marketing
      • View All
  • Tools & Software
  • Account
    • Submit Guest Post
    • Submit a tool
    • My listing
  • Contact
QueryFeedz
  • News
  • Business
    • Digital Marketing
      • Marketing & Sales
      • SEO
      • Content Marketing
      • AEO and GEO
    • Startups
      • Founder Stories
      • Funding & VC
      • Product & Growth
    • Money
      • Investing
      • Markets & Economy
      • Saving & Budgeting
  • AI & Technology
    • Technology
      • Consumer Tech
      • CRM
      • Cyber Security
      • Software Engineering
      • WordPress
      • Hardware
    • Artificial IntelligenceAI Glossary
      • LLMs
      • Machine Learning
      • AI Fundamentals
      • Generative AI
      • Deep Learning
    • AI Use Cases
      • Automation
      • Content
      • Customer Support
      • Finance
      • Marketing
      • View All
  • Tools & Software
  • Account
    • Submit Guest Post
    • Submit a tool
    • My listing
  • Contact
QueryFeedz
  1. Home /
  2. AI Glossaries /
  3. LLMs /
  4. What is Cross-Entropy Loss?
LLMs

What is Cross-Entropy Loss?

Updated September 26, 2026 Read 3 min

Cross-entropy loss measures how far a model's predicted probability distribution is from the correct answer. It is the standard loss function for classification and for training language models.

Contents 11
  1. 01Key takeaways
  2. 02Cross-entropy explained in simple terms
  3. 03The formula and a worked example
  4. 04Why cross-entropy rather than accuracy?
  5. 05Variants
  6. 06Cross-entropy and perplexity
  7. 07Practical notes
  8. 08Limitations
  9. 09Common Use Cases
  10. 10Frequently Asked Questions
  11. 11Related Terms

Cross-entropy loss measures how far a model’s predicted probabilities are from the correct answer. For each example, it is the negative logarithm of the probability the model gave to the true class or token. Confident correct predictions produce a small loss; confident wrong predictions produce a very large one. It is the standard loss function for classification and for training LLMs.

Key takeaways

  • Loss for one example = −log(probability assigned to the correct answer).
  • It punishes confident mistakes heavily.
  • Average cross-entropy over tokens is what LLM training minimises.
  • Perplexity is simply the exponential of average cross-entropy.
  • It is computed from logits for numerical stability.

Cross-entropy explained in simple terms

Imagine a weather forecaster. If they say 90% chance of rain and it rains, they scored well: small penalty. If they said 10% and it rains, the penalty is much larger. If they had said 1%, larger still. Cross-entropy is that penalty system, and training pushes the model to avoid confident mistakes.

The formula and a worked example

For a single prediction, loss = −ln(p), where p is the probability assigned to the correct answer.

Probability given to the truthLoss
0.990.01
0.900.105
0.500.693
0.251.386
0.102.303
0.014.605

The curve rises steeply as probability approaches zero, which is why models learn quickly from confident errors.

In an LLM: if the true next token is “Mumbai” and the model gave it 0.30, the loss at that position is −ln(0.30) ≈ 1.20. Training averages this across every token in the batch.

Why cross-entropy rather than accuracy?

Accuracy only counts right or wrong, so it gives no gradient to learn from: nudging a weight slightly rarely flips a prediction. Cross-entropy responds smoothly to probability changes, so even small improvements produce a useful learning signal. It is also differentiable, which gradient descent requires.

Variants

VariantUse
Binary cross-entropyTwo classes, or multi-label problems
Categorical cross-entropyOne correct class among many
Label smoothingSoftens targets slightly to reduce overconfidence
Weighted cross-entropyGives rare classes more importance
Focal lossFocuses on hard examples in imbalanced data

Cross-entropy and perplexity

Perplexity = exp(average cross-entropy loss). A loss of 2.0 corresponds to a perplexity of about 7.4; a loss of 1.0 corresponds to about 2.7. Training curves for LLMs are usually shown as loss, while evaluation reports often use perplexity, but they carry the same information.

Practical notes

  • Loss is computed from logits using stable implementations rather than computing softmax first.
  • In LLM fine-tuning, loss is often applied only to response tokens, not the prompt.
  • Padding tokens are masked out so they do not affect the loss.

Limitations

  • Assumes exactly one correct answer, which is a poor fit when several continuations are equally valid.
  • Encourages matching training text, not truth or helpfulness.
  • Very confident wrong predictions can produce huge gradients, which is one reason for gradient clipping.
  • A low loss does not guarantee a useful assistant.

Common Use Cases

01

LLM pretraining

Measure next-token prediction error across trillions of tokens.

02

Fine-tuning

Train models on response tokens for specific behaviours.

03

Classification models

Train spam, fraud and topic classifiers.

04

Evaluation

Compute perplexity from average loss.

05

Imbalanced data

Apply weighted or focal variants for rare classes.

06

Distillation

Compare student and teacher distributions during training.

Frequently Asked Questions

A loss function measuring how far predicted probabilities are from the correct answer, computed as the negative log probability of the truth.

It gives a smooth, differentiable signal for next-token prediction and penalises confident mistakes strongly.

Perplexity is the exponential of the average cross-entropy loss per token.

It depends on the task and tokenizer. Track it relative to a baseline and over time rather than as an absolute target.

Softening the target slightly so the model is not trained to be fully certain, which can improve calibration.

Related Terms

  • Loss Function
  • Perplexity
  • Next-Token Prediction
  • Logit
  • Gradient Descent
  • Classification

Related AI Terms

What is an Attention Head?An attention head is a single attention unit inside a transformer layer, with its own query, key and…What is Prefix Tuning?Prefix tuning is a parameter-efficient fine-tuning method that learns trainable vectors inserted into the attention keys and values…What is an Attention Mechanism?An attention mechanism is a technique that lets a neural network focus on the most relevant parts of…What is Self-Attention?Self-attention is a mechanism where each position in a sequence attends to every other position in the same…What is Multi-Head Attention?Multi-head attention runs several attention operations in parallel, each with its own learned projections, so a model can…What is RoPE (Rotary Positional Embedding)?RoPE (rotary positional embedding) encodes a token's position by rotating its query and key vectors by an angle…

Contents

  1. 01Key takeaways
  2. 02Cross-entropy explained in simple terms
  3. 03The formula and a worked example
  4. 04Why cross-entropy rather than accuracy?
  5. 05Variants
  6. 06Cross-entropy and perplexity
  7. 07Practical notes
  8. 08Limitations
  9. 09Common Use Cases
  10. 10Frequently Asked Questions
  11. 11Related Terms

AI Topic

  • LLMs

Related Terms

  • What is an Attention Head?
  • What is Prefix Tuning?
  • What is an Attention Mechanism?
  • What is Self-Attention?
  • What is Multi-Head Attention?
  • What is RoPE (Rotary Positional Embedding)?

Quick Navigation

  • Common Use Cases
  • Frequently Asked Questions
  • Related Terms
  • Back to top

Details

Updated
September 26, 2026
Read
3 min
  • Forum
  • Submit a tool
  • Submit Guest Post
  • List Your Startup
  • Privacy Policy
  • Editorial Policy
  • Account
  • Contact
  • AI Productivity
  • AI Video
  • AI Coding
  • AI Chatbots
  • Sales
  • AI Business
  • View All Tools

Subscribe our Newsletter

Get weekly exclusive content - No spam.

Copyright © 2026 -  Query Feedz

Manage Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
  • Manage options
  • Manage services
  • Manage {vendor_count} vendors
  • Read more about these purposes
View preferences
  • {title}
  • {title}
  • {title}