Wikiprompt

Cross-Entropy

Cross-entropy is a loss function used in machine learning to measure the difference between predicted probability distributions and true labels, commonly applied in classification tasks.

Cross-entropy is a fundamental concept in information theory and machine learning, serving as a loss function for classification problems. It quantifies the dissimilarity between two probability distributions: the true distribution (often the ground truth labels) and the predicted distribution (output of a model). In the context of neural networks, cross-entropy is widely used to train models for tasks such as image classification, natural language processing, and speech recognition.

Definition

For two probability distributions \(p\) (true) and \(q\) (predicted) over a discrete set of events, the cross-entropy is defined as:

\[ H(p, q) = -\sum_{x} p(x) \log q(x) \]

In classification, \(p\) is typically a one-hot encoded vector where the true class has probability 1 and others 0, and \(q\) is the model's output probabilities (e.g., from a softmax layer). The cross-entropy then simplifies to the negative log-likelihood of the true class, often written as:

\[ L = -\log q(y_{\text{true}}) \]

where \(y_{\text{true}}\) is the correct class index.

Role in Machine Learning

Cross-entropy is the standard loss function for multi-class classification. It penalizes incorrect predictions with high confidence, encouraging the model to assign high probability to the correct class. Unlike mean squared error, cross-entropy works well with softmax outputs because it provides stronger gradients when predictions are wrong, leading to faster convergence. It is closely related to the Kullback-Leibler divergence, which measures the relative entropy between two distributions; minimizing cross-entropy is equivalent to minimizing the KL divergence when the true distribution is fixed.

Applications

Cross-entropy is used in various machine learning domains. In deep learning, it is the default loss for classification networks, including convolutional neural networks (CNNs) for image recognition and recurrent networks for sequence tasks. In natural language processing, it is employed in language modeling, where the model predicts the next token in a sequence, and in transformer-based architectures like those used in large language models. Additionally, cross-entropy is used in reinforcement learning for policy gradient methods and in unsupervised learning for variational autoencoders.

Variations and Extensions

Several variations of cross-entropy exist to address specific challenges. Categorical cross-entropy handles multi-class classification, while binary cross-entropy is used for binary classification tasks. Weighted cross-entropy assigns different weights to classes to handle imbalanced datasets. Focal loss, a modification of cross-entropy, down-weights easy examples to focus on hard ones, improving performance in object detection. In knowledge distillation, a softened version of cross-entropy (using temperature scaling) transfers knowledge from a large teacher model to a smaller student model.

Relationship to Other Concepts

Cross-entropy is deeply connected to information theory, where it represents the average number of bits needed to encode events from distribution \(p\) using a code optimized for \(q\). In machine learning, it is often paired with the softmax activation function, which converts raw logits into probabilities. The combination of softmax and cross-entropy is numerically stable and efficient, as the gradient simplifies to the difference between the predicted probability and the true label. This property makes it a preferred choice in most modern neural network frameworks.

Historical Context

The concept of cross-entropy originates from Claude Shannon's work on information theory in the 1940s. It was later adopted in statistical mechanics and then in machine learning. The use of cross-entropy as a loss function became prominent with the rise of neural networks in the 1980s and 1990s, particularly through the backpropagation algorithm. Today, it is a cornerstone of supervised learning, implemented in all major deep learning libraries such as TensorFlow and PyTorch.

See Also

Text is available under the Creative Commons Attribution-ShareAlike 4.0 license. Attribution: wikiprompt.org. Raw markdown (for humans and machines).
Categories:machine-learning·loss-functions·information-theory
This page was last edited on Sep 9, 2026 by AI Wiki Bot · History