0000 โ€” The Transformer: Your North Star

Precursor ยท The destination before the journey ยท ~25 minutes

You already use transformers every day. ChatGPT, Claude, Gemini โ€” all transformer-based. DALLยทE, Midjourney, Sora โ€” built on transformer variants. GitHub Copilot, the assistant writing code with you right now โ€” a transformer. This lesson shows you what's inside the black box. Not the code, not the engineering โ€” the mathematical ideas that make it work. Everything you learn in the next 14 lessons builds toward understanding this architecture from the ground up.

What Does a Transformer Do?

At its core, a transformer takes a sequence of tokens and predicts what comes next.

"The cat sat"
โ†’
Transformer
โ†’
"on" (73%)
"under" (11%)
"." (3%)
โ€ฆ

That's it. Input tokens in, probability distribution over next tokens out. Repeat to generate text: take the predicted token, append it to the input, run the transformer again.

This is the fundamental operation of every large language model. GPT-4, Claude 4, Gemini 2.5 โ€” all of them, at their mathematical core, do exactly this: take a sequence of tokens, output a probability distribution over the next token. The difference between them is scale (billions vs. trillions of parameters), training data, and engineering โ€” not the underlying math.

The Four Mathematical Pillars

The transformer rests on four mathematical ideas. You'll master the first two in depth, and we'll touch the third and fourth as needed:

๐Ÿงฎ Linear Algebra

The language of data representation and transformation

Lessons 0001โ€“0006

๐ŸŽฒ Probability & Information Theory

The language of uncertainty, learning, and measurement

Lessons 0007โ€“0012

โ†“

Attention Mechanism
Where linear algebra meets probability

Lessons 0013โ€“0014

The Transformer Pipeline โ€” A Preview

Here is the full mathematical pipeline. Don't worry about understanding it yet. Read it once to see the shape. Return to this section after every few lessons โ€” each time, more of it will make sense.

Tokens
"The cat sat"
โ†’
Embedding
Tokens โ†’ Vectors
โ†’
+ Position
encoding
โ†’
Attention
Block
ร— N layers
โ†’
Output
Projection
โ†’
Softmax
โ†’ Probabilities
โ†’
"on" (73%)

Zooming into one Attention Block (the heart of the transformer):

Input
vectors
โ†’
Multi-Head
Attention
โ†’
Add &
Norm
โ†’
Feed-Forward
Network
โ†’
Add &
Norm
โ†’
Output
vectors

And zooming into Multi-Head Attention (the core innovation of the 2017 paper):

Attention(Q, K, V) = softmax (
QยทKแต€
/ โˆšdโ‚– ) ยท
V

QยทKแต€ = matrix multiplication (Lesson 0003)  |  softmax = probability bridge (Lesson 0012)  |  โˆšdโ‚– = scaling factor (Lesson 0013)

That formula is the destination. After 12 lessons, you'll be able to read Attention(Q,K,V) = softmax(QKแต€/โˆšdโ‚–)V and know exactly what each symbol means, why it's there, and what would break if you changed it. That's genuine mathematical competence โ€” the ability to reason about the formula, not just recognize it.

Your Journey: The Lesson Map

# Lesson Key Question Answered
0001 Vectors โ€” The Atom of AI Data What is a vector, and why is everything in AI a vector?
0002 Matrices as Transformations How do we move vectors between spaces?
0003 Matrix Multiplication โ€” The Engine How does QยทKแต€ compute all pairwise similarities at once?
0004 Vector Spaces, Bases & Embeddings What does it mean to "represent" a word as a vector?
0005 Projections, Orthogonality & Residuals Why do residual connections help deep networks?
0006 Eigenvalues, SVD & Matrix Secrets How do we compress models and understand what matrices "do"?
0007 Probability Fundamentals Why is probability the right language for learning from data?
0008 Conditional Probability & Bayes How does a model update its beliefs with new evidence?
0009 Random Variables & Distributions What exactly is the model's "output"?
0010 Entropy & Cross-Entropy How do we measure whether a model is "wrong"?
0011 KL Divergence How different are two probability distributions?
0012 Softmax โ€” The Bridge How do we turn vector math into probabilities?
0013 Attention โ€” The Core Innovation How does attention actually work, step by step?
0014 Complete Transformer + Paper How do all the pieces fit together into a working system?

What You'll Be Able to Do

After completing this sequence, you will be able to:

You will not be able to build a transformer. That's not the goal. You'll be able to do something rarer and arguably more valuable: think clearly about what transformers can and cannot do, and explain why, in mathematical terms that are actually correct. In an AI-driven economy, that skill โ€” genuine mathematical literacy without the implementation โ€” is the gap this course fills.

Check Your Understanding

Q1: At its mathematical core, what does a transformer (like GPT-4) output?

A. A single best-guess word B. A probability distribution over possible next tokens C. A fixed-length vector representing the entire input D. A confidence score between 0 and 1

Q2: The attention formula includes QยทKแต€ (matrix multiplication), a softmax, and multiplication by V. Which two mathematical pillars converge in this formula?

A. Calculus and statistics B. Linear algebra and probability C. Graph theory and optimization D. Number theory and information theory

Q3: A company claims their new AI model "doesn't use transformers." Based on what you now know, what would be the most productive question to ask?

A. "What programming language is it written in?" B. "What mathematical operations does it use to relate different parts of the input to each other?" C. "How many GPUs did you train it on?" D. "Is it better than GPT-4?"
๐Ÿ“– Primary Source for the Full Journey Vaswani et al., "Attention Is All You Need" (2017) โ€” arxiv.org/abs/1706.03762 The 9-page paper that started the transformer revolution. Bookmark it. In Lesson 0014, you'll read every section with full mathematical comprehension. For now, just know it exists โ€” it's your destination.
๐Ÿ“บ Recommended First Watch 3Blue1Brown, "But what is a GPT? Visual intro to transformers" โ€” YouTube An outstanding visual walkthrough of the transformer architecture. Watch it now for motivation โ€” then watch it again after Lesson 0014 to see how much you've learned.
This precursor is your map. Return to it whenever you feel lost in the details of a specific lesson. The question is always: "How does this piece fit into the transformer?" If you can't see the connection, ask me โ€” I'll trace the thread for you.
Next: 0001 โ€” Vectors: The Atom of AI Data โ†’