Ask HN: Can someone ELI5 transformers and the “Attention is all we need” paper?
61–70 of 240 posts
Re: Ask HN: Can someone ELI5 transformers and the “Attention is all we need” paper?
#62The Yannic kilcher review is quite good. https://youtu.be/iDulhoQ2pro I can't ELI5 but I can ELI-junior-dev. Tl;dw: Transformers work by basically being a differentiable lookup/hash table. First your input is tokenized and (N) tokens (this constitutes the attention frame) are encoded both based on token identity and position in the attention frame. Then there is an NxN matrix that is applied to your attention frame "…
What does it mean for a lookup/hash table to be differentiable?
https://en.wikipedia.org/wiki/Differentiable_programming
See automatic differentiation.
Re: Ask HN: Can someone ELI5 transformers and the “Attention is all we need” paper?
#63Earlier quoted context omitted.
When you train a transformer, you're training what the next expected token is. You can train all positions of the sequence each in parallel rather than having to sequentially build up the memory state as you generate the sequence with an LSTM. Mind you the inference portion of a transformer is still sequentially bottlenecked since you don't know what the output sequence is supposed to be.
I believe the other big thing is it allowed you to parallelize the training as well, so you could split those colossal training sets across many machines in a way you could not do with LSTMs.
Re: Ask HN: Can someone ELI5 transformers and the “Attention is all we need” paper?
#64Transformers are about converting some input data (usually text) to numeric representations, then modifying those representations through several layers to generate a target representation. In LLMs, this means go from prompt to answer. I'll cover inference only, not training. I can't quite ELI5, but process is roughly: - Write a prompt - Convert each token in the prompt (roughly a word) into numbers. So "the" might m…
I don't think this description of attention is correct.
It's really oversimplified, as I mentioned. A more granular look is:
- Project the vectors with a linear regression. In decoder-only attention (what we usually use), we project the same vectors twice with different coefficients. We call the first projection queries, and the second keys. This transforms the vectors linearly.
- Find the dot product of each query vector against the key vectors (multiply them)
- (training only) Mask out future vectors, so a token can't look at tokens that come after it
- At this point, you will have a matrix indicating how important each query vector considers each other vector (how important each token considers the other tokens)
- Take the softmax, which both ensures all of the attention values for a vector sum to 1, and penalizes small attention values
- Use the softmax values to get a weighted sum of tokens according to the attention calc.
- This will turn one vector into the weighted sum of the other vectors it considers important.
The goal of this is to incorporate information from multiple tokens into a single representation.Re: Ask HN: Can someone ELI5 transformers and the “Attention is all we need” paper?
#65Feedforward: y=Wx Attention: y=W(x)x W is Matrix, x & y Are vectors. In the second case, W is a function of the input.
You must be from a planet with very long years! There is no way I can even begin to digest what you have said in your comment.
Re: Ask HN: Can someone ELI5 transformers and the “Attention is all we need” paper?
#66The Yannic kilcher review is quite good. https://youtu.be/iDulhoQ2pro I can't ELI5 but I can ELI-junior-dev. Tl;dw: Transformers work by basically being a differentiable lookup/hash table. First your input is tokenized and (N) tokens (this constitutes the attention frame) are encoded both based on token identity and position in the attention frame. Then there is an NxN matrix that is applied to your attention frame "…
How does N relate to the number of parameters that is frequently mentioned?
Re: Ask HN: Can someone ELI5 transformers and the “Attention is all we need” paper?
#67Earlier quoted context omitted.
What does it mean for a lookup/hash table to be differentiable?
I wanted to ask the same and especially I've always been wondering: How is the meaning of aforementioned 'differentiable' related to the same term in math?
Re: Ask HN: Can someone ELI5 transformers and the “Attention is all we need” paper?
#68The Yannic kilcher review is quite good. https://youtu.be/iDulhoQ2pro I can't ELI5 but I can ELI-junior-dev. Tl;dw: Transformers work by basically being a differentiable lookup/hash table. First your input is tokenized and (N) tokens (this constitutes the attention frame) are encoded both based on token identity and position in the attention frame. Then there is an NxN matrix that is applied to your attention frame "…
What does it mean for a lookup/hash table to be differentiable?
Re: Ask HN: Can someone ELI5 transformers and the “Attention is all we need” paper?
#69We'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.
To begin with, though, we just have a vector for each word. This is insufficient - does the word "bank" 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.
A natural idea might be to look at the words next to it. This works okay, but it's not the best. In the sentence "I needed some money so I got in my car and took a drive down to the bank", the word that really tells me the most about "bank" is "money", even though its far away in the sentence. What I really want is to find informative words based on their meaning.
This is what transformers and attention are for. The process works like this: For each word, I compose a "query" - in hand-wavy terms, this says "I'm looking for any other words out there that are X". X could be "related to money" or "near the end of the sentence" or "are adjectives". Next, for each word I also compute a "key", this is the counterpart of the query, and says "I have Y". 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 "value". Whereas the "key" was sort of an advertisement saying what sort of information the word has, the "value" is the information itself. Under the hood, the "query", "key" and "value" are all just vectors. A query and a key match if their vectors are similar.
So, as an example, suppose that my sentence is "Steve has a green thumb". We want to understand the meaning of the word "thumb". Perhaps a useful step for understanding any noun would be to look for adjectives that modify it. We compute a "query" that says "I'm looking for words near the end of the sentence that are adjectives". When computing a "key" for the word green, maybe we compute "I'm near the end of the sentence, I'm a color, I'm an adjective or a noun". These match pretty well, so "thumb" attends to "green". We then compute a "value" for "green" that communicates its meaning.
By combining the information we got from the word "green" with the information for the word "thumb", 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 "what might come next?", and use that to generate more text.
But how did we know which queries, keys and values to compute? How did we know how to represent a word's meaning as numbers at all? These seemingly impossible questions are what is being "learned". How exactly that happens would require an equally big explanation of its own.
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.
Re: Ask HN: Can someone ELI5 transformers and the “Attention is all we need” paper?
#70The Yannic kilcher review is quite good. https://youtu.be/iDulhoQ2pro I can't ELI5 but I can ELI-junior-dev. Tl;dw: Transformers work by basically being a differentiable lookup/hash table. First your input is tokenized and (N) tokens (this constitutes the attention frame) are encoded both based on token identity and position in the attention frame. Then there is an NxN matrix that is applied to your attention frame "…
What does it mean for a lookup/hash table to be differentiable?