Transformers, the tech behind LLMs | Deep Learning Chapter 5
Topic How a GPT-style transformer takes in text and produces a next-token prediction: embeddings, unembedding, softmax and temperature, plus the deep-learning background needed before attention
Excellent intuition-first foundation for the transformer's input and output ends, with GPT-3 parameter counting. But the title promises 'the tech behind LLMs', and the attention block, the MLP block and training are all deferred to later chapters.
What is covered
- Next-token generation loop The model outputs a probability distribution over tokens. Repeatedly sampling from it and appending the sample yields text. GPT-2 gave a nonsensical story, while the much bigger GPT-3 gave a sensible one.
- High-level data flow Tokens become vectors, then alternating attention blocks and multi-layer perceptron blocks process them. A final operation on the last vector gives the distribution. Chatbots are built by prepending a system prompt.
- Deep learning format and weights Inputs are arrays of real numbers (tensors), and weights interact with data only through weighted sums packaged as matrix-vector products. GPT-3's 175B weights sit in just under 28,000 matrices. Weights are contrasted with data, and linear regression is the toy example.
- Embeddings and geometry An embedding matrix W_E of 50,257 tokens by 12,288 dimensions (about 617M weights) maps tokens to vectors. Directions carry meaning, as in the woman-minus-man and Italy-minus-Germany examples, and the queen example is shown not to work perfectly. Dot products measure alignment and are tested on a plural direction.
- Context size, unembedding, softmax and temperature The context size is 2048. The unembedding matrix W_U adds another 617M weights. Softmax is explained as exponentiate then normalize, and temperature T is demonstrated at different settings. Logits are defined.
What is missing
- Tokenization mechanics Tokens are described only as 'words or pieces of words', with no explanation of how the vocabulary is built (for example byte-pair encoding). Viewers are left with no idea why the vocabulary has 50,257 entries or why models stumble on spelling and numbers.
- Attention, MLP, positional encoding and training These are the core mechanisms of a transformer, but the video explicitly defers them to later chapters. Someone judging the title alone would not learn how the transformer actually works.
- Limits of the embedding-arithmetic intuition The video notes that the queen example is imperfect, but it never explains that these analogies are cherry-picked, or that static word vectors cannot separate the senses of a word before attention adds context.
What to add
- How tokens are actually built Learn how a tokenizer is trained on text by repeatedly merging the most frequent adjacent character pairs into new tokens. This explains why common words are single tokens while rare words split into pieces, and why spelling, arithmetic and non-English text can be awkward for these models.
- Other sampling strategies Temperature is only one of the controls used at generation time. Top-k and top-p (nucleus) sampling restrict which candidates can be chosen, and greedy decoding always takes the top one. Together these explain why the same prompt can produce different outputs.
- From base model to assistant The video mentions only the system-prompt trick. Real chatbots are made through additional training, including supervised fine-tuning on example conversations and reinforcement learning from human feedback. This is the part that turns a text autocompleter into an assistant.
Where to look next
- 3Blue1Brown Deep Learning Chapter 6: Attention in transformers The direct continuation of this video, covering the attention mechanism.
- Attention Is All You Need (Vaswani et al., 2017) The original transformer paper, which this video only refers to as the 2017 Google invention.
- Andrej Karpathy: Let's build GPT from scratch Hands-on coding of a small GPT that complements this visual explanation.
- Andrej Karpathy: Let's build the GPT Tokenizer A detailed treatment of byte-pair encoding, which fills the tokenization gap.
- Search: byte pair encoding tokenization explained Quick sources on how a vocabulary of subword tokens is created.