Softmax Calculator softmax(x)
Enter a vector of numbers (logits) separated by spaces or commas, e.g. 2 1 0.1. You get the softmax probabilities that sum to 1, a live bar chart, the predicted class, and the numerically-stable working with NumPy code.
This free softmax calculator turns any vector of numbers into a probability distribution that sums to exactly 1, draws a live bar chart of the probabilities, and shows the numerically-stable working step by step. Enter your logits above, press Compute softmax, and you see which class wins, how confident the model is, and the NumPy code that produces the same result.
What is the softmax function?
The softmax function takes a vector of real numbers — often called logits or scores — and squashes them into a set of positive values that add up to 1. Because the outputs are non-negative and sum to one, they can be read directly as probabilities. Softmax is the standard way a classification model converts its raw output scores into “the probability that this input belongs to each class”. A large score becomes a large probability, a small score a small probability, and the gaps between scores are exaggerated by the exponential, so the winning class usually stands out clearly.
Softmax is a generalisation of the logistic sigmoid function to more than two classes. Where sigmoid answers a single yes/no question, softmax answers a “which one of these k classes” question. For exactly two classes the two functions are equivalent.
The rule in one line
For a vector x, the softmax of element i is exp(x_i) divided by the sum of exp(x_j) over all elements. Every output lands between 0 and 1, and together they sum to 1.
How to use the softmax calculator
- Type your numbers into the input vector box, separated by spaces or commas — for example
2 1 0.1. These are your logits or raw scores. - Press Compute softmax (or just keep typing — the result updates live). The probabilities appear as an equation, a bar chart, and a per-class list.
- Read the predicted class (argmax) tile to see which element wins, and the sum check tile to confirm the outputs really add to 1.
- Open Show the working to follow the three steps: shift by the max, exponentiate, and normalise.
Use the example chips to load a typical three-class logit vector, a two-class case, a uniform input where every class is equally likely, and a random vector for experimentation. Adjust the decimal places to see more or fewer significant figures.
The softmax formula
For an input vector x = [x_1, x_2, ..., x_k], the softmax produces a vector p of the same length:
p_i = exp(x_i) / ( exp(x_1) + exp(x_2) + ... + exp(x_k) )
The numerator raises e to the power of each score, which is always positive. The denominator is the sum of all those exponentials, so dividing by it forces the whole vector to sum to 1. The exponential is what makes softmax “soft”: it strongly favours the largest input without ever setting the smaller ones exactly to zero, so every class keeps a little probability. That smoothness is exactly what gradient-based training needs.
Worked example: softmax of [2, 1, 0.1]
Take the vector [2, 1, 0.1]. First find the exponentials: exp(2) = 7.389, exp(1) = 2.718, and exp(0.1) = 1.105. Their sum is 7.389 + 2.718 + 1.105 = 11.212. Now divide each exponential by that sum:
7.389 / 11.212 = 0.659, 2.718 / 11.212 = 0.242, and 1.105 / 11.212 = 0.099.
So softmax([2, 1, 0.1]) = [0.659, 0.242, 0.099], which sums to 1. Class 0 — the largest input, 2 — receives about 66% of the probability, class 1 about 24%, and class 2 about 10%. The calculator above reproduces exactly these numbers, along with the bar chart that shows the winning class at a glance.
Why subtract the max: numerical stability
Mathematically, softmax is unchanged if you subtract a constant from every input, because that constant factors out of the numerator and denominator. The calculator uses this fact to stay numerically stable. If you exponentiate a large logit directly — say exp(1000) — a computer returns infinity (overflow), and the calculation collapses into inf/inf, which is not a number. The fix is to subtract the maximum element m from every score before exponentiating:
p_i = exp(x_i - m) / sum( exp(x_j - m) )
Now the largest exponent is exp(0) = 1 and every other is between 0 and 1, so nothing overflows, yet the answer is identical to the naive formula. This is why the working panel above shows the shift by m = max(x) as its very first step. It is the single most important implementation detail of softmax and a favourite interview question.
Forgetting to subtract the max (overflow on large logits), applying softmax twice (a softmax of a softmax is not a softmax), summing along the wrong axis on a batch of vectors, and feeding softmax to a loss function that already applies it internally — PyTorch's
CrossEntropyLoss expects raw logits, not probabilities. Passing it softmax output double-applies the function and hurts training.Temperature: sharpening or softening the distribution
A common extension is the temperature parameter T. Before applying softmax you divide every logit by T: softmax(x / T). A temperature below 1 sharpens the distribution, pushing probability toward the top class and making the model more confident; a temperature above 1 softens it, spreading probability more evenly. As T approaches 0 softmax approaches a hard argmax (all probability on the winner); as T grows large the output approaches a uniform distribution. Temperature is used when sampling text from language models — higher temperature gives more varied, creative output — and in knowledge distillation, where a “soft” teacher distribution carries more information than a hard label.
Softmax in Python with NumPy
The stable softmax is a few lines of NumPy. Note the x - x.max() shift, which mirrors what this calculator does:
import numpy as np
def softmax(x):
e = np.exp(x - x.max())
return e / e.sum()
x = np.array([2.0, 1.0, 0.1])
print(softmax(x)) # [0.659 0.242 0.099]
For a batch of vectors stored as rows of a 2-D array, take the max and the sum along the last axis and keep the dimensions so broadcasting works: e = np.exp(x - x.max(axis=1, keepdims=True)) then e / e.sum(axis=1, keepdims=True). Getting that axis right is the most common bug when moving from a single vector to a batch.
Where softmax shows up in machine learning
Softmax is everywhere in classification. It is the output layer of almost every neural-network classifier: the final linear layer produces one logit per class, and softmax turns those logits into class probabilities that are compared with the true label using cross-entropy loss. In natural-language models, softmax over the vocabulary produces the probability of every possible next token. Inside the transformer attention mechanism, softmax converts raw attention scores into weights that sum to 1, deciding how much each token attends to every other. Reinforcement-learning policies use softmax to turn action preferences into a probability of taking each action. Wherever a model must express “how likely is each option”, softmax is usually the function doing it.
Frequently asked questions
Why do the softmax outputs always add up to 1?
Because every output is an exponential divided by the sum of all the exponentials. Adding the outputs adds all those numerators, which equals the denominator, so the total is exactly 1 — that is what makes them a valid probability distribution.
What is the difference between softmax and sigmoid?
Sigmoid maps a single number to one probability and is used for binary or independent multi-label problems. Softmax maps a whole vector to a set of probabilities that compete and sum to 1, and is used for mutually-exclusive multi-class problems. For two classes they are equivalent.
Does subtracting the maximum change the answer?
No. Subtracting any constant from every input leaves the softmax result unchanged, because the constant cancels between the numerator and denominator. Subtracting the maximum is done purely to prevent numerical overflow.
Can softmax outputs be exactly 0 or 1?
Not exactly. Because the exponential is always positive, every class keeps a tiny non-zero probability, and no class can reach a full 1. Values can get extremely close to 0 or 1 when one logit dominates, but never quite reach them.
What is temperature in softmax?
Temperature T scales the logits before softmax as softmax(x / T). Low temperature sharpens the distribution toward the top class; high temperature flattens it toward uniform. It controls how confident or exploratory the output is.
Related calculators
Compare softmax with the binary sigmoid calculator, brush up on vectors with the cross product calculator, or explore the full linear algebra calculators hub to keep building your machine-learning toolkit.