Visual walkthrough — Image classification pipeline
The heart of the image classification pipeline is the moment a stack of raw scores becomes a set of confidences you can trust. This page builds that moment from absolute zero. No symbol appears before we draw it.
Step 1 — What the network hands us: a row of "scores"
WHAT. The last layer of the network gives us a short list of numbers, one per possible class. If there are 3 classes (say cat, dog, fox), we get three numbers. We call each number a logit and write the whole row as :
- — the whole row of raw scores (a list).
- — the score for class 1. The subscript just means "first slot".
- The comma-list means these are separate numbers sitting side by side.
WHY. These numbers are the network's gut feeling, but they are useless as-is: a score of or means nothing on its own. We cannot say "the network is 5 sure it's a dog." We need to compare them and convert to something bounded.
PICTURE. Look at the three bars below. Their heights are the raw logits — one dips below zero (negative score allowed!), and they clearly do not add to anything meaningful.
Step 2 — Try the naïve fix, and watch it break
WHAT. The obvious idea: to make numbers add to 1, divide each by their total. That is
- — our attempted probability for class .
- — the score of that class (top).
- — the running total of all scores (bottom).
WHY (it fails). Two disasters. First, if any is negative, we get a negative "probability" — impossible. Second, if the scores sum to zero (e.g. ), we divide by zero — the formula explodes.
PICTURE. The red bar is a negative score. Dividing it by the total produces a bar pointing below the zero line — a negative probability. That is our warning sign: raw division is not allowed.
Step 3 — The tool that fixes "must be positive": the exponential
WHAT. We pass every score through the exponential function . Here is a fixed number, and means " raised to the power ". We create new numbers
- — the exponentiated score for class (always positive).
- — raised to that class's logit.
WHY this tool and not another? We need a function that (a) turns any real number — even negative — into a positive one, and (b) keeps the order: a bigger score must stay bigger. The exponential is the natural choice because:
- for every , including negatives (e.g. , still positive).
- is strictly increasing, so bigger logit → bigger . Order preserved.
PICTURE. The black curve is . Follow the red guide line: a negative input at the bottom still lands on a positive output. The curve never touches zero and never goes below it.
Step 4 — Now divide safely: the softmax formula appears
WHAT. Every is positive, so their sum is positive too — no more divide-by-zero, no more negatives. So now we do the "divide by the total" step from Step 2, but on the safe positive numbers:
Term by term:
- — the final probability for class (the hat means "the network's estimate").
- (top) — the positive, exponentiated score of the class we're asking about.
- (bottom) — the sum of the same transform over all classes. The symbol ("sigma") means "add up"; runs from to ; is the number of classes.
- The bottom is the same for every — it is the shared normaliser that guarantees the outputs add to 1.
This is the softmax function, and it feeds straight into Softmax activation.
WHY it works now. Top is positive → each . Bottom is the sum of the tops → dividing forces . Both probability laws satisfied, and no input can break it.
PICTURE. Left: the positive exponentials as tall bars. Right: after dividing by their total, they become the red probability bars whose heights stack to exactly 1 (the dashed line at the top).
Step 5 — Why exponential amplifies the winner (the secret bonus)
WHAT. Softmax does more than normalise — it sharpens. Compare two classes by dividing their probabilities:
- — the gap between the two scores.
- — that gap, exponentiated: the ratio depends only on the difference, and it grows fast.
WHY this matters. If and , the gap is , so class is more likely than — a confident vote. Plain division (Step 2) would give only — a wishy-washy vote. The exponential turns small score gaps into decisive preferences, exactly what a classifier wants.
PICTURE. The black line is naïve division's ratio (nearly flat as the gap grows). The red curve is softmax's ratio , shooting upward — small gaps become strong decisions.
Step 6 — The degenerate cases: ties, huge numbers, one giant
WHAT & WHY — three edge cases every reader must see.
-
All scores equal (). Then every is the same, so for all . With that's — pure "I have no idea", spread evenly. Correct behaviour.
-
One score dominates (). The bottom is basically , so the big class gets and the rest . Softmax approaches a hard "pick the max" — but stays smooth (never exactly 0 or 1), which backprop needs to keep learning.
-
Enormous scores overflow (). A computer cannot store . The fix: subtract the biggest logit from all of them before exponentiating. Since Step 5 showed only differences matter, this changes nothing about the answer:
- — the largest logit in the row.
- — every score shifted down so the biggest becomes ; now is the largest term, safe to compute.
PICTURE. Three tiny bar charts side by side: the flat tie, the single-spike winner, and the shifted-then-safe version. Same shape before and after shifting — proof the shift is free.
The one-picture summary
The whole journey: raw logits (can be negative, no rules) → exponentiate (all positive, order kept, winner amplified) → divide by the total (heights now sum to 1) → a valid probability row.
Recall Feynman retelling — say it like you're explaining to a friend
The network ends by shouting out a few raw numbers, one per class — like judges holding up scorecards, and some scores are even negative. We want to turn those scorecards into "how sure are we, in percent." The dumb way — just divide each score by the total — breaks the moment a score is negative or the total is zero. So first we run every score through , which does two lovely things at once: it makes any number positive (negatives included), and it keeps the ranking (bigger stays bigger) while blowing up the gaps so the leader really pulls ahead. Now that all our numbers are safely positive, we finally divide each by their total — and because they're all positive, the results are guaranteed between 0 and 1 and add up to exactly 1. If two scores tie, we get an even split ("no idea"). If one score towers over the rest, that class gets nearly all the probability but never exactly 1, so learning can continue. And if the scores are astronomically large, we quietly subtract the biggest one first — which the math proves changes nothing — so the computer doesn't choke. That's softmax: exponential to be safe and sharp, divide to be fair.
Recall
What is a logit? ::: A raw, unbounded score the network's final layer outputs for each class, before any conversion to probability. Why exponentiate before normalizing instead of dividing raw scores? ::: is always positive (handles negative scores) and keeps ordering, so the divide can't produce negatives or blow up; it also amplifies score gaps into confident decisions. Why does softmax always sum to 1? ::: Each output divides a term by the sum of all those same terms, so adding the outputs reconstructs the whole sum over itself, which is 1. How do we prevent numerical overflow with huge logits? ::: Subtract the maximum logit from every score before exponentiating; since only differences matter, the probabilities are unchanged. What does softmax output when all logits are equal? ::: A uniform distribution, for each of the classes.
See also: Cross-entropy loss (the partner that scores these probabilities), Backpropagation (learns the logits), ResNet architecture and Transfer learning (produce the logits in the parent pipeline), and Multi-label classification (where softmax is replaced because classes are no longer mutually exclusive).