HomeAI & Machine LearningScaled Dot-Product Attention: The Role of √d_k

Scaled Dot-Product Attention: The Role of √d_k

Interactive 3D visualization of scaled dot-product attention: watch raw Q·K dot products spread out as key dimension grows, then see how dividing by √d_k keeps the softmax attention distribution well-behaved instead of collapsing to one-hot.

AI & Machine Learning3DAdvanced60 FPS📱 Mobile-adapted⇄ 2D version
transformer-attention-mechanism-visualization ↗ Open standalone

This simulator isolates one specific mechanic inside every transformer attention head: the √d_k scaling term in softmax(QKᵀ/√d_k)V. Nine tokens sit in a 3D row, each holding a random query and key vector; picking a query token computes its raw dot product against every key, optionally divides by the square root of the key dimension, applies a softmax, and renders the resulting attention distribution as glowing beams and flowing particles into the query token, with bars above each token tracking its live weight. Widening the key dimension d_k with scaling switched off drives the raw scores' standard deviation up and collapses the softmax onto a single token — exactly the vanishing-gradient failure mode the √d_k term exists to prevent — while switching scaling back on keeps the distribution well-behaved at any width.

⚙ Under the hood

Interactive 3D visualization of the √d_k scaling term in transformer attention: watch raw query-key dot products spread out as the key dimension grows, then see how dividing by √d_k keeps the softmax attention distribution well-behaved instead of collapsing onto one token.

transformersattentionsoftmaxself-attentiondeep-learningneural-networks

3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)