Attention
A mechanism by which the model selects which words in the text to pay more attention to in order to correctly understand the meaning.
Why is this needed
Before the advent of attention, texts were processed in order. The problem: the further the words, the worse the model sees their connection.
Attention solves this differently: the model looks at the entire text at once and decides for itself what is connected to what.
How it works with an example
Take the phrase:
"The cat drinks milk because he is hungry."
Who is "he"? The model compares the word "he" with all the words and assigns weights:
| Word | Importance for "he" |
|---|---|
| Cat | 0.82 |
| milk | 0.05 |
| hungry | 0.08 |
The highest weight is for "cat" — so the model connects them.
Types of attention
- Self-Attention — words relate within one text;
- Multi-Head Attention — several "heads" search for different types of connections;
- Cross-Attention — connection between different sequences.
Why is this important
Attention is the heart of the Transformer architecture, on which all modern LLMs are built.