1. Home
  2. 3Blue1Brown

Mar 31, 2024

Inside the Transformer: what the T in GPT actually does

27 min → 1:34

Overview

3Blue1Brown visually explains the Transformer neural network architecture behind the recent AI boom, detailing how it converts text into numerical vectors and uses attention to predict the next word.

3 things to know

Transformer Model

A specific type of neural network that is the key invention driving modern AI.

More

It's not just for text; it can be adapted for voice, images, and more.

▶ Watch at 0:23

Word Embeddings

The process of converting words (tokens) into high-dimensional vectors.

More

In this "embedding space," the distance and direction between vectors carry semantic meaning, allowing for analogies like King - Man + Woman โ‰ˆ Queen.

▶ Watch at 14:21

Next-Token Prediction

The primary task of a language model like GPT is to predict the most probable next "token" (a word or piece of a word) in a sequence.

More

By repeatedly doing this, it generates coherent, long-form text.

Also in this episode

Weights vs. Data

The video makes a critical distinction between the model's weights (the billions of learned parameters that define the model's "brain") and the data (the input text being processed).

▶ Watch at 12:12

GPT (Generative Pre-trained Transformer)

The model is Generative (creates new content), Pre-trained on vast amounts of data, and based on the Transformer architecture.

Data Flow

The video outlines the fundamental steps of data processing in a Transformer:

Quotes

“A transformer is a specific kind of neural network, a machine learning model, and it's the core invention underlying the current boom in AI.”

▶ Watch at 0:23

“The big idea here is that as a model tweaks and tunes its weights... it tends to settle on a set of embeddings where directions in the space have a kind of semantic meaning.”

▶ Watch at 14:21

“You should draw a very sharp distinction in your mind between the weights of the model... and the data being processed... The weights are the actual brains. They are the things learned during training and they determine how it behaves.”

▶ Watch at 12:12

Full summary

Episode Overview

  • This episode breaks down the meaning of GPT (Generative Pre-trained Transformer), emphasizing that the "Transformer" is the core neural network architecture behind the recent AI boom.
  • It provides a high-level, visual overview of how a Transformer processes information, from converting text into numerical vectors (embeddings) to predicting the next word in a sequence.
  • The video explains that various AI applications, including text-to-image (DALL-E), voice-to-text, and machine translation, are all built upon this fundamental Transformer technology.
  • It establishes the core goal of the series: to visually explain the internal workings of a Transformer, focusing on concepts like word embeddings, attention, and multilayer perceptrons.

Key Concepts

  • GPT (Generative Pre-trained Transformer): The model is Generative (creates new content), Pre-trained on vast amounts of data, and based on the Transformer architecture.
  • Transformer Model: A specific type of neural network that is the key invention driving modern AI. It's not just for text; it can be adapted for voice, images, and more.
  • Next-Token Prediction: The primary task of a language model like GPT is to predict the most probable next "token" (a word or piece of a word) in a sequence. By repeatedly doing this, it generates coherent, long-form text.
  • Word Embeddings: The process of converting words (tokens) into high-dimensional vectors. In this "embedding space," the distance and direction between vectors carry semantic meaning, allowing for analogies like King - Man + Woman โ‰ˆ Queen.
  • Data Flow: The video outlines the fundamental steps of data processing in a Transformer:
    • Input text is broken into tokens.
    • Tokens are converted into numerical vectors via an embedding matrix.
    • These vectors pass through Attention and Multilayer Perceptron blocks, which update them based on context.
    • The final vector is converted back into a probability distribution over all possible next tokens via an unembedding matrix and a softmax function.
  • Weights vs. Data: The video makes a critical distinction between the model's weights (the billions of learned parameters that define the model's "brain") and the data (the input text being processed).

Quotes

  • At 00:23 - "A transformer is a specific kind of neural network, a machine learning model, and it's the core invention underlying the current boom in AI." - The narrator highlights the central importance of the Transformer architecture.
  • At 12:12 - "You should draw a very sharp distinction in your mind between the weights of the model... and the data being processed... The weights are the actual brains. They are the things learned during training and they determine how it behaves." - Explaining the fundamental difference between the static model and the dynamic input it processes.
  • At 14:21 - "The big idea here is that as a model tweaks and tunes its weights... it tends to settle on a set of embeddings where directions in the space have a kind of semantic meaning." - Describing the emergent property of word embeddings, where vector arithmetic can capture abstract relationships between words.

Takeaways

  • The "T" in GPT, Transformer, is the single most important component, representing the specific neural network architecture that makes large language models possible.
  • At its core, a generative language model operates by iteratively predicting the next most likely word (or token) based on the sequence of text that has come before it.
  • All data, whether text, images, or audio, must be converted into numerical vectors for a deep learning model to process it. This is done through a process called "embedding."
  • The meaning and relationships between words (like gender or geography) can be represented geometrically as directions and distances in a high-dimensional vector space.

Watch the full episode 27 min

Read along with the audio summary

The narrator of this episode points out that a single invention, a specific kind of machine learning model called a Transformer, is the core architecture behind the current boom in artificial intelligence. In this episode, which came out on March 31, 2024, the narrator gives a visual overview of how these models actually process information. By the end, you will understand how a machine turns plain words into numbers to predict what comes next.

Let us start by unlocking the three words hidden inside the letters G, P, and T. G, P, T stands for Generative Pre-trained Transformer. The model is generative because it creates new content, and it is pre-trained because it has already learned from vast amounts of data. Most importantly, it is built on the Transformer architecture.

That brings us to how one neural network architecture powers text, voice, and images alike. As the narrator explains, a Transformer is a specific kind of neural network, which is a machine learning model. While it powers text systems, this same fundamental technology is adapted to build voice to text tools, machine translation, and even text to image generators like DALL E.

So how does this network actually write? A language model like GPT has one primary task: predicting the most probable next token in a sequence. A token is simply a word or a small piece of a word. By repeatedly guessing the next most likely token based on the text that came before it, the model builds long, coherent passages of text one piece at a time.

To make those predictions, the machine has to turn words into geometry, where directions hold actual meaning. A deep learning model cannot process raw text, audio, or images until that information is converted into high-dimensional numerical vectors. This conversion process is called word embedding. Because meaning is mapped like directions on a compass, you can do math with words: taking the vector for King, subtracting Man, and adding Woman gets you approximately to the vector for Queen.

Once words become numbers, they take a four step journey through the Transformer. The data flow begins when input text is broken into tokens and converted into numerical vectors via an embedding matrix. Next, these vectors pass through specialized processing layers called Attention blocks and Multilayer Perceptron blocks, which update the vectors based on the surrounding context. Finally, the updated vector passes through an unembedding matrix and a mathematical tool called a softmax function, turning the numbers back into a list of probabilities for every possible next token.

To understand that journey, you have to separate the machine's permanent brain from the temporary text passing through it. The data is simply the dynamic input text being processed at that moment. The weights, on the other hand, are the billions of learned parameters tuned during training: they are the actual brains of the model, and they determine how it behaves.

If you remember one thing, let it be that the T in GPT, the Transformer, is the single most important component making large language models possible. "A transformer is a specific kind of neural network, a machine learning model, and it's the core invention underlying the current boom in AI."

More from 3Blue1Brown

Related Episodes