06 · 2017 · The idea behind modern chatbots

Transformer attention

An LSTM reads one letter at a time and hopes its memory holds on. A transformer lets every letter look at every earlier letter at once and decide which ones matter. That mechanism is called attention, and it is the core of nearly every large language model.

Type a sentence below. The picture shows, for each letter, how strongly it attends to the letters before it. This tiny model (2 layers, 4 heads each) was trained on the same text as the LSTM page, so you can compare the two.

How it works

  1. Embed. Each letter becomes a vector of 64 numbers, plus a signal for its position.
  2. Ask and answer. Each letter produces a query (“what am I looking for?”), a key (“what do I contain?”) and a value (“what can I pass on?”). Query·key gives a score for every earlier letter.
  3. Attend. Scores become weights that add up to 1 (softmax). The letter’s new meaning is a blend of the values it attends to. Four heads do this in parallel with different questions.
  4. Repeat and predict. Two such layers refine each letter, then the last position outputs probabilities for the next letter.

Try it

runs in your browser
tap a letter to see what it attends to

Layer

Head

Next letter guesses

Lines go from the selected letter back to the letters it reads from. Thicker = more attention.
rows = reading letter · columns = letter being attended to

Things to try

“Attention is all you need”

The 2017 paper from Google researchers dropped recurrence entirely. Because every position is processed at once, transformers train far faster on GPUs, and scaling them up turned out to keep making them better.

Where they are used

Chat assistants, translation, code completion, search, summarisation, speech recognition, and, with images cut into patches, vision models and protein-structure prediction.

Today’s variations

Large models add mixture-of-experts (route each token to a few specialist sub-networks), long-context tricks, and efficient attention. This page shows the plain 2017 idea at small scale.