Scaled dot-product self-attention, computed live on a worked example — the Query–Key–Value mechanism that powers transformers.
Every token is linearly projected into three vectors. The query asks “what am I looking for?”, each key advertises “what do I offer?”, and the value carries the information actually mixed into the output. A query scores itself against every key, those scores are normalized with softmax into attention weights, and the output is the weighted sum of the values. Everything below is the real arithmetic — no mock data.
The token currently being updated. It probes the sequence for relevant context.
One per token. The dot product Q·K measures how relevant each token is to the query.
The payload. Attention weights blend the values into the new representation.
Sentence: “the cat sat on the mat” — tokenized into 6 tokens. Pick a query token, switch attention heads, and drag the temperature slider to see softmax sharpen or flatten.
Rows = query tokens, columns = key tokens. Each row sums to 1. The selected query row is outlined.
bertviz-style arcs from the query token. Arc width & opacity encode the attention weight.
Honest, reproducible pipeline — this is exactly what the code does on each render:
Head 1 is tuned toward local/adjacent attention, Head 2 toward content similarity (the two “the” tokens attend to each other), and Head 3 is more diffuse — mirroring the specialized heads observed in real transformers.