How Transformers Work
Another horrible and misleading description that I cannot imagine had a single machine learning person in the loop.<p>TLDR: They say that transformers are pretrained word embeddings with one round of self attention that predict the next word sequence by beam search. They aren&#x27;t any of those things.<p>Why start with word embeddings? The authors think that you first train word embeddings and then use them as the input for your Transformer. Nope.<p>&gt; A word embedding can have hundreds of values, each representing a different aspect of a word’s meaning. Just as you might describe a house by its characteristics — type, location, bedrooms, bathrooms, storeys — the values in an embedding quantify a word’s linguistic features.<p>No. That&#x27;s literally not what a word embedding is! It&#x27;s completely the wrong intuition. It mixes up a semantic representation with the distributional hypothesis. These are two completely different ideas. Word embeddings are not describing words by their characteristics, exactly the opposite! They abandon that idea. To say that this is true but we just don&#x27;t know what the characteristics being described are is just a total confusion about what is happening.<p>&gt; Self-attention looks at each token in a body of text and decides which others are most important to understanding its meaning.<p>Why even introduce the word token here? When it&#x27;s not explained at all. Just say word. And no, self attention does not decide which words are important for the meaning of this word, it&#x27;s which other inputs are important to carry out some task. &quot;meaning&quot; is not a thing. Also, that&#x27;s just attention. Where&#x27;s the self part friends!? It sounds like they think self attention refers to a word itself paying attention. Things are getting dicey.<p>&gt; With self-attention, the transformer computes all the words in a sentence at the same time. Capturing this context gives LLMs far more sophisticated capabilities to parse language.<p>Well, for one thing there&#x27;s masked attention. For another, this isn&#x27;t a property of self-attention. It&#x27;s a property of how Transformers split apart attention and the positional feed forward layers. But I&#x27;m sure we&#x27;ll talk about that (spoiler: we won&#x27;t, things fall apart dramatically shortly; the authors don&#x27;t understand anything).<p>&gt; Transformers process an entire sequence at once — be that a sentence, paragraph or an entire article — analysing all its parts and not just individual words.<p>They just talked about an RNN that process words. And all of their parts. Also there are bidirectional RNNs. This comparison is nonsense. They should just not talk about RNNs if they can&#x27;t say anything reasonable.<p>&gt; This allows the software to capture context and patterns better, and to translate — or generate — text more accurately. This simultaneous processing also makes LLMs much faster to train, in turn improving their efficiency and ability to scale.<p>Ironically, they managed to identify the one part of LLMs that is slowest and most problematic as the part that is the fastest. A whole lot of papers focus on making attention faster because it&#x27;s the computational bottleneck of Transformers; very funny to call that what makes them faster to train. Also, faster to train than what!? RNNs just don&#x27;t scale up well (traditionally, let&#x27;s not get into newer models). So it&#x27;s not a matter of faster, it&#x27;s a matter of, we couldn&#x27;t train large models before at all.<p>Then there&#x27;s a whole lot of &quot;it does X, Y, and Z&quot;, no idea what in their story would make anyone think the models should ever do that.<p>&gt; From this enormous corpus of words and images, the models learn how to recognise patterns and eventually predict the next best word.<p>Huh? How&#x27;d we sneak this one in? So the story they&#x27;re telling is: we learn word embeddings, then we self attend to them which means looking at how other words related to them, and then that model learns to predict the next best word? Wow, it&#x27;s like watching a blender process ideas into goo.<p>&gt; After tokenising and encoding a prompt, we’re left with a block of data representing our input as the machine understands it, including meanings, positions and relationships between words.<p>tokenising!? encoding a prompt!? Where&#x27;d this come from. I love how we start the sentence with &quot;tokenizing&quot; and end it with &quot;words&quot;, just a total confusion of ideas.<p>A block of data encoding the text as the machine understands it. Look at that beautiful block of data! A beautiful block of data that comes from.. word embeddings + positional encoding (huh? never talked about this one either) + self attention. Because, that&#x27;s all there is to transformers.<p>Just some self attention, one round of it. On top of word embeddings.<p>That&#x27;s the message. That&#x27;s total and complete gibberish.<p>&gt; At its simplest, the model’s aim is now to predict the next word in a sequence and do this repeatedly until the output is complete.<p>What is there to predict? In the story they&#x27;ve told I have pretrained word embeddings and self attention.<p>&gt; To do this, the model gives a probability score to each token, which represents the likelihood of it being the next word in the sequence.<p>A &quot;probability score&quot;!? My inner statistician just took their own life. The next word in the sequence!? They&#x27;re mixing up decoders with masked word prediction.<p>&gt; With beam search, the model is able to consider multiple routes and find the best option.<p>Why!? Why talk about beam search? Who told them about beam search? Most models do something called top-p not beam search these days. But that&#x27;s such a minor and worthless detail.<p>&gt; This produces better results, ultimately leading to more coherent, human-like text.<p>I wish human-like text was coherent.<p>So there you have it. Transformers are pretrained word embeddings with one round of self attention that predict the next word sequence by beam search. <i>cry</i>