Ask HN: Can someone ELI5 transformers and the “Attention is all we need” paper?
Here is an attempt that sacrifices technical precision for intuition.<p>We&#x27;re going to represent words as vectors (a sequence of numbers). We would like it to be the case that the value of the numbers reflects the meaning of the words. Words that mean similar things should be near each other. We also want to represent higher level ideas, ideas that take multiple words to express, in the same way. You can think of all the possible vectors as the entire space of ideas.<p>To begin with, though, we just have a vector for each word. This is insufficient - does the word &quot;bank&quot; mean the edge of a river or a place to store money? Is it a noun or a verb? In order to figure out the correct vector for a particular instance of this word, we need to take into account its context.<p>A natural idea might be to look at the words next to it. This works okay, but it&#x27;s not the best. In the sentence &quot;I needed some money so I got in my car and took a drive down to the bank&quot;, the word that really tells me the most about &quot;bank&quot; is &quot;money&quot;, even though its far away in the sentence. What I really want is to find informative words based on their meaning.<p>This is what transformers and attention are for. The process works like this: For each word, I compose a &quot;query&quot; - in hand-wavy terms, this says &quot;I&#x27;m looking for any other words out there that are X&quot;.  X could be &quot;related to money&quot; or &quot;near the end of the sentence&quot; or &quot;are adjectives&quot;. Next, for each word I also compute a &quot;key&quot;, this is the counterpart of the query, and says &quot;I have Y&quot;. For each query, I compare it to all the keys, and find which ones are most similar. This tells me which words (queries) should pay attention to which other words (keys). Finally, for each word I compute a &quot;value&quot;. Whereas the &quot;key&quot; was sort of an advertisement saying what sort of information the word has, the &quot;value&quot; is the information itself. Under the hood, the &quot;query&quot;, &quot;key&quot; and &quot;value&quot; are all just vectors. A query and a key match if their vectors are similar.<p>So, as an example, suppose that my sentence is &quot;Steve has a green thumb&quot;. We want to understand the meaning of the word &quot;thumb&quot;. Perhaps a useful step for understanding any noun would be to look for adjectives that modify it. We compute a &quot;query&quot; that says &quot;I&#x27;m looking for words near the end of the sentence that are adjectives&quot;. When computing a &quot;key&quot; for the word green, maybe we compute &quot;I&#x27;m near the end of the sentence, I&#x27;m a color, I&#x27;m an adjective or a noun&quot;. These match pretty well, so &quot;thumb&quot; attends to &quot;green&quot;. We then compute a &quot;value&quot; for &quot;green&quot; that communicates its meaning.<p>By combining the information we got from the word &quot;green&quot; with the information for the word &quot;thumb&quot;, we can have a better understanding of what it means in this particular sentence. If we repeat this process many times, we can build up stronger understanding of the whole sentence. We could also have a special empty word at the end that represents &quot;what might come next?&quot;, and use that to generate more text.<p>But how did we know which queries, keys and values to compute? How did we know how to represent a word&#x27;s meaning as numbers at all? These seemingly impossible questions are what is being &quot;learned&quot;. How exactly that happens would require an equally big explanation of its own.<p>Keep in mind that this explanation is very fuzzy, and is only intended to convey the loose intuition of what is going on. It leaves out many technical details and even gets some details intentionally wrong to avoid confusion.