Urgent.News

What's breaking now, across thousands of outlets.

Tech

Entropy and Cross-Entropy, Explained

If you've spent any time around machine learning the familiarizing yourself with the concept, you have seen the term "entropy" and "cross entropy" show up everywhere. These two distinct terms often show up in topics regarding: classification models, neural networks, and understanding language models. But if you are like me a few weeks ago, you would not be able to write down the formulas without…

Entropy and Cross-Entropy, Explained

Entropy, derived from information theory, gauges the level of surprise associated with the outcome of a random event. Consider two coins, Coin A, fair with equal chances of heads and tails, and Coin B, rigged with a 99% chance of heads. Flipping Coin B would rarely surprise you due to its predictable nature, while Coin A would leave you in disbelief each time.

Entropy quantifies this uncertainty, with a fair coin exhibiting high entropy (maximum uncertainty) and a rigged coin displaying low entropy (predictable outcomes). The formula for entropy is H(P) = -Σ p(x)log(p(x)), where p(x) represents the probability of an event. Rare events, with small p(x), generate higher surprise scores, while common events, with larger p(x), result in lower surprise scores. Entropy, essentially, is the average surprise experienced when sampling from a distribution.

Cross-entropy builds upon the concept of entropy, but without assuming prior knowledge of the true distribution of outcomes. In machine learning, we often lack this knowledge and instead aim to predict the distribution. The cross-entropy formula is H(P,Q) = -Σ p(x)log(q(x)), where P is the true distribution (the actual label of an image) and Q is the predicted distribution (the model's guess).

The key difference from entropy lies in the log term, which now uses the predicted probability q(x) instead of the true probability p(x). The intuition behind cross-entropy is that if the predicted distribution Q closely matches the true distribution P, the cross-entropy will be low. Conversely, if the model confidently predicts incorrectly, the cross-entropy value will skyrocket.

This is precisely the desired behavior for a loss function: confident and correct predictions lead to low loss, while confident and incorrect predictions result in high loss. Uncertain predictions yield moderate losses.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Node.js Express Observability: A Beginner's Health Endpoint-to-Uptime Signal Contract

Short answer: for a flagged fintech pricing change, use an external uptime monitor to test whether the public path is reachable, then use an internal dashboard to decide whether the new rule is…

  • External uptime monitor checks public path reachability for availability decisions
  • Internal health dashboard monitors pricing rule impact on service health
  • Signal contract defines failure meaning for each signal

More from Tuesday 25 August →