9 ms·
What are transformer models and how do they work?
- ttul 4y agoAs with most tutorials on Transformers, this one leaves out some essential details: - how are the input encodings generated? - what is in those position vectors? - how are the attention vectors learned? The answer is that these things are all learned as the network is trained; the whole thing is one “thing”. The concept that is most important in understanding neural networks generally is that they start out as just a bunch of random numbers and then the numbers are gradually adjusted until the outputs converge closely enough on the desired loss. I recommend watching Karpathy’s YouTube video where he codes up a Transformer from scratch. It’s the best way to understand these beasts.
- tomcam 4y agoThank you. This one? https://youtu.be/kCc8FmEb1nY https://youtu.be/kCc8FmEb1nY
- totoglazer 4y agoI’m sure that’s the one being referred to. It’s great.
- leobg 4y agoIs that an actual transformer, though? Like with encoder and decoder layers? That’s the part I never truly understood. Or is it “just” an example of a neural network? Thanks!
- tarvaina 4y agoNot all transformers have separate encoders and decoders. GPTs, for instance, only have the equivalents of decoder layers of the original transformer paper, but they are still considered transformers. Karpathy’s video shows an actual GPT-style transformer. I think a neural network can be considered a transformer if it contains a stack of attention blocks as its core mechanism.
- HarHarVeryFunny 4y agoThe original transformer, from the "attention is all you need paper" had an encoder-decoder architecture because it was designed for language translation use where you are mapping one sequence to another, and are able to use both the preceding and following context of words when performing this mapping. The encoder utilizes the forward context. In contrast to seq-2-seq use, for generative language models such as ChatGPT you only have access to preceding (not forward) context in order to decide what to generate next, so the encoder part of the architecture is not applicable and a decoder-only transformer is used.
- seydor 4y agonote that embedding and positional vectors are fixed and not trained with the transformer. The attention vectors are also computed in each step, but what is learned is the transformation of inputs to qvk vectors and the fully connected layers. There are some great people on youtube who explain the series of steps. I think this is the most comprehensive: https://www.youtube.com/watch?v=Nw_PJdmydZY https://www.youtube.com/watch?v=Nw_PJdmydZY
- ttul 4y agoThank you so much for setting me straight. CodeEmporium’s 10-part explainer is so great.
- HarHarVeryFunny 4y agoYes, that's increasingly the case, but there's no fundamental reason for nets to be trained end-to-end as a single entity. Going back a few years it used to be quite common for people to use fixed word embeddings such as word2vec rather than learning them, and for image classification to take an ImageNet-pretrained general purpose model, then freeze the lower convolutional feature-detector layers and only train a new model "head" for more specialized use. End-to-end learnt embeddings are going to be more optimal though, and in the context of these massive models the computational cost of training them is a drop in the bucket!
- posharma 4y agoI found the blogs written by Jay Alammar to be much more informative and complete. It appears that companies are rehashing and compressing the same content to advertise their products.
- macromackie 4y agoI believe Jay actually works at Cohere now (although I’m a little surprised that the post doesn’t state that).
- quantisan 4y agohttps://jalammar.github.io/visualizing-neural-machine-translation-mechanics-of-seq2seq-models-with-attention/ https://jalammar.github.io/visualizing-neural-machine-transl... and https://jalammar.github.io/illustrated-transformer/ https://jalammar.github.io/illustrated-transformer/ for anyone looking
- jaidhyani 4y agoSkimming it, there are a few things about this explanation that rub me just slightly the wrong way. 1. Calling the input token sequence a "command". It probably only makes sense to think of this as a "command" on a model that's been fine-tuned to treat it as such. 2. Skipping over BPE as part of tokenization - but almost every transformer explainer does this, I guess. 3. Describing transformers as using a "word embedding". I'm actually not aware of any transformers that use actual word embeddings, except the ones that incidentally fall out of other tokenization approaches sometimes. 4. Describing positional embeddings as multiplicative. They are generally (and very counterintuitively to me, but nevertheless) additive with token embeddings. 5. "what attention does is it moves the words in a sentence (or piece of text) closer in the word embedding" No, that's just incorrect. 6. You don't actually need a softmax layer at the end, since here they're just picking the top token and they can just do that pre-softmax since it won't change. It's also weird how they talked about this here when the most prominent use of softmax in transformers is actually in the attention component. 7. Really shortchanges the feedforward component. It may be simple, but it's really important to making the whole thing work. 8. Nothing about the residual
- antimora 4y agoI am trying to learn more in depth. Could you suggest some good resource for learning transformers?
- quantisan 4y agothis one's been mentioned a lot: Let's build GPT: from scratch, in code, spelled out. https://youtu.be/kCc8FmEb1nY https://youtu.be/kCc8FmEb1nY
- andai 4y agoThe whole playlist is fantastic: https://youtube.com/playlist?list=PLAqhIrjkxbuWI23v9cThsA9GvCAUhRvKZ https://youtube.com/playlist?list=PLAqhIrjkxbuWI23v9cThsA9Gv...
- andai 4y ago
- dilawar 4y agoThanks. ML noob here. I liked the insight that attention adds context, by modifying the distance in an embedding.
- jaidhyani 4y agoThe way the article presents this is misleading. The attention mechanism builds a new vector as a linear combination of other vectors, but after the first layer these have also all been altered by passing through a transformer layer so it makes less sense to talk about "other tokens" in most cases (it becomes increasingly inaccurate the deeper into the model you go). It's also not really moving closer so much as adding, and what it's adding isn't the embedding-derived-vector but a transform of the embedding-derived-vector after it's been projected into a lower-dimensional-space for that attention head. It would be more accurate to say that it's integrating information stored in other vectors-derived-from-token-embeddings-at-some-point (which can also entail erasing information)
- riffraff 4y agoIsn't "adding" the same as "moving closer" ? E.g. the vector for "bank" is mid-way between the geographical and financial meaning, "bank + money" is closer while "bank + river" if further away.
- jaidhyani 4y agoIt depends on the values of the vectors. (4, 4) + (3, 3) results in a new vector (7, 7) which is further away from both contributing vectors than either one was to each other originally. Additionally, negative coefficients are a thing.
- joaogui1 4y agoYou still have one vector per token, that's what they meant, also the fact that the vector associated with each token will ultimately be used to predict the next token, once again showing that it makes sense to talk about other tokens even though they're being transformed inside the model.
- 1024core 4y ago> Transformers are a new development in machine learning that have been making a lot of noise lately. The paper on transformers was published 6 years ago. 6 years in ML is an eternity nowadays.
- riffraff 4y agoWas there any "big idea" after that? It seems most of the user-visible innovation has been "let's use transformers on more data". Perhaps capsule networks? But those are years old too.
- PeterisP 4y agoNo, not really, there was a lot of engineering work and bunch of not-so-big ideas (e.g. InstructGPT reinforcement learning after the model's training), but you can go from the transformers paper to current state of art without needing a "big idea". And I think this is the major "big idea", accepting the bitter lesson (http://incompleteideas.net/IncIdeas/BitterLesson.html http://incompleteideas.net/IncIdeas/BitterLesson.html) that major user-visible progress and new emerging capabilities doesn't necessarily require any big ideas but simply scaling to more compute.
- mdp2021 4y agoI disagree. And first of all, there is a reflective meta teaching from the very idea of the "Bitter Lessons": the past reveals that (in a way) "the application of models has not been a winner" - but we cannot really know that it is not, because we do not have obtained a model out of it, a model that shows why, an explanation - epistemologically, the "discouraging" protocols cannot be made a "law". Practically, there still is a need to identify the proper architecture(s) to avoid the undesired weaknesses of the attempts in the current stages.
- hnfong 4y agoSomebody had to invest resources into training those super large models and observe emergent intelligent behavior. It's not like the authors of the original paper knew that transformers would lead to GPT-4 and spark an AGI debate. Nobody expected transformers to get powerful so fast.
- ipnon 4y agoAre transformers the new monads?
- shitgoose 4y agono
- p-e-w 4y agoThe more I learn about the technical details of how ML systems are implemented, the more I feel that those details obscure, rather than illuminate, what is actually going on. It's as if we were trying to understand human ethics by looking at neurotransmitters or synapses in the brain. These structures seem way too low-level to actually explain the interesting stuff. What I hear is "something something transformer autoencoder attention [...] MAGIC [...] a machine that speaks like a human". Where is the connection between computational details and the model's high-level behavior? Do we even know? Is there a "psychology of ML models" that develops useful concepts that deal with what a model does, rather than how it functions at the plumbing layer?
- asdfman123 4y agoI agree. Maybe it's because the human mind is good at breaking things into neat modules that fit together hierarchically. We can figure them out piecemeal and eventually grasp the whole system. But messy organic systems are not like that, and we just don't have the hardware to perceive everything at once. Or maybe it's because we have trouble acknowledging that intelligence and consciousness isn't limited to animals, and the human brain doesn't have to epitomize it.
- SanderNL 4y agoWe just don’t know. We can’t even agree on if there is any significant high-level behavior. “It’s alive!” and “stochastic parrot” are still both quite popular in my experience.
- pmoriarty 4y agoThis is called emergent behavior, and we don't know how it happens with organic brains, minds, and neurons either. It's actually pretty amazing that it's happening at all with computers, since neural nets are such simple, high level abstractions compared to how the brain works. It's possible that all the tremendous complexity of organic systems isn't actually necessary for intelligence or consciousnes, which is similarly surprising.
- fruit2020 4y ago
- bighoki2885000 4y ago[dead]
- seydor 4y agoI don't think anyone knows yet why transformers work. "Attention is moving vectors in embedding space" does not make sense. At the moment we know how they multiply vectors and then pass through networks etc, but let's not pretend that we understand how they "work".
- vrglvrglvrgl 4y ago[dead]
- kleiba 4y agoOh, come on - this article is from three days ago, but it starts with "Transformers are a new development in machine learning". Transformers have been around for six years now, that's an eternity when you consider how fast this field is moving.
- fulafel 4y agoDeep learning (multilayer perceptrons) was 1965... The timeline is pretty long.
- kleiba 4y agoMaybe on a theoretical level, but of course you will agree that what we mean by deep learning today has only become possible with the availability of sufficient computational power (and Hinton's work around the mid-2000's).
- fulafel 4y agoThere are lots of important moments I guess, I would credit the main break in practicality to the ~1990 Swiss/German stuff: https://people.idsia.ch/~juergen/deep-learning-miraculous-year-1990-1991.html#Sec.%201 https://people.idsia.ch/~juergen/deep-learning-miraculous-ye... But still even the early perceptrons stuff was applied research, I wouldn't call it purely theoretical by any means.
- kleiba 4y agoI agree about your notion of there being lots of important moments in history, and Schmidhuber's contributions are not small by any means. Yet, 1990 was not the year when Deep Learning took off.
- HarHarVeryFunny 4y agoTrue, yet we're still all here talking about them with plenty of questions and confusion, and people outside of ML are suddenly curious to know what's behind things like ChatGPT, unaware of the history. FWIW one of the founders of Cohere (where this article comes from) was Aidan Gomez who was one of the transformer paper authors.
- denton-scratch 4y ago> In short, text embeddings send every piece of text to a vector (a list) of numbers. What does "sent to" mean? Is that baby-talk for "mapped to"?
- passion__desire 4y agoI sometimes wish why don't mathematical equations come with simple visual examples to help students build mental models (an example here [0]). It is difficult to parse meaning behind equations if written in terse language. [0] Tai-Danae Bradley: "Entropy as an Operad Derivation" https://www.youtube.com/watch?v=_cAEfQQcELA https://www.youtube.com/watch?v=_cAEfQQcELA
- jstx1 4y agoIt's poorly written but yes, an embedding is a representation of text as a list of numbers. [text] --> [ML model] --> [list of numbers]
- radarsat1 4y agoI've been modifying an LSTM GAN model to use a transformer in the encoder and it seems to do much worse. Or at least the training dynamics are very different. Transformers perform great when they work but it seems to be a lot harder to get them to work in my experience. Can anyone corroborate that or is it likely that I'm doing something fundamentally wrong? To be clear I'm not implementing it myself but using PyTorch's Transformer classes as drop-in replacements for my LSTM-based encoder and decoder. Been trying lots of variations in the hyperparameters and position encoding methods etc but it always either doesn't train at all (generator/discriminator divergence) or it produces blurry images. (The "prenet" and "postnet" remain the same as my reference model so I find this surprising.). Really frustrating when all the latest results say that this should work amazingly well. Tons of articles like this on "how transformers work", very few on "tips for getting transformers to work in practice."
- alephxyz 4y agoI'm mostly working on fairly simple image segmentation tasks but in my experience just replacing convolutional layers with attention layers + position embeddings works well. Using convolutional embeddings before the transformer encoder also helps. It still take a lot more epochs to train though, so you might have to decrease the learning rate of your discriminator by a lot.
- radarsat1 4y agoI admit I do run out of patience when it's been running for quite a while and seems to be really far behind the equivalent number of iterations for my LSTM solution. I often stop and adjust things and try again, when maybe it just needs to run longer. I will try that, thanks.
- guy98238710 4y agoThere's one aspect I never saw explained. Why is masking used instead of a sliding window? Why even bother with masking when future tokens can be easily hidden by simply positioning the context window before the current token? Isn't sliding window optimal for maximizing context available to the model? Is masking done because moving the window would impact computational cost or output stability/quality? Can anyone shed light on this?
- remontoire 4y agoI think it's because you want to be able to predict the next token using only 1 token or the whole context window (and any size inbetween). So, you end up getting n different losses for each text snippet (where n is the size of the context window). If i'm wrong, can someone correct here, would be useful to know.
- guy98238710 4y agoWhy would you train the model on shorter context than you can provide? Why not provide all context you have? Sure the model has to learn to handle short context, but that occurs naturally at the beginning of the document. Anyways, this still involves only left-side masking. Why mask future tokens when sliding window can do that (without wasting a single token of context)?
- throwoutway 4y ago> In short, what attention does is it moves the words in a sentence (or piece of text) closer in the word embedding. In that way, the word “bank” in the sentence “Money in the bank” will be moved closer to the word “money”. It's unclear to me. How does this "move" closer? Are the vector positions in the NN changed temporarily and it carries a local copy across the blocks?
- Emanation 4y agoSaying we develop sentences one word at a time seems wrong. Sure, it might appear so when we're writing out text, lag of input, but if you spend any time meditating on your own thoughts it becomes apparent that it's more of chunks of words, clauses, or the idea, that are formed followed by a sweeping compulsion to think the words in their entirety. The concept is conceptualized and then entire phrases resonate with said concet
- victor106 4y agoWe tried cohere for some of our products and it was terrible in generating anything of value. Maybe they will have something better with their later versions but for now this seems like a company built to take advantage of hyped ai keywords
- penciltwirler 4y agoJust read the original paper "Attention Is All You Need". Cohere's founder was the guy who wrote that paper in the first place.