Attention Pulls Words Toward Their Meaning
Embeddings are the bridge between words and numbers. Every word becomes a list of numbers, a vector, and similar words get similar numbers. In a toy two-dimensional embedding, banana sits at 6, 5, fruits cluster in one corner, sports in another, vehicles in a third. Real embeddings use up to 4096 numbers per word, and each number captures something about the word, size or color or some pattern the computer noticed that we cannot name. The better the embedding, the easier every later step becomes.
But embeddings have a blind spot: words with more than one meaning. Apple is a fruit and a brand, and a single point in space cannot be both. Put it somewhere in the middle and the model is stuck. Attention fixes this by using context. In please buy an apple and an orange, the word orange tells you it is a fruit. In Apple unveiled a new phone, the word phone tells you it is a brand. Attention lets the other words in the sentence pull the ambiguous word toward the right meaning.
Luis Serrano pictures it as gravity. Words are points in space, and similar words pull each other closer. Apple starts at 6, 7, unsure. Orange sits at 11, 11 and phone at 1, 2. In the fruit sentence, orange pulls apple toward itself, and the model uses the new coordinates, around 8, 8.5, instead of the old ones. In the brand sentence, phone pulls apple the other way, to around 4, 5. Repeat that pulling many times through the model and apple ends up deep in fruit territory in one sentence and deep in technology territory in the other.
Apple x-coordinate after attentionData from the sources listed below.
That is all the attention mechanism does, at heart: a few mathematical operations that move words toward the words that explain them. The famous query, key, and value matrices are the machinery behind the pulling, but the idea is geometric. Words gravitate toward each other, and the model reads the new positions instead of the old ones. Context is not a separate feature bolted on. It is the embedding itself, reshaped by the sentence around it.
This is why attention was the step that let LLMs take off. Before it, a model read a few words at a time and guessed. With it, the whole sentence shapes every word in it, so the model can tell a fruit from a brand, a pronoun from its noun, a verb from its subject. The paper that introduced it, Attention Is All You Need, also introduced the transformer, and the two ideas have been inseparable ever since.
Try this
bashpip install numpy python -c "import numpy as np; print(np.dot([6, 7], [11, 11]))"
Sources
- Source: The Attention Mechanism in Large Language Models - Luis Serrano Academy
