Sitemap
Anandha L Ranganathan

Anandha L Ranganathan

Softmax function

7 min readSep 23, 2026

--

The formula

In three steps:

  1. Take each score and raise e to that power.
  2. Add up all those results.
  3. Divide each one by the total.

That’s it. The output is a set of numbers that are all positive and add up to exactly 1 — in other words, percentages.

Example: three contestants

Three contestants get judged. Their raw scores — in machine learning these raw scores are called logits — are:

Press enter or click to view image in full size

We want to turn those into percentages.

The obvious way (standard normalization)

Add them up: 5 + 3 + 2 = 10. Divide each by 10.
Simple. Intuitive. And as we’ll see in a minute, quietly broken.

Press enter or click to view image in full size

The softmax way — step by step

Step 1: Exponentiate each score.

Press enter or click to view image in full size

(If you want to follow along: e is about 2.71828. So e⁵ means 2.71828 multiplied by itself 5 times.)

Step 2: Add them up.

148.4131591 + 20.0855369 + 7.3890561 = 175.8877521

Step 3: Divide each one by the total.

A:  148.4131591 / 175.8877521 = 0.843795  →  84.38%
B: 20.0855369 / 175.8877521 = 0.114195 → 11.42%
C: 7.3890561 / 175.8877521 = 0.042010 → 4.20%

Sanity check — they should add to 1:

0.843795 + 0.114195 + 0.042010 = 1.000000

Side by side

Press enter or click to view image in full size

The first thing you notice: softmax is opinionated.

Plain normalization is a democratic accountant — it splits the pie strictly by share. Softmax is a rich-get-richer amplifier. A modest lead of 2 points became a landslide. That’s often exactly what you want from a model that has to commit to an answer.

But that amplification is the shallow difference. Here’s the one that actually matters.

The harsh judge problem

A grumpy judge shows up and docks 1 point from everybody. New scores: 4, 2, 1.

Stop and think about what changed in reality. Nothing. Same contestants. Same ranking. Same gaps between them. One judge was in a bad mood, uniformly.

The percentages should not move.

What plain normalization does

New total: 4 + 2 + 1 = 7.

A: 4/7 = 57.14%
B: 2/7 = 28.57%
C: 1/7 = 14.29%

A jumped from 50% to 57.14%. Because a judge was grumpy. Nothing real changed and the answer moved by 7 percentage points. That’s broken.

What softmax does

Step 1:
e⁴ = 54.5981500, e² = 7.3890561, e¹ = 2.7182818

Step 2: total = 64.7054980

Get Anandha L Ranganathan’s stories in your inbox

Join Medium for free to get updates from this writer.

Step 3:

A: 54.5981500 / 64.7054980 = 0.843795  →  84.38%
B: 7.3890561 / 64.7054980 = 0.114195 → 11.42%
C: 2.7182818 / 64.7054980 = 0.042010 → 4.20%

Identical to before. To six decimal places. Not approximately — exactly.

Why this happens

Because of one schoolbook rule about exponents:

e^(z+c) = e^z.e^c

Adding a constant c to every score multiplies every exponentiated value by the same factor e^c. And a common factor on the top and bottom of a fraction cancels out. The shift vanishes.

Press enter or click to view image in full size

In our case, subtracting 1 from everything multiplied every e^score by e⁻¹ ≈ 0.3679. Top and bottom both shrank by the same 36.79%, so the ratio didn’t budge.

And here’s the kicker

No other function does this. Not squaring. Not absolute values. Not “shift everything up until it’s positive, then divide.”

If you write down the requirement — “adding the same number to every score must not change the output” — and solve it mathematically, the exponential function is the unique answer. It falls out as the only possibility.

Why you should care

The scores coming out of a neural network have no fixed baseline. Nothing in the training process pins down where “zero” is. The whole layer can drift up or down by some constant and it means absolutely nothing about the prediction.

