borch

Core techniques · 5

Softmax & cross-entropy

A classifier outputs raw scores — logits. Softmax turns them into a probability distribution that sums to 1, and cross-entropy measures how far that distribution is from the true label. Together they are how nearly every classifier is trained. Everything below runs in this page, in both languages.

Softmax: scores to probabilities

softmax exponentiates each score and divides by the total, so the outputs are positive and sum to 1 — the largest logit gets the largest probability, but every class keeps some.

Cross-entropy: the distance to the truth

For a one-hot label, cross-entropy is just −log(p) of the probability the model gave the true class. It is small when the model already favours the right answer and large when it does not — which is exactly the signal training pushes down.

Your turn: make it a distribution

The block reports the sum of its "probabilities", which must be 1 for a real distribution. Right now it is summing the raw logits. Turn them into probabilities with softmax.

The distribution, drawn

Five raw scores become five probabilities, drawn as a strip — brighter is more likely, and the five sum to 1. This is the shape a classifier's output always takes.

What to remember

If a block above errors, that is worth knowing. Every example on this page runs against the same library the tests run against — nothing here is a screenshot. Press Reset to get the original code back.