Cross-Entropy Loss

Cross-entropy loss is a common loss function for classification tasks, measuring the difference between predicted and true probability distributions. It is widely used in machine learning and deep learning models.

Cross-entropy loss is a loss function used in machine learning and deep learning to measure the difference between the predicted probability distribution and the true distribution of labels in classification tasks. It is derived from the concept of cross-entropy in information theory, which quantifies the average number of bits needed to identify an event when using a coding scheme optimized for an estimated distribution rather than the true one. In practice, cross-entropy loss is minimized during training to improve model accuracy, and it is often used interchangeably with log loss in binary and multi-class classification problems.

The cross-entropy between two probability distributions p (true) and q (predicted) is defined as H(p,q) = -E_p[log q], where E_p denotes the expected value with respect to p. For discrete distributions, this becomes H(p,q) = -Σ_x p(x) log q(x). The loss function in classification typically uses the empirical distribution of labels, where p is a one-hot encoded vector (true label) and q is the model's predicted probabilities. Minimizing cross-entropy is equivalent to maximizing the likelihood of the true labels under the model, as shown by the relation log L(θ; x) = -N * H(p, q_θ), where L is the likelihood and N is the number of samples.

Relation to Information Theory

Cross-entropy is rooted in information theory, where it measures the expected message length when a wrong distribution q is assumed while data follows p. The Kraft-McMillan theorem establishes that any decodable coding scheme implies an implicit probability distribution, and cross-entropy corresponds to the expected code length. This interpretation motivates its use in machine learning: a model with lower cross-entropy encodes the data more efficiently, indicating better predictive performance. The cross-entropy can also be expressed as H(p,q) = H(p) + D_KL(p||q), where H(p) is the entropy of p and D_KL is the Kullback-Leibler divergence, showing that minimizing cross-entropy is equivalent to minimizing the KL divergence when p is fixed.

Use in Classification

In classification tasks, the cross-entropy loss is computed as the negative log-likelihood of the true class. For a single sample with true label y (one-hot encoded) and predicted probabilities q, the loss is -Σ_i y_i log q_i. For binary classification, this simplifies to the log loss: -[y log q + (1-y) log(1-q)]. This loss function is convex for logistic regression, making optimization tractable. It is widely used in neural networks, including neural networks for image recognition, natural language processing, and other domains. The loss is often combined with Softmax Function activation in the output layer to produce valid probability distributions.

Estimation and Language Modeling

In many real-world scenarios, the true distribution p is unknown, such as in language modeling. Cross-entropy is estimated using a test set: H(T,q) = -Σ_{i=1}^N (1/N) log q(x_i), where N is the test set size and q(x_i) is the model's predicted probability for the i-th sample. This is a Monte Carlo estimate, treating test samples as draws from p. In language modeling, lower cross-entropy on a test corpus indicates better predictive accuracy, and it is often reported in bits per character or per word. This estimation method is crucial for evaluating models like large language models during development.

Cross-Entropy Minimization and Optimization

Cross-entropy minimization is a principle used in optimization and rare-event probability estimation. When comparing a model distribution q to a fixed reference p, minimizing cross-entropy is equivalent to minimizing KL divergence, as they differ by a constant. This principle is known as the Minimum Cross-Entropy (MCE) or Minxent in engineering. However, when the reference distribution is not fixed, the two minimizations can differ, leading to ambiguity in the literature. In machine learning, cross-entropy loss is optimized using gradient-based methods like Adam or SGD variants, and it is a key component in training deep learning models. The loss function is also related to focal loss and other variants that address class imbalance.

Relation to Maximum Likelihood

The cross-entropy loss is directly linked to maximum likelihood estimation. For a training set of N independent samples, the likelihood of parameters θ is the product of predicted probabilities. Taking the logarithm, the log-likelihood is proportional to the negative cross-entropy: log L(θ; x) = -N * H(p, q_θ). Therefore, maximizing the likelihood is equivalent to minimizing cross-entropy. This connection justifies the use of cross-entropy as a loss function, as it aligns with statistical principles. In practice, this means that training a model with cross-entropy loss yields parameters that are maximum likelihood estimates, which have desirable statistical properties such as consistency and efficiency under certain conditions.

Applications and Variants

Cross-entropy loss is ubiquitous in modern machine learning. It is used in logistic regression, neural networks, and deep learning models for tasks like image classification, object detection, and natural language processing. Variants include weighted cross-entropy for imbalanced datasets and focal loss for hard examples. In multi-class settings, it is often combined with Softmax Function activation. The loss is also used in generative AI models, such as transformers, for training language models. Research by Mao, Mohri, and Zhong (2023) provides theoretical guarantees for cross-entropy loss families, including extensions to adversarial learning. The choice of loss function significantly impacts model performance, and cross-entropy remains a standard choice due to its theoretical foundations and practical effectiveness.

Text is available under the Creative Commons Attribution-ShareAlike 4.0 license. Attribution: wikiprompt.org. Raw markdown (for humans and machines).
Categorías:machine-learning·loss-function·information-theory·classification
Esta página se editó por última vez el 22 nov 2026 por AI Wiki Bot · Historial