Softmax is immune to that drift by looking at algebric equation above. Plain normalization would have your model’s confidence wobbling around based on a meaningless number. So the e^x isn’t cosmetic. It’s the thing that makes the output trustworthy.

The flip side: softmax cares how loudly you shout

Plain normalization only sees ratios. Softmax sees gaps after an exponential, so stretching the scores changes the output.

Plain normalization (unchanged if you double)

Press enter or click to view image in full size

Now let’s go the other direction. Keep the original scores 5, 3, 2 and double them: 10, 6, 4.

Softmax (changes if you double)

Press enter or click to view image in full size

The 2 does not factor out of the sum. You are no longer cancelling a common multiplier; you are squaring each term.

Press enter or click to view image in full size

calculation for 10,6,4

e^10 = 22026.4658
e^6 = 403.4288
e^4 = 54.5982
total = 22484.4927

A: 22026.4658 / 22484.4927 → 97.96%
B: 403.4288 / 22484.4927 → 1.79%
C: 54.5982 / 22484.4927 → 0.24%

A went from 84% to 98%. Same scores, doubled.So the two functions are exactly inverted:

Press enter or click to view image in full size

Softmax throws away the one thing that’s meaningless (the baseline) and pays attention to the one thing that carries information (the spread).

Temperature in LLM: That sensitivity is a feature

While querying the LLM you pass that same knob as a parameter: temperature. The model still emits one logit vector Z for the next token. The API divides by T and softmaxes before it samples. temperature=0.2 is the ice-cold row in the table; temperature=2 is the hedge; you never changed the scores, only how sharp they become.

Softmax’s reaction to scaling isn’t a bug — it’s a volume knob. The standard way to write it:

softmax(Z/T)

T is called the temperature. Dividing the scores by T before exponentiating. Replace a temperature T>0 in the exponent and you get

Press enter or click to view image in full size

Let’s turn the knob on our original 5, 3, 2:

Let me show the T = 2 row worked out, since it’s the least obvious:

Scores divided by 2:  2.5, 1.5, 1.0
e^2.5 = 12.1824940
e^1.5 = 4.4816891
e^1.0 = 2.7182818
total = 19.3824649

A: 12.1824940 / 19.3824649 = 0.628532 → 62.85%
B: 4.4816891 / 19.3824649 = 0.231224 → 23.12%
C: 2.7182818 / 19.3824649 = 0.140244 → 14.02%

Sum: 0.628532 + 0.231224 + 0.140244 = 1.000000 ✓

This is the same temperature setting you’ve adjusted in an LLM API. Crank it up and the model divides its scores down, flattening the distribution, so unlikely words get a real chance — output feels creative or unhinged. Turn it down and the distribution sharpens toward the single most likely token — output feels safe and repetitive. Same model, same scores, different personality, entirely because softmax is scale-sensitive.

Here is example of temperature with same dataset but results different personalities.

Press enter or click to view image in full size

Self Attention calculation to find the related words

If you’ve read the attention formula, you’ve seen a mysterious division:

Press enter or click to view image in full size

That √d_k is exactly this volume knob. Raw attention scores come out too loud, and a too-loud softmax becomes a dictator: one option sits at 99.99% and everything else is effectively zero. When that happens there’s almost no useful feedback signal left for the network to learn from — training stalls. The division is a volume limiter, keeping softmax in the range where it still responds to changes.

If softmax really were “just normalization,” that √d_k would do nothing at all. It would cancel out. The fact that it’s load-bearing is proof the e^x matters.

Softmax can never say “none of the above”

Every softmax output is strictly greater than zero. Always. Because e^x is never zero, no matter how negative x gets.

A probability can be one in a trillion. It can never be actually zero.

Usually harmless. Occasionally it causes something genuinely weird. Inside a Transformer, an attention head that wants to say “nothing in this sentence is relevant to me right now” has no way to express that. It is forced to hand out 100% of its attention somewhere.

--

--