Why are attention scores scaled by the square root of the key dimension in scaled dot-product attention?

Last updated 22 November 2026

  • With unit-variance components, q·k has variance d_k. Dividing by √d_k (the standard deviation) brings the logit variance back to about 1.

  • Large logits saturate softmax into a near one-hot output. Its gradients then vanish and training becomes slow or unstable.

  • Dividing by d_k instead would over-shrink the logits and make attention nearly uniform.

  • https://datarekha.com/interview/deep-learning/scaled-dot-product-scaling/
  • https://aiengineeringfromscratch.com/interviews/transformers/why-scale-by-sqrt-dk
  • https://community.deeplearning.ai/t/why-do-we-use-square-root-of-key-dimension-for-scaling/776800
All Transformers interview questions