7 ms·
The Yannic kilcher review is quite good. https://youtu.be/iDulhoQ2pro https://youtu.be/iDulhoQ2pro I can't ELI5 but I can ELI-junior-dev. Tl;dw: Transformers
by throwawaymaths 3y ago
The Yannic kilcher review is quite good.
https://youtu.be/iDulhoQ2pro 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 "performing the lookup query" over all other tokens in the attention frame, so every token gets a "contextual semantic understanding" that takes in both all the other stuff in the attention frame and it's relative position.
Gpt is impressive because the N is really huge and it has many layers. A big N means you can potentially access information farther away. Each layer gives more opportunities to summarize and integrate long range information in a fractal process.
Two key takeaways:
- differentiable hash tables
- encoding relative position using periodic functions
NB: the attention frame tokens are actually K-vectors (so the frame is a KxN matrix) and the query matrix is an NxNxK tensor IIRC but it's easier to describe it this way
- rekttrader 3y agoI came here to post this video. It’s a great primer on the topic and it gives you ideas to prompt gpt and have it output more. It’s how I got an understanding of beam search, a technique employed in some of the response building.
- jimkleiber 3y agoI had to look up "tl;dw" and realized it meant "too long; didn't watch" and not my first AI-laden instinct of "too long, didn't write" :-D
- sva_ 3y agoOne thing that might be worth pointing out is that the transformer architecture owes a great deal of its success to the fact that it can be implemented in a way that it can be massively parallelized in a very efficient manner.
- throwawaymaths 3y agoCompared to rnns... maybe? The big nxn is really a killer. I don't know how to judge parallelizability of different DNN models, you're comparing apples to oranges
- Salgat 3y agoWhen 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.
- saynay 3y agoI 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.
- throwawaymaths 3y agoI don't really believe this because in theory it's possible to split up training of arbitrary neural nets using decoupled neural interfaces (not that it's easy mind you) but at the point where you have openAI scale resources the bottleneck to achieving that is the difficulty of Python.
- golly_ned 3y agoWhat’s a neural interface?
- throwawaymaths 3y agohttps://arxiv.org/abs/1608.05343 https://arxiv.org/abs/1608.05343
- zorr 3y agoHow does N relate to the number of parameters that is frequently mentioned?
- throwawaymaths 3y agoIn my screed, N is the attention width. (How many token it looks at at a time) number of parameters is O(KxNxNxL) where k is the vector size of your tokens, and l is the # of layers. There are other parameters floating around, like in the encoder and decoder matrices, but the NXN matrix dominates.
- 8thcross 3y agoThis is an awesome explanation. You guys are the real heroes
- kenjackson 3y agoWhat does it mean for a lookup/hash table to be differentiable?
- weinzierl 3y agoI 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?
- kccqzy 3y agoSame thing. You need everything to be differentiable in order to run gradient descent. To first approximation, training a neural network is just gradient descent.
- visarga 3y agoThe neural net is just a math function, continuous even, fully differentiable in all input points. In order to "learn" anything we compute gradients towards the function parameters. They get "nudged" slightly towards a better response, and we do this billions of times. It's like carving a raw stone block into a complex scene. If you put your data into the system it flows towards the desired output because the right path has been engraved during training. <rant> This explains a bit how neural nets work but from this to chatGPT is another whole leap. You'd have to assign some of the merits of the AI to the training data itself, it's not just the algorithm for learning, but what is being learned that matters. The neural net is the same, but using 1T tokens of text is making it smart. What's so magic about this data that it can turn a random init into a language programmable system? And the same language information make a baby into a modern human, instead of just another animal. </>
- bjourne 3y agoNo, it's the loss function we differentiate. The input to the loss function are the network weights. The input to the network are samples and those we do not differentiate.
- dpcx 3y agoI appreciate the explanation, but I don't know what junior-dev would understand most of this. I may be just a web developer, but I couldn't understand most of this. I'd still have to read for 30m to grok it all.
- throwawaymaths 3y agoYeah sorry, it still requires math and probably some exposure to ML basics.
- shadowgovt 3y agoI think one hole in the description for simplicity is that "differentiable" it's not an adjective that applies to hash tables. Differentiable relative to what? What is (x) in the d(hashtable)/d(x) equation?
- lhnz 3y agoI think it applies because lookups can be done by multiplying one-hot vectors (or masks) with matrices; this is roughly analogous to what happens when we multiply Q with K^T in a self-attention head. Read this: https://e2eml.school/transformers.html#table_lookup https://e2eml.school/transformers.html#table_lookup And then read: https://e2eml.school/transformers.html#attention https://e2eml.school/transformers.html#attention Matrix multiplication is differentiable as it is continuous. Therefore you can calculate partial derivatives of these operations. The ability to do that is what allows gradient descent optimization via the chain rule. > Differentiable relative to what? > What is (x) in the d(hashtable)/d(x) equation? I think the derivative we actually care about is `∂L/∂(hashtable-lookup)` but here the `hashtable-lookup` is actually the matrix multiplication mentioned above. We want to know how much the "loss" (or error) changes with respect to each of our "lookups". Knowing how each of our "lookups" causes our model to err from the output we expect, allows us to optimise it. Note: it's not really a "lookup" in the normal sense of the word. Hashtable lookups are discontinuous since we either have a value for a particular key or we do not. Our matrix multiplication is sort of like a fuzzy, probabilistic, continuous form of lookup in which nearby keys get partially activated based on their similarity to the query, and in which a small change in this query causes continous changes to the keys produced. As far as my understanding of the self-attention equation (e.g. `softmax(QK^T / sqrt(d_k))V`) goes, its actually quite important that we get this fuzzy output in which lots of keys get partially activated for a particular query. If it only picked the maximum similarity and ignored the rest, there would be less information propagating through the network and it'd be harder for the network to learn relationships/interactions between inputs. This is why we scale `QK^T` by `sqrt(d_k)` in order to pass a tighter range of values into the `softmax()` function (which importantly generates probabilities that sum to 1, but contains exponentials which give it a tendency to over-emphasize the maximum value and ignore other values if they are too far apart).
- ogoparootbbo2 3y agowhat is a differentiable hash table? I understand differentiation, I don't understand differential hash table ... does that mean for every tiny gradient of a key, a corresponding gradient in value can be expected?
- legalizemoney 3y agoHaving read the paper myself, I'm impressed with the quality of your explanation. Well done!