Zenaique

Name the two properties softmax guarantees for every row of the attention weight matrix

Fill in blank·Easy·4.0 · 0·~1 min·Asked atN8nPerplexity·Relevant atMicrosoft
Attempt it
Every entry of a softmax normalized attention row lies in the interval [, ], and the entries of each row sum to exactly .
TL;DR

Every entry lies in [0, 1] and each row sums to exactly 1. Softmax produces a row-stochastic matrix, a valid probability distribution over keys.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Picture cutting a single pizza into slices to share among friends. No friend can get a slice of negative size, no friend can get more than the whole pizza, and the total amount of pizza handed out has to add up to exactly one pizza, no more, no less. The step that turns raw model scores into attention works the same way. Each item on the menu gets a fraction of the model's focus that is at least 0 and at most 1, and the fractions across the whole row always sum to exactly one pizza's worth. That tidy 'no negatives, no overweights, total of one' rule is what makes the row behave like a clean share-out.

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

Softmax guarantees two properties on every row of the attention weight matrix: each entry lies in [0, 1], and the entries sum to exactly 1. Together these make each row a valid probability distribution over the keys, equivalently a point on the probability simplex. The simplex constraint is the algebraic substrate of essentially every important property of attention: the convex-combination interpretation of the output, the way masking works, and the structural inevitability of attention sinks.

This deep dive proves both properties from the softmax formula, walks the probability-simplex interpretation, traces the three main downstream consequences, and covers the edge cases (fully masked rows, softmax-1, hard attention) where the constraints behave differently.

Mental model: softmax is the operator that takes arbitrary real-valued scores and slices them onto the probability simplex. The two properties together are the simplex constraint.

Proving the two properties from the formula

The softmax operator on row i of the score matrix produces:

wij=esijkesikw_{ij} = \frac{e^{s_{ij}}}{\sum_k e^{s_{ik}}}

Non-negativity (w_{ij} >= 0)

The exponential function e^x is strictly positive for every real x. So:

  • The numerator e^{s_{ij}} is positive.
  • The denominator sum_k e^{s_{ik}} is a sum of positives, so positive.
  • The ratio is positive.

The only way to get exactly 0 is to feed in s_{ij} = -inf, which is what masking does deliberately.

Upper bound (w_{ij} <= 1)

The denominator includes the numerator as one of its summands:

denominator = e^{s_{ij}} + sum_{k != j} e^{s_{ik}}

The other summands are all positive, so denominator >= numerator, so w_{ij} = numerator / denominator <= 1. Equality w_{ij} = 1 is approached but not reached in practice; in the limit, one score dominates and all others are infinitely smaller.

Row sum = 1

Sum the row entries:

jwij=jesijkesik=jesijkesik\sum_j w_{ij} = \sum_j \frac{e^{s_{ij}}}{\sum_k e^{s_{ik}}} = \frac{\sum_j e^{s_{ij}}}{\sum_k e^{s_{ik}}}

The numerator and denominator are the same sum (just with different dummy indices), so the ratio is exactly 1.

Key insight: the row-sum-to-1 property is not approximate. It is exact by construction, holding even after numerical operations like the row-max stabilization trick softmax(s - max(s)).

The probability-simplex interpretation
Three downstream consequences of the simplex constraint
Edge cases and variants
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.

Real products, models, and research that use this idea.

  • Vaswani et al. 2017: the canonical attention formula softmax(QK^T / sqrt(d_k)) V produces row-stochastic weight matrices, the [0, 1] entries and row-sum-to-1 are why the output is a convex combination of values.
  • Attention visualizations (BertViz, exBERT) display the post-softmax weight matrix as a heatmap where each row's cells visually add up to 1.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QWhat changes about the [0, 1] and sum-to-1 properties when softmax-1 is used in place of standard softmax?
A

Softmax-1 computes w_j = exp(s_j) / (1 + sum_k exp(s_k)). The +1 in the denominator means each row entry is still in [0, 1], but the row sum is now in [0, 1) rather than exactly 1. The model can express 'no key matters' by letting the row sum approach 0. This eliminates the structural cause of attention sinks but requires retraining since gradients flow differently.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Forgetting that weights must be NON-NEGATIVE and at most 1. Softmax cannot produce negative weights or weights larger than 1, regardless of the score values.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • The range [0, 1] for every softmax-normalized attention entry

  • Why every entry is non-negative (exponential is positive)

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
Explain scaled dot product attention.
Short answer·Medium