Skip to content

Self-Attention

An attention mechanism where each element in a sequence looks at all other elements in the same sequence. For text: each word relates to every other word.

What It Is

Previously, models read text in order, and distant connections were lost. Self-attention looks at the entire text at once:

"The cat chased the mouse because she was hungry."

The model understands: "she" refers to "cat", not "mouse", — because attention connects words directly.

How It Works

For each word, the following are calculated:

  • query — "what I am looking for";
  • key — "what I can offer";
  • value — "what I carry in meaning".

The degree of "attention" a word pays to others is calculated based on the proximity of query and key.

Importance

Self-attention is a key idea in Transformer and all modern LLM. Without it, there would be no ChatGPT or Claude.

See Also

← All terms