Speaker Notes

Transformers, the tech behind LLMs | Deep Learning Chapter 5

Transformers process text by converting tokens into high-dimensional vectors, passing them through attention and feed-forward layers via matrix multiplications, and outputting next-token probability distributions.

3Blue1Brown · 27:14 · YouTube ↗

Talk · solo speaker  Intermediate · concepts and visual geometry

Highlights

3 clips · 8 min of 27 min
    • Inputs are broken into tokens and mapped to high-dimensional vectors encoding meaning.
    • Attention blocks allow vectors to communicate and update their values based on context.
    • Multi-layer perceptrons apply parallel transformations equivalent to a long list of questions.
    • Computation relies entirely on massive piles of matrix multiplications.
    • Word embeddings map vocabulary tokens to coordinates in a high-dimensional space.
    • Directions in embedding space often capture semantic relationships like gender or geography.
    • Vector arithmetic can reveal conceptual analogies, such as king minus man plus woman.
    • Softmax converts raw unnormalized model outputs into a valid probability distribution.
    • Higher temperatures flatten the distribution for more creative output at the cost of coherence.
    • Lower temperatures concentrate probability on the most likely next token for predictable text.

Questions this video answers

10 · every answer cites the moment it was said
01 How do transformers generate text if they are just predicting the next word? 1 source · 1:52

Transformers take an initial snippet and output a probability distribution for the next chunk of text. By repeatedly sampling from this distribution, appending the result, and feeding it back in, the model generates longer text.

02 What is the high-level role of an attention block in a transformer? 2 sources · 3:55

The attention block allows vectors to talk to each other and pass information back and forth. It determines which words in context are relevant to updating the meanings of other words.

03 How do multi-layer perceptron blocks process vectors compared to attention blocks? 2 sources · 4:35

Unlike attention blocks where vectors talk to each other, multi-layer perceptron or feed-forward blocks process all vectors in parallel through the same operation. They update vectors based on answering a long list of questions about each one.

04 What format must input data take for deep learning models to function? 2 sources · 9:41

Input data must be formatted as an array of real numbers, often referred to as a tensor. This data is progressively transformed through distinct layers of weighted sums and non-linear functions.

05 How are words initially converted into vectors in a transformer? 2 sources · 12:55

Words or tokens are mapped using a predefined vocabulary and an embedding matrix. Each column in the embedding matrix corresponds to a word and determines the high-dimensional vector it turns into.

06 What kind of semantic meaning do word embedding dimensions capture during training? 2 sources · 14:28

During training, models learn embeddings where specific directions in the high-dimensional space encode semantic meanings like gender or geography. This allows vector arithmetic, such as finding similarities between related concepts.

07 How can dot products be used geometrically to measure word relationships? 2 sources · 16:37

The dot product of two vectors measures how well they align by multiplying corresponding components and adding the results. Geometrically, it is positive when vectors point in similar directions and zero if they are perpendicular.

08 How does the unembedding matrix produce a probability distribution from the final vector? 2 sources · 20:51

The unembedding matrix maps the final vector in the context to a list of values for each token in the vocabulary. This raw output is then normalized into a probability distribution using the softmax function.

09 What is the function of the softmax operation in the network? 2 sources · 22:55

Softmax converts an arbitrary list of negative or unnormalized numbers into a valid probability distribution where values range between zero and one and sum to one. Larger input values end up closest to one while smaller values approach zero.

10 How does adjusting the temperature parameter affect token generation? 2 sources · 24:14

A higher temperature adds weight to lower values, making the probability distribution more uniform and introducing creative or unpredictable choices. Conversely, a lower temperature causes larger values to dominate more aggressively for more predictable outputs.

Section-by-section summary

5 parts

Transformers as next-token prediction engines

Transformers are neural networks that generate text by repeatedly predicting the probability distribution of the next token. By sampling from this distribution and feeding the result back into the input, the model can generate coherent multi-word outputs.

The end-to-end architecture preview

Input text is tokenized and embedded into vectors, which then alternate between attention blocks and feed-forward layers. The final vector is projected back into vocabulary space to predict the next token probabilities.

Deep learning foundations and scale

Deep learning models rely on backpropagation to tune billions of parameters formatted as weights. These weights interact with processed data exclusively through weighted sums and matrix vector multiplications.

Token embeddings and geometric semantics

The embedding matrix maps each vocabulary token to a high-dimensional vector. During training, the model organizes these vectors so that geometric directions encode meaningful semantic relationships between concepts.

Unembedding matrices and probability generation

The unembedding matrix maps the final context vector to raw scores called logits for every token in the vocabulary. The softmax function then normalizes these scores into probabilities, modulated by a temperature parameter.

0:00 / 27:14
k play/pause · f fullscreen · m mute
n next · p previous clip · t highlights/full
< > slower/faster · / search what was said
  • Transformer11× · first 0:00

    A specific kind of neural network architecture underlying modern generative AI models.

  • Token8× · first 3:19

    A small chunk of text, image, or sound used as input units for a model.

  • Attention block4× · first 3:55

    An operation that allows vectors to talk to each other and update their meanings based on context.

  • Multi-layer perceptron3× · first 4:35

    A block where vectors independently pass through the same operation in parallel.

  • Embedding matrix4× · first 13:03

    A matrix with columns that determine the high-dimensional vector representation for each token in the vocabulary.

  • Dot product3× · first 16:37

    A mathematical operation measuring how well two vectors align by multiplying components and summing them.

  • Unembedding matrix2× · first 21:45

    A matrix that maps the final vector in a context to a list of values for each token in the vocabulary.

  • Softmax4× · first 21:12

    A function that normalizes an arbitrary list of numbers into a valid probability distribution.