Transcription
Consider this sentence: The cake was left out in the sun because it melted quickly. Now, what does it refer to here? Does it mean the cake or the sun?
For a human reader, this is straightforward, but for an algorithm, this isn't as simple. When a model processes the word it, self-attention helps it figure out that it refers to the cake.
As the model goes through each word in the sentence, self-attention enables it to look at other positions for clues, helping it build a better understanding of each word. If you're familiar with RNNs, imagine how maintaining a hidden state helps an RNN carry context from previous words as it processes the current word.
In the Transformer, self-attention performs a similar job, letting the model take into account other relevant words when encoding each word it encounters. This approach makes self-attention one of the key reasons Transformers are so good at tasks involving language understanding.