liveBook · Manning

Softmax

As explained in Grokking Machine Learning

A function that converts multiple real-valued scores into positive values whose normalized values sum to one and represent class probabilities.

Suppose an image might be a dog, cat, or bird. Instead of choosing one label immediately, softmax produces a probability mix such as 10% dog, 85% cat, and 5% bird. section 6.5

Softmax converts several classifier scores into positive values and normalizes them so they sum to one. It exponentiates each score, then divides by the sum of all exponentiated scores. section 6.5

Use the equation to follow the two steps: exponentiate every score, then normalize the resulting positive values. section 6.5

Apply softmax in three steps:

  • Collect one score from each class classifier. section 6.5
  • Exponentiate every score so all transformed values are positive. section 6.5
  • Divide each transformed value by their total to obtain probabilities summing to one. section 6.5

Animal scores

For scores of 3 for dog, 2 for cat, and −1 for bird, exponentiation gives approximately 20.085, 7.389, and 0.368. Normalizing these values makes dog the most probable class while keeping every probability positive. section 6.5

Softmax in Keras

A neural network can use a two-node softmax output for two classes or a ten-node softmax output for MNIST digits. Categorical cross-entropy trains these probability outputs, and argmax selects the highest-probability label. section 10.3

How Grokking Machine Learning covers it

How deep it goes
Explains the motivation, exponential normalization, worked scores, and Keras implementation without deriving deeper optimization details.
Examples
Uses dog, cat, and bird scores, a two-class circular dataset, and handwritten MNIST digit classification.
What it assumes
Assumes familiarity with perceptron classifiers and develops logistic classification before extending it to multiple classes.
What you can do after
Apply softmax in Keras to create multi-class outputs and select predictions from their highest probabilities.
How it connects
Connects logistic classifiers, sigmoid functions, linear classifiers, categorical cross-entropy, and neural networks.

Also explained in

Compare how 17 books explain softmax →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Machine Learning. The section links point to the parts of the book it draws on.