Dot-product variance grows with head width. We will widen a random attention head while holding sequence length and input variance fixed, then measure both score scale and attention concentration.
The setup defines a stable row-wise softmax and normalized entropy. Entropy near one means attention is spread across keys. Entropy near zero means it is concentrated on very few keys.
Question: Does Dividing by \(\sqrt{d_k}\) Stabilize Attention?
For each width, we compute unscaled scores \(\mathbf Q\mathbf K^\top\) and scaled scores \(\mathbf Q\mathbf K^\top/\sqrt{d_k}\). Predict how their standard deviations and softmax entropies change with \(d_k\).
score_std = {"Unscaled": [], "Scaled": []}entropy = {"Unscaled": [], "Scaled": []}for dk in dimensions: variances = {"Unscaled": [], "Scaled": []} entropies = {"Unscaled": [], "Scaled": []}for trial inrange(trials): Q = rng.standard_normal((sequence_length, dk)) K = rng.standard_normal((sequence_length, dk)) scores = Q @ K.Tfor name, values in [("Unscaled", scores), ("Scaled", scores / np.sqrt(dk))]: weights = row_softmax(values) variances[name].append(np.mean(values **2)) entropies[name].append(normalized_entropy(weights).mean())for name in score_std:# Scores have population mean zero, so E[score^2] is their variance. score_std[name].append(np.sqrt(np.mean(variances[name]))) entropy[name].append(np.mean(entropies[name]))
Each trial uses an ordinary query matrix and key matrix, with one row per token. The paired calculations use the same scores, so scaling is the only difference.
Answer. Without scaling, score magnitude grows like \(\sqrt{d_k}\) and the softmax becomes increasingly concentrated. Scaling keeps the score variance near one and makes the entropy nearly independent of width.
The factor removes concentration caused by width alone. Learned query-key alignment can still produce concentrated attention.