Transformer Self-Attention & Softmax
Scaled dot-product self-attention lets every Transformer token dynamically weight information from all visible context tokens by dividing QK^T dot products by sqrt(d_k) before row-wise softmax.
Technical Reference & Equations
- Scaled Dot-Product Attention:
\mathrm{Attention}(Q, K, V) = \mathrm{softmax}\!\left(\frac{Q K^\top}{\tau \sqrt{d_k}} + M\right) V(sqrt(d_k) prevents large dot products from saturating softmax gradients; M masks future tokens.) - Row-Wise Temperature Softmax:
\alpha_{i,j} = \frac{\exp(s_{i,j} / \tau)}{\sum_{k} \exp(s_{i,k} / \tau)}(Lower temperature tau sharpens focus toward the top key; higher tau flattens weights.) - Attention Entropy & Effective Context (Perplexity):
H_i = -\sum_j \alpha_{i,j} \log_2 \alpha_{i,j}, \quad \mathrm{PPL}_i = 2^{H_i}(Effective number of tokens actively attended to by query token i.)
Related Machine Learning Calculators
- Activation Functions & Derivatives: Compare Sigmoid, Tanh, ReLU, Leaky ReLU, GELU, and Swish outputs alongside their gradients.
- Gradient Descent & Momentum: Inspect how learning rate and momentum traverse convex and non-convex loss landscapes.
- Classification Metrics & Confusion Matrix: Compute accuracy, precision, recall, F1, specificity, and MCC from TP/FP/FN/TN counts.
- Matrix & Linear Transform: Determinant, inverse, trace, rank, and eigenvalues with 2D basis vector transforms.
- 3D Vector Dot, Cross & Projection: Compute dot product, cross product, angle, and projection on a 3D isometric vector plot.
- Base & Two’s Complement Converter: Convert between Binary, Octal, Decimal, Hex, and signed 8/16-bit Two’s Complement with interactive bit toggles.