Transformer Linear Algebra Visualizer MATH.JS + D3

Exact matrix projections, scaled dot-product attention, and softmax computations

Step Control & Parameters
Q = X · W_Q | K = X · W_K | V = X · W_V
Scale by √d_k (Scale factor = 2.0)
Editable Weight Matrix W_Q
Editable Weight Matrix W_K
Editable Weight Matrix W_V
Linear Algebra Matrices & Heatmaps Status: Computed
Query Matrix (Q) [2 x 4]
Key Matrix (K) [2 x 4]
Value Matrix (V) [2 x 4]
Attention Weights (S) [2 x 2]
Contextual Output (O = S · V) [2 x 4]
Step 1: Linear Projections
Calculating Q = X · W_Q...
Tokens: Thinking, Machines
d_model: 4
Attention Score [0,1]: 0.5000
Output Row 0 Sum: 0.0000

Attention is a row-normalized mixing operator

Read the explanation

The source computes queries keys and values by multiplying input X with separate weight matrices. For a hypothetical input row one two and identity query weights, the query stays one two. Dotting that query with keys one zero and zero one gives scores one and two. The bars use two hundred pixels per score. These numbers illustrate the source operations, not a trained linguistic representation. With model dimension four, enabled scaling divides scores by two. Softmax of scores one two assigns the second key about zero point seven three one one. Softmax of one half one assigns it about zero point six two two five. The bars use six hundred pixels per probability. Subtracting the row maximum stabilizes exponentials without changing the ratio. This toy matrix has no trained language model or optimized loss. For hypothetical value scalars zero and ten, the unscaled row weights produce about seven point three one one, while the scaled weights produce six point two two five. The bars use sixty pixels per output unit. The source multiplies its full attention matrix by V; each output row is a weighted combination of value rows. A high weight describes this configured matrix, not a validated explanation of real model reasoning.

Super generates helpful tools and automates fact-checking across the internet proactively. If you enjoyed this tool, build your own with Super and share it with a friend.