Interactive Lab · Attention & Transformers
A transformer's superpower is attention: to understand a word, the model lets it look at every other word and decide how much each one matters. It works by a simple recipe, compare each word to every other (a dot product), then softmax the scores into a set of weights that sum to 1. Type a sentence and watch the attention matrix light up. Hover a row to see what that word is paying attention to.
▶ The playground, type a sentence, read the attention
Attention is the core mechanism of every transformer and LLM: each token decides how much to “look at” every other token. It replaced RNNs for language, vision, and audio. Understanding this one operation is understanding how GPT-class models read and relate information.
The code that's actually running
Drop the temperature toward 0.2 and watch the matrix collapse, each word attends almost entirely to a single other word (its best match). Push it to 4 and every row goes flat grey: the word spreads its attention evenly, gathering a little from everyone. Real models learn a temperature-like scaling (the √d in the formula) so attention is sharp enough to be useful but soft enough to blend context. Now slide position influence up: attention stops caring about which word and starts hugging the diagonal, each token just looks at its neighbours. Meaning vs. position, traded with one knob.
The takeaway
i, column j = how much word i attends to word j. Bright diagonal = self-focus; bright off-diagonal = a relationship the model found.