Softmax

Softmax is a mathematical function that converts a list of arbitrary numbers into a probability distribution: every value becomes positive, larger values get disproportionately more weight, and all values add up to one. It is used wherever a neural network has to choose among several options.

Where it appears

In a classifier, softmax turns the network’s final scores – called logits – into a probability for each category. A large language model applies it to its scores for every token in its vocabulary to decide what comes next; dividing the scores by a temperature beforehand makes the choice more or less random. Inside a transformer, softmax also turns attention scores into weights that determine how much each token draws on every other.

Origins and quirks

Mathematically, softmax has the same form as the Boltzmann distribution of statistical physics. The engineer John Bridle gave it the name around 1989–90, because it is a smooth (“soft”) version of simply picking the maximum. Its cost grows with the size of the vocabulary, which motivated shortcuts such as the hierarchical softmax used in Word2vec. And because its weights must always add up to one, attention layers often park much of their attention on the first tokens of a text, whatever their meaning – an effect researchers call “attention sinks”.

Why it matters

Softmax is where a model’s internal numbers become choices – one reason AI outputs are probabilities rather than certainties (see Calibration and Next-Token Prediction).

Written with Claude, made by Anthropic, whose language models, like those of competitors OpenAI, Google (also an Anthropic investor) and Meta, choose each token from a probability distribution.

Related

Temperature · Next-Token Prediction · Attention · Activation Function · Calibration · Loss Function

Sources: John S. Bridle: Training Stochastic Model Recognition Algorithms as Networks can Lead to Maximum Mutual Information Estimation of Parameters (NIPS 2) (1990) · John S. Bridle: Probabilistic Interpretation of Feedforward Classification Network Outputs, with Relationships to Statistical Pattern Recognition (Neurocomputing, NATO ASI Series F68) (1990) · Ian Goodfellow, Yoshua Bengio and Aaron Courville: Deep Learning, chapter 6 (MIT Press) (2016) · Ashish Vaswani et al.: Attention Is All You Need (arXiv) (2017) · Guangxuan Xiao et al.: Efficient Streaming Language Models with Attention Sinks (arXiv) (2023)

Leave a Reply

Your email address will not be published. Required fields are marked *