Lessons › Chapter 4: Classification
Sigmoid and softmax
A model first produces a raw score, which can be any number at all. The sigmoid turns it into a chance between 0 and 1. The numbers under the bars are the raw scores; the bar heights are the chances.
Watch it move. This lesson is interactive on Gradient Lab: every step is an animated scene you can replay.
Start the interactive lessonStep by step
Routing support emails
Support emails need routing to one of several teams: cards, loans or fraud.
Sigmoid squashes any number
A model first produces a raw score, which can be any number at all. The sigmoid turns it into a chance between 0 and 1. The numbers under the bars are the raw scores; the bar heights are the chances.
The S-shape
Join the tops and you get the S. Big positive scores get close to 1 but never reach it. Big negative scores get close to 0. A score of 0 means “50 / 50”.
More than two answers
What if the photo could be a cat, a dog or a bird? The model gives one raw score per class: 2.0, 1.0 and 0.1. These are not chances yet. They don’t add up to anything in particular.
Softmax: share out 100%
softmax first boosts each score (the leader pulls further ahead), then divides by the total so the shares add to 1. Result: cat 66%, dog 24%, bird 10%.
They always fill exactly 100%
Stack the three shares and they make one full tower: 100%. Whatever the scores, softmax always gives chances that add up to exactly 1. The tallest share is the model’s answer.
In real life: photo labels on your phone
When your phone’s gallery finds “cats” or “beaches”, the last step of its model is a softmax. Every label gets a share of 100%, and the biggest share becomes the tag you see.
Quick check: The softmax chances for three classes always…
- add up to 1 (correct)
- are all equal
- can be negative
Softmax divides each boosted score by the total, so the shares always sum to 1, and none is negative.
Pseudocode
# two answers: sigmoid sigmoid(score) = 1 / (1 + e^(−score)) sigmoid(-4) → 0.02 sigmoid(0) → 0.5 sigmoid(4) → 0.98 # many answers: softmax scores = [cat 2.0, dog 1.0, bird 0.1] boosted = e^score for each # [7.39, 2.72, 1.11] chances = boosted / sum(boosted) # [0.66, 0.24, 0.10] # chances always add up to 1
Key terms
- sigmoid
- An S-shaped squasher that turns any number into a value between 0 and 1.
- softmax
- Turns a list of scores into chances that add up to 100%.
In the news
Recent models and papers that build on this idea: