Vibeleaderboard
← All Intel
Intel / article

Some Intuition on Attention and the Transformer

Source
eugeneyan.com
Author
Eugene Yan
Date
Photo by Des Récits on Unsplash

Context

builds a representation of a word or text fragment using information from other positions in the sequence. Eugene Yan's intuitive explanation introduces three numerical representations: a query for the position being updated, keys used to calculate relevance and values containing the information to combine.

The original Transformer paper makes the operation precise: comparisons between queries and keys produce weights, and those weights determine how much each value contributes to the result. This lets a position incorporate from elsewhere in the text. In the paper's decoder, attention is restricted to available output positions, and generation proceeds one symbol at a time.

Terms in this piece · Glossary
  • attention — The mechanism that lets a model weigh which earlier words matter for the word it's currently processing — the core operation of a transformer.
  • transformer — The neural network architecture behind modern AI models, built on attention — letting every word directly consider every other word in parallel.
  • context window — The maximum amount of text a model can consider at once — its working memory for the current conversation or task.
Key quotes

“Via this approach, the encoder had to cram the entire input into a fixed-size vector which is then passed to the decoder—this single vector had to convey everything about the input sentence!”

Eugene Yan

“Because we use the softmax function in attention, it amplifies the highest value while squashing the lower ones. As a result, each head tends to focus on a single element.”

Eugene Yan

“Because attention acts as a filter, it blocks most information from passing through.”

Eugene Yan

“The Transformer is a magnificient neural network architecture because it is a general-purpose differentiable computer.”

Andrej Karpathy

“Stacking attention layers also broadens the model’s receptive field. The first attention layer produces context vectors by attending to interactions between pairs of words in the input sentence. Then, the second layer produces context vectors based on pairs of pairs, and so on.”

Eugene Yan
Read the source eugeneyan.com
More from Eugene Yan
Recommended reads
Comments

Checking sign-in…

Loading comments…