Softmax

Softmax is a function that converts a vector of arbitrary real numbers into a probability distribution – all the output values are positive and they sum to one. Each element is exponentiated and divided by the sum of the exponentials of all the elements. The exponential ensures that differences between the inputs are amplified: an element only slightly higher than the rest receives a markedly larger share of the probability, hence the “soft” version of the maximum function. In a language model, softmax appears in two crucial places. At the output of the network it turns raw scores (logits) across the entire vocabulary into the probability of each next token, with the division by temperature before the function controlling how sharp that distribution is. Inside the attention mechanism it normalizes the similarity scores between a query and the keys into the weights used to sum the values. Softmax is differentiable, so backpropagation passes through it without difficulty; its drawbacks are the cost for very large vocabularies and a susceptibility to numerical overflow, which is handled by subtracting the maximum.


Imagine a jury that has awarded the contestants points: 8, 5 and 2. The points are not probabilities in themselves – they do not add up to a hundred percent. Softmax is the conversion table that turns points into odds: “the first has 85 percent, the second 12 percent, the third 3 percent.” It is not a simple pro-rata conversion, though. Softmax deliberately accentuates the winner’s lead, so eight points against five become a far bigger gap than the original numbers suggested. The model thus gets a clear signal about whom to favour without ruling the others out entirely.

Is this article useful to you and are you citing it? Copy the citation