"Ravi said he is going to his school"
When you read the word "he" — your brain immediately thinks: "he = Ravi"
When you read "his" — again your brain says: "his = Ravi's"
How did your brain do this? You looked back at the other words and figured out which word is connected to which. You paid attention to "Ravi" when reading "he."
Self-attention is exactly this — every word looks at every other word in the sentence and asks: "How much should I care about you?"
Imagine you're at a wedding party 🎉
There are 100 people in the hall. You walk in, and your eyes scan the room. You're looking for people who are relevant to you:
You don't give equal attention to everyone. You focus more on people who matter to you.
Self-attention does the same thing for words. Every word scans all other words and decides: