LLMs

Self-attention

Self-attention mixes information among positions in the same sequence.

ThecatsatThe.70.20.10cat.15.60.25sat.10.65.25Each row sums to 1. "sat" attends most to "cat".
Self-attention mixes information among positions in the same sequence. Values shown in the worked visual are illustrative unless the labels state otherwise.

How it works

Each position scores other positions using query-key similarity and combines their value vectors. The learned weights make the context-dependent mixture explicit.

A concrete example

Illustrative: one token assigns weights [0.05, 0.15, 0.70, 0.10] across four positions.

Do not confuse it with Cross-attention

self-attention reads the same sequence; cross-attention reads another sequence or modality.

Study the full lesson