Book a demo →

Softmax

Definition

Softmax turns a list of scores (logits) into probabilities that sum to 1. Formula, worked example, temperature, LLM output and sigmoid compared.

In short

Softmax is a function that turns a list of raw scores, called logits, into probabilities between 0 and 1 that add up to 1. Neural networks use it in their output layer to pick among several classes, and language models use it to turn logits into the probability of each possible next token.

What is softmax?

Softmax is a function that turns a list of numbers into probabilities. Wikipedia describes it this way: “The softmax function, also known as softargmax” … “converts a tuple of K real numbers into a probability distribution over K possible outcomes.” Every output lies between 0 and 1, and the outputs add up to 1. The inputs are called logits: the raw scores a network produces before they become probabilities.

The formula for a list of scores z with K entries is softmax(z)i = exp(zi) / Σj exp(zj). Each score goes through the exponential function, and each result is divided by the sum of all results. Goodfellow, Bengio and Courville write in their textbook Deep Learning (2016), section 6.2.2.3: “Softmax functions are most often used as the output of a classifier, to represent the probability distribution over n different classes.”

How softmax works: a worked example

Take a language model that has to continue the prompt “The capital of France is” and scores four candidate tokens with the logits 3, 1, 0 and −1. Softmax first takes the exponential of each logit: 20.086, 2.718, 1.000 and 0.368. Their sum is 24.172, and dividing each value by that sum gives the probabilities:

TokenLogitProbability
Paris383.1 %
Lyon111.2 %
Marseille04.1 %
London−11.5 %

Example computed with the softmax formula, not from a source. The rounded values add up to 99.9 %.

The logit of “Paris” is two points above the logit of “Lyon”, yet its probability is more than seven times higher. The exponential function stretches the gaps between scores, so the largest logit takes a disproportionate share. The order never changes: a higher logit always ends with a higher probability.

Why it is called softmax

Goodfellow et al. find the name confusing and explain why: “The function is more closely related to the arg max function than the max function.” Argmax returns only the position of the largest value. Softmax spreads the choice: the largest input gets the largest share, and every other input keeps some probability. According to the textbook, “soft” refers to the fact that softmax is continuous and differentiable, which argmax is not. The authors conclude: “It would perhaps be better to call the softmax function ‘softargmax,’ but the current name is an entrenched convention.”

Wikipedia states where the word comes from: “In machine learning, the term "softmax" is credited to John S. Bridle in two 1989 conference papers”. One of these papers appeared in 1990 in the Springer volume Neurocomputing under the title “Probabilistic Interpretation of Feedforward Classification Network Outputs, with Relationships to Statistical Pattern Recognition”.

Softmax in language models

At the end of each step a language model has one score for every token in its vocabulary. Softmax turns these scores into a probability for each possible next token. The transformer paper by Vaswani et al., “Attention Is All You Need” (arXiv 1706.03762, version 7, 2 August 2023), names this step: “We also use the usual learned linear transformation and softmax function to convert the decoder output to predicted next-token probabilities.”

The same paper uses softmax a second time, inside its attention mechanism, where it turns similarity scores into weights; the transformer architecture entry quotes that passage. Goodfellow et al. describe this kind of use in general terms: softmax functions “can be used inside the model itself, if we wish the model to choose between one of n different options for some internal variable.”

The probabilities are not yet the answer. A decoding method picks the next token from them, for example by sampling or, as in the Vaswani paper, by beam search. Figure 1 shows the order of the steps.

Steps from logits to next-token probabilities as described in Vaswani et al. (2017); the paper picks tokens with beam search. Values are not shown.

Softmax and temperature

The temperature setting of a language model acts on the softmax. In the formula on Wikipedia each logit is multiplied by β, and the temperature is proportional to 1/β, so a higher temperature divides the logits by a larger number. Wikipedia describes the effect: “A higher temperature results in a more uniform output distribution (i.e. with higher entropy; it is "more random"), while a lower temperature results in a sharper output distribution, usually with one value dominating.” The entry on LLM temperature lists the values that model providers allow and works through an example of its own.

Softmax, sigmoid and argmax

Goodfellow et al. call softmax “a generalization of the sigmoid function, which was used to represent a probability distribution over a binary variable.” The three functions differ in what they return:

FunctionOutputTypical use
SigmoidOne probability between 0 and 1A yes-or-no outcome, such as spam or not spam
SoftmaxOne probability per option, all adding up to 1Choosing among several classes, or among all tokens in a vocabulary
ArgmaxThe position of the largest valuePicking a single option without any probability

With two options the formula shows the link: softmax gives the first option exp(z1) / (exp(z1) + exp(z2)), which equals the sigmoid of the difference z1 − z2. Argmax sits at the other end. Goodfellow et al. write: “The argmax function, with its result represented as a one-hot vector, is not continuous or differentiable.” A network cannot learn through such a hard choice, which is why classifiers are trained with softmax and only switch to argmax when a single answer is needed.

Numerical stability

Computers store numbers with limited range, and the exponential function leaves that range quickly. Goodfellow et al. write in chapter 4.1: “One example of a function that must be stabilized against underflow and overflow is the softmax function.” A very large logit makes exp overflow, and if all logits are very negative the sum in the denominator can round to zero.

The remedy in the same passage: subtract the largest logit from every logit before the calculation. The textbook notes that “the value of the softmax function is not changed analytically by adding or subtracting a scalar from the input vector.” In the example above, 3, 1, 0 and −1 become 0, −2, −3 and −4, and the probabilities stay at 83.1 %, 11.2 %, 4.1 % and 1.5 %.

LLM temperature. The setting that rescales logits before softmax has its own LLM temperature entry with provider ranges.

Transformer architecture. Softmax appears twice in this design, in attention and in the output layer; the entry on the transformer describes both parts of the model.

Knowledge distillation. A student model learns from a teacher's softened probabilities, raised with a softmax temperature; the knowledge distillation entry explains the method.

Large language model. Models that predict text token by token are covered in the large language model entry.

AI token. The units a model scores before softmax are explained in the entry on AI tokens.

Source

  • Wikipedia, “Softmax function” (last edited 2026-11-10). Source for the definition, the origin of the term and temperature (retrieved 2026-12-06): https://en.wikipedia.org/wiki/Softmax_function
  • Ian Goodfellow, Yoshua Bengio and Aaron Courville, Deep Learning, MIT Press 2016, chapter 6 “Deep Feedforward Networks”, section 6.2.2.3. Source for the use in classifiers, the name, sigmoid and argmax (retrieved 2026-12-06): https://www.deeplearningbook.org/contents/mlp.html
  • Ian Goodfellow, Yoshua Bengio and Aaron Courville, Deep Learning, MIT Press 2016, chapter 4 “Numerical Computation”, section 4.1. Source for numerical stability (retrieved 2026-12-06): https://www.deeplearningbook.org/contents/numerical.html
  • Ashish Vaswani et al., “Attention Is All You Need”, arXiv 1706.03762, version 7 (2 August 2023). Source for next-token probabilities, attention and beam search (retrieved 2026-12-06): https://arxiv.org/abs/1706.03762v7
  • John S. Bridle, “Probabilistic Interpretation of Feedforward Classification Network Outputs, with Relationships to Statistical Pattern Recognition”, in Neurocomputing, Springer 1990 (title from the Crossref record; full text not read). Source for the paper behind the term (retrieved 2026-12-06): https://doi.org/10.1007/978-3-642-76153-9_28

Frequently asked questions

What is the purpose of the softmax function in neural networks?

Softmax turns the raw scores of a network into probabilities that add up to 1. Goodfellow, Bengio and Courville write that softmax functions “are most often used as the output of a classifier, to represent the probability distribution over n different classes.” Language models use the same step to score every possible next token.

How is softmax different from sigmoid?

Sigmoid returns a single probability for a yes-or-no outcome. Softmax returns one probability for each of several options, and these add up to 1. Goodfellow, Bengio and Courville describe softmax as “a generalization of the sigmoid function, which was used to represent a probability distribution over a binary variable.”

Why is it called softmax?

The name is misleading, according to Goodfellow, Bengio and Courville: “The function is more closely related to the arg max function than the max function.” Softmax is a smooth version of argmax, continuous and differentiable. The authors suggest “softargmax” as a better name but call the current one “an entrenched convention.”

What is the difference between softmax and argmax?

Argmax returns only the position of the largest value, for example the third of four options. Softmax returns a probability for every option, and the largest input receives the largest share. Argmax is not continuous or differentiable, so networks are trained with softmax and use argmax only when one final answer is needed.

Can softmax be used for binary classification?

Yes. With two outputs, softmax gives the first class exp(z1) divided by exp(z1) plus exp(z2), which equals the sigmoid of z1 minus z2. Both approaches produce the same probabilities. A single sigmoid output does the same job with one score instead of two.