When I first learned the Transformer, I looked at plenty of architecture diagrams. I knew the name of every module, yet when I had to explain how a sentence turns into the next token, I still got stuck.

This section builds up those connections step by step: how text becomes numbers, how RNNs and LSTMs handle sequences, and how Seq2Seq connects input to output. From there, it introduces attention and the Transformer before moving on to today's decoder-only models. Each topic starts with examples, then develops the equations and code you can write yourself.

To see how the whole collection fits together, start with the study and review guide. This page covers language-model foundations; you don't need to finish the other areas first.

One path, end to end

flowchart LR
    A["Text"] --> B["Token IDs"]
    B --> C["RNN / LSTM<br/>recurrent state"]
    C --> D["Seq2Seq<br/>encode and generate"]
    D --> E["Transformer<br/>parallel attention"]
    E --> F["Decoder-only<br/>autoregressive LM"]
    F --> G["Pre-training · SFT · Preference · RL"]

Level one: what you must know

After reading these, try drawing the computation from text to logits without notes, explaining the input and output of each step. Wherever you get stuck is where to go back.

Beyond the main line: two advanced routes

If similarity or a training step still feels fuzzy, read embeddings and similarity and one training step first. To see how images join the same computation, continue with CLIP → visual language models.

Once the main sequence is clear, you can study the equations, gradients, and code in more detail, or compare how different model families solve the same problem. In either case, consider both the results and the systems cost.

1. Dig into mechanisms

Topic What you really need to understand What you can answer afterwards
From linear models to neural networks Sigmoid / Softmax / ReLU / Tanh, feature maps, backpropagation, XOR Why are the four functions not interchangeable? What does nonlinearity actually change?
Sequence gradients and gates BPTT, Jacobian products, vanishing / exploding gradients, LSTM cell state Why is "being able to remember" first of all an optimization problem?
Attention mathematics and shapes $Q/K/V$, masks, multiple heads, RoPE, GQA, RMSNorm, SwiGLU Which matrices does one attention call actually multiply?
Language-model objectives and generation causal loss, teacher forcing, exposure gap, sampling, cache Training computes everything in one parallel pass; why does generation still go token by token?

2. Read model families sideways

Once you know the Transformer's parts, the next step is not to memorise more model names. It is to ask: why did this model change this component, what did it save, what extra cost did it add, and do the experiments support that choice?

Start with the model-family map for the reading method. To compare exactly what changes inside the block, open the interactive architecture map.

Quick reference

Topic Focus
ML mathematics: the main line Softmax / CE / LSE, L1 / L2, Bias–Variance, MLE / MAP, BLUE
Whiteboard hand-writing kit stable implementations, gradients, and numerical checks

These chapters are useful when a model misbehaves: they help you trace an interrupted gradient, find positions hidden by an incorrect mask, and explain a mismatch between training and generation.

Build it yourself: make the understanding run

Without PyTorchSee where every number comes from

BPE in pure Python; RNN, LSTM, and scaled dot-product attention in NumPy.

Open labs →
With PyTorchMake the same mechanism actually learn

Implement the modules yourself, use autograd, train seq2seq, and verify the Transformer's causality and KV cache.

Open labs →
cd 00-foundations/code
python tokenizer_from_scratch.py
python sequence_numpy.py
python sequence_torch.py
python test_learning_path.py

How to use this material

Follow the example first, then consult the equations or code where a step is unclear. For a new architecture, ask which component changed, why it changed, and where the previous approach fell short.

I just want to understand the main line first

Read core notes 01 → 05, leaving deeper derivations and code for later if useful. First understand how the methods connect, then return for details.

I want to be able to explain it, not just to have "heard of it"

After each main-line note, read the matching deep-dive page and do three things: write out the central equation, label every tensor shape, and say which bottleneck of the previous generation the architecture removes.

I want to understand a new model report

Use the six questions in the model family deep dives to structure your reading, then return to the interactive diagram to compare blocks. Before copying the parameter table, identify whether the change concerns architecture, training, post-training, inference, or evaluation.

I want to write it by hand until it breaks

Run the framework-free version first, then the PyTorch version. Don't start by calling high-level APIs; if you have never handled hidden state, a causal mask, and cache positions by hand even once, a lot of bugs will all look like "training instability."

Where this path finally leads

Only once the base model has been trained does the question move from "how does it predict the next token" to "how do we make it fit tasks, preferences, and real feedback better." The next stop is Post-Training; if you care about how a model finds external evidence, continue with Search.