The potential of transformers in reinforcement learning
lorenzopieri.com
lorenzopieri.com
So far they can handle: text, image, video, code, proteins and now planning and behavior. It's like a universal algorithm for learning and reminds me of the uniformity of the brain. Hope we're going to see much more efficient hardware implementations in the future.
I think I’d do better with pseudo code or a toy example.
For more simplified look at embeddings, I would look at Word2Vec (although, it doesn't involve transformers). It encodes single words, instead of entire phrases, and does so by looking at their relative position to other words while being trained.
Embeddings are just vectors, and so you can do math or compare them to other embeddings. The famous example is E(king) - E(man) + E(woman) = E(queen)
The process of encoding the input data stream to an embedding is done by a NN. The part that tripped me up when I was first trying to understand it is that the encoding is not like encoding elsewhere in compsci. It isn't trying to convert the input to a well-known encoding format or anything. The "encoder" is just the name of the neural-net that is converting the big, multi-dimensional input into a single-dimension, fixed-length vector. The "decoder" is just the neural-net that converts it to output. That fixed-length vector is entirely meaningless to anything other than the two neural-nets trained to generate/consume it.
So what’s the point of the encoding and decoding steps?
Then the transformer is just another neural net in between that does some funny business with attention?
A transformer block is usually the above operation, and then it immediately runs the result through a high-dimensional MLP ending with a layer with dimension d. And it will usually use multi-head attention which splits the input d-dimensional representation into m splits along the d axis (so that you end up with m 10 x m/d vectors) and then does the above calculation on each of the m inputs using layer- and head-specific QKV matrices, and then recombines all the results along the d axis to recover the 10 x d representation. It can be confusing when you read code that does this because it’s all vectorized and the splitting and head-specific matrices are implicit.
* after dividing by the square root of d. this reduces absolute value of the inputs to the softmax and mitigates an issue that softmax has with gradients on large inputs becoming 0 on limited precision floating points.
You can think of finite state machines as being two functions: f(input, state) = output, and g(input, state) = next_state. (Traditional FSMs have 3 ‘output’ states, basically ‘terminated - success’, ‘terminated - failure’, and ‘still working’, but in theory it makes sense to fully generalize it).
If you think about plain neural networks as approximating arbitrary functions f(input) = output, then recurrent neural networks are “continuous state machines”, where you have the same two functions f(input, state) = output, and g(input, state) = next_state, except instead of being finite symbols, they’re continuous points in N dimensional space. This, at least to me, clarifies why recurrent neural networks work on simple and short time-based problems, but can’t efficiently generalize to complex problems—they’re just FSMs!
The paper I linked above provides a similar high-level computational analogy to how transformers work.
link: https://e2eml.school/transformers.html
discussion here: https://news.ycombinator.com/item?id=29315107
https://www.youtube.com/watch?v=iDulhoQ2pro
Yannic has been making about 62 other transformer paper reviews since. You can find the usual suspects.
https://www.youtube.com/watch?v=u1_qMdb0kYU&list=PL1v8zpldgH...
- https://jalammar.github.io/illustrated-transformer/
- HN post for the article: https://news.ycombinator.com/item?id=18351674