Definition

Self-Attention

Self-attention updates each token’s representation using other positions in the same sequence. It compares a query at the current position with keys at permitted positions, then uses the resulting weights to combine their values. Masks determine which positions are visible. A causal decoder excludes future positions.

Combine two values using attention weights

Take two visible positions with scaled scores ln(2) and 0. Their exponentials are 2 and 1, so softmax assigns weights 2/3 and 1/3. If the value vectors are simplified to the scalars 6 and 0, their weighted sum is 4. A causal mask removes any position to the right of the current token from that calculation.

Scaled dot-product attention in the Transformer paper

Intelligence at Scale by Shashank Agarwal

Self-Attention diagram from Intelligence at Scale
Diagram from chapter 3, Attention Is All You Need

Explained in

Chapter 3: Attention Is All You Need Free

The paper behind every major AI model today. Google invented it. Then watched someone else ship it.

Related terms

This is one term. The chapter is the argument.

Intelligence at Scale: 22 chapters, 65,000 words, 80-plus diagrams. Kindle, paperback and hardcover on Amazon.

Buy on Amazon.com
← All terms