Skip to content
AI & Machine Learning Medium #softmax#cross-entropy#classification

Softmax + Cross-Entropy

Logits become probabilities, target class loss is -log(p_correct). The classification staple.

A free, animated softmax + cross-entropy you can read here or embed on any website, from Scrollchart.

Softmax + Cross-Entropy

Softmax + Cross-Entropy LossLogits exp normalize probabilities −log(p_correct). Gradient is simply p y.Logits zSoftmax Probabilities00.000.250.500.751.00softmaxexp(z) / Σexpcat3.2dog1.0bird0.1fish-0.5frog-1.2cat83.8%dog9.3%bird3.8%fish2.1%frog1.0%p_correct = 83.8%Cross-Entropy LossL = log(p_correct)= log(0.838)= 0.176 natsGradient w.r.t. logitsdL/dzᵢ = pᵢ − yᵢcorrect class: p 1other classes: p 0No sigmoid needed: softmax+ CE combines cleanly.Perfect prediction:p=1.0 L=0p=0.01 L=4.6Softmax + CE is the standard classification head: numerically stable via log-sum-exp, gradient is just py per class.

Logits across classes -> exp -> normalize -> probabilities -> cross-entropy with one-hot target. Gradient w.r.t. logits is just (p - y), shown algebraically and visually.

Good for

  • Multi-class classification tutorials and deep learning course material
  • Loss function comparison articles contrasting CE with MSE, focal loss, and hinge loss
  • Explainers on logit calibration, temperature scaling, and label smoothing

Source & accuracy

This softmax + cross-entropy is an editorial illustration built to represent the concept accurately. Where it shows figures, they are typical or representative values chosen to make the relationship clear, not a single underlying dataset. The diagram and its explainer are reviewed and maintained centrally, and updated over time as understanding improves.

Converting logits to probabilities and losses

Classification networks output logits (raw unnormalized scores) from the final layer. Softmax converts them to probabilities: each logit is exponentiated, then all are normalized to sum to 1. Softmax is the standard because it is smooth, differentiable, and the probabilities are interpretable. Cross-entropy loss measures how well the predicted probabilities match the true distribution. For a multi-class problem, it is the negative log probability of the true class: -log(p_correct). If the model assigns 90% probability to the correct class, loss is -log(0.9) = 0.10. If it assigns 10%, loss is -log(0.1) = 2.30. This penalty structure makes sense: slightly wrong predictions are cheaper than wildly wrong ones.

Why softmax plus cross-entropy is standard

The combination is mathematically elegant. The gradient of cross-entropy loss with respect to logits is simply (predicted_probability - true_probability), leading to simple and stable gradient updates. Softmax ensures probabilities sum to 1 and are bounded between 0 and 1, preventing extreme values. Alternatives like Hinge loss (for SVMs) or Focal loss (for imbalanced data) exist and suit specific problems, but softmax-cross-entropy is the default for multi-class classification because it handles most cases well, is numerically stable (when implemented carefully), and benefits from decades of optimization. The pairing is so common that many frameworks provide a fused implementation that computes both efficiently and prevents numerical issues that can arise from computing them separately.

Embed this diagram

Add this animated softmax + cross-entropy to your own site. Copy one line of HTML, or use the embed builder for theme and sizing options.

Reference

What this is
A free, embeddable, animated softmax + cross-entropy for any website.
Who uses it
AI/ML blogs, CS educators.
How to embed
Copy one line of HTML. No signup. No watermark. Works in WordPress, Webflow, Ghost, Substack, plain HTML.
File size
iframe embed, ~80 KB gzipped (loads on demand, does not block your page paint).
License
Free forever. Editorial explainer text included; updated centrally over time.

Embed format options

Copy the universal HTML snippet, the WordPress shortcode, or an iframe fallback - see the WordPress plugin page for details. Any format keeps the same Core Web Vitals profile and the same explainer text.

Embed snippet
<div data-scrollchart="softmax-crossentropy" data-scrollchart-v="1"></div>
<script src="https://scrollchart.com/embed.js" async></script>

Frequently asked questions

Where can I get a free animated "Softmax + Cross-Entropy" for my website?
Scrollchart provides "Softmax + Cross-Entropy" as a free, embeddable animated diagram you can add to any website with one line of HTML. No signup is required and there is no watermark. The diagram and its explainer text are served from scrollchart.com, so the embed stays current without any maintenance on your end.
How do I embed a softmax + cross-entropy in a developer or tech blog?
Copy the one-line snippet from the Scrollchart diagram page and paste it into your post HTML. It works in any static site generator, CMS, or hand-coded HTML page. The embed is a thin loader, not an iframe, so the content is fully in your DOM.