Learning path plan and review sheets
Choose a stage to find the ideas to master and review them with a question and answer. Prior learning links point to lessons that supply knowledge used at the stage shown.
Guided route and optional resources · Français · English
Visual recall cards for self-testing
Each card is a short retrieval prompt with a concise correction; try to reconstruct the diagram before opening its answer. Worked exercises remain on the dedicated practice pages. · Same token, two positions · From scores to output · One decode step with a KV cache
Compare uses
| Stage | Context \(c\) | Parameters \(\theta\) | Operation |
|---|---|---|---|
| Generate | Grows with each token fed back | Fixed | Output · Select and feed back a token |
| Shape context | Assembled for each call | Fixed | Input · Choose the information supplied |
| Score | Prefix given for each target | Fixed | Output · Score an observed target or sequence |
| Train | Prefixes from observed examples | Updated | Training · Aggregate losses and update parameters |
Context design shapes the input. The other three operations use the distribution. Training aggregates penalties on observed targets, backpropagates the gradient, and applies an update.
How an LLM works
What does a GPT compute from the text it receives? It assigns a probability to each candidate for the next unit of text, called a token.
Formal view
\[ c \mapsto p_\theta(\cdot \mid c) \]
For a given prefix \(c\), the distribution is over the next token. The parameters \(\theta\) stay fixed across the overview’s two steps.
Stage objective. Locate the model’s context and parameters. Follow two generation steps in the overview before studying how a prediction is computed.
Overview: what is an LLM?
Overview: what is an LLM? · Review — How an LLM works
- Scope — Places the language model, its parameters and its context. Introduces the three uses of a prediction with a black-box generation example.
- Learning outcome — Trace two generation steps with fixed parameters and distinguish generating a token, scoring an observed target and training.
- What the sheet covers — Next-token prediction, the generation loop, and what parameters and context each contribute.
From text to tokens
How does text become input to the network? A tokenizer splits the text into tokens and looks up each token’s ID in its vocabulary.
Formal view
\[ s \xrightarrow{\mathrm{tok}} (i_1,\ldots,i_T), \qquad i_t \in \mathcal{I}_{\mathrm{tok}} \]
The length \(T\) depends on the text \(s\) and the tokenizer used. \(\mathcal{I}_{\mathrm{tok}}\) is the set of valid IDs for that tokenizer.
Stage objective. Distinguish text, tokens, and token IDs that form the model’s discrete input without needing to study segmentation algorithms.
Trace token IDs to their embedding rows
From text to tokens: representing language
From text to tokens: representing language · Review — From text to tokens
- Prior learning — Overview: what is an LLM?
- Scope — Covers the path from text to tokens, tokens to IDs, and IDs to embedding lookup. Distinguishes prompt encoding from corpus preparation; segmentation algorithms belong to the dedicated deep dive.
- Learning outcome — Explain the text → tokens → IDs → initial vectors chain, compare two tokenizers on the same input, distinguish IDs from numerical quantities, and understand why tokenizer and weights form a contract.
- What the sheet covers — A recall sheet for the text → tokens → IDs → initial lookup chain, tokenizer dependencies, and the distinction between prompts and corpora.
From IDs to representations
What happens to the IDs at the network input? Each ID selects a list of numbers. In the project’s GPT, a signal based on its position is added to that list.
Formal view
\[ H^{(0)}_t = E_\theta[i_t] + P_\theta[t] \]
With a fixed table, the same ID gives the same base embedding \(E_\theta[i_t]\). The formula describes the project’s GPT, which adds the learned position vector \(P_\theta[t]\) before the first block. RoPE instead applies positional information to queries and keys within attention.
Stage objective. Identify embeddings and positional information. Compare initial and contextualized states before opening the blocks that turn the former into the latter.
Trace token IDs to their embedding rows
Separate positional addition from contextualization
Compare a change before or after the token under study
From token IDs to vectors: embeddings
From token IDs to vectors: embeddings · Review — Embeddings and table lookup
- Prior learning — From text to tokens: representing language
- Scope — Traces an ID sequence through lookup: sequence position, ID, selected row, and resulting initial vector. Distinguishes this result from positional processing and contextualized states.
- Learning outcome — Given an ID sequence, retrieve the selected rows and vectors in order, explain why repeated IDs share the same vector with a fixed table, and predict the effect of coordinated renumbering.
- What the sheet covers — The ID as an address, the initial embedding as a learned vector, and its relation to contextual states.
Positional encoding: giving tokens an order
Positional encoding: giving tokens an order · Review — Positional information
- Prior learning — From token IDs to vectors: embeddings
- Scope — Explains why order must be represented and compares the insertion points of absolute encodings, relative representations, score biases and RoPE. Distinguishes these signals from causal visibility and locates NoPE as the omission of an explicit positional mechanism. Derivations remain in the deep dives.
- Learning outcome — Explain why content alone is insufficient, compare where positional mechanisms act in the computation, and distinguish explicit information, implicit order and causal visibility.
- What the sheet covers — A synthesis sheet on order, absolute and relative insertion points, score biases, and the distinction between causal visibility and implicit order in NoPE.
Why can the same token have different contextualized representations?
Why can the same token have different contextualized representations? · Review — Contextualized representations
- Prior learning — From token IDs to vectors: embeddings, Positional encoding: giving tokens an order
- Scope — Compares the initial lookup with hidden states at each position, then explains their dependence on accessible context in a causal GPT. Sub-layer formalization and analysis of specific linguistic dependencies belong in the deep dive.
- Learning outcome — Predict what can change an occurrence’s state by separating token ID, position, accessible prefix, and network transformations.
- What the sheet covers — A recall sheet on initial lookup, position-wise hidden states, and the causal boundary of accessible context.
Understand Transformer computation
How does the prefix influence the representation at one position? In each block, attention combines information from accessible positions. The MLP then transforms each position’s representation independently.
Formal view
\[ H^{(0)} \mapsto H^{(L)}, \qquad H^{(0)}, H^{(L)} \in \mathbb{R}^{T \times d} \]
The stack preserves the \(T\) positions and width \(d\) across its \(L\) blocks. For each query, attention softmax normalizes scores over the permitted key positions. In a causal GPT, changing tokens after \(t\) leaves the state at \(t\) unchanged at each layer, with positions and parameters fixed and deterministic execution.
Stage objective. Connect Q/K/V projections, attention scores and weights, value aggregation, causal masking, and the other operations in a Transformer block.
Separate positional addition from contextualization
Compare a change before or after the token under study
Compute the probabilities and find the next-token row
Distinguish attention weights from next-token probabilities
Trace a token visible as input and ignored as a target
The Transformer in a GPT: architecture and computation
The Transformer in a GPT: architecture and computation · Review — GPT Transformer computation
- Prior learning — Why can the same token have different contextualized representations?
- Scope — Introduces the decoder-only GPT computation flow, the general role of repeated blocks, and the boundary between the forward pass and decoding.
- Learning outcome — Trace representations to logits, explain what a Transformer block repeats, and distinguish network computation from generation of the next token.
- What the sheet covers — The path from embeddings through blocks and final states to logits, including attention, the MLP and residual connections.
Queries, keys, and values (Q, K, V)
Queries, keys, and values (Q, K, V) · Review — Queries, keys and values
- Prior learning — The Transformer in a GPT: architecture and computation
- Scope — Distinguishes three learned projections of a block state and their roles in one self-attention head.
- Learning outcome — Explain why self-attention projects the block input into Q, K, and V; distinguish compatibility computation (Q/K) from aggregated content (V); and predict the effects of changing one projection in isolation.
- What the sheet covers — The three projections of a hidden state and the path from Q–K comparisons to weights and the weighted combination of V.
Scaled dot-product attention
Scaled dot-product attention · Review — Scaled dot-product attention
- Prior learning — Queries, keys, and values (Q, K, V)
- Scope — Traces one attention row from Q–K comparisons to a weighted combination of values.
- Learning outcome — Explain and reconstruct one attention row — scores, scaling, masking, softmax, and aggregation — and justify the shapes and normalization of its intermediate quantities.
- What the sheet covers — One row of scores, scaling by the square root of key dimension, softmax and the weighted sum.
Causal masking
Causal masking · Review — Causal masking
- Prior learning — Scaled dot-product attention
- Scope — Determines the positions each query can access in autoregressive computation and locates the mask before normalization.
- Learning outcome — Read a causal-mask row, infer the accessible prefix and identify the next token to predict.
- What the sheet covers — Accessible positions for a query, the diagonal and applying the mask before softmax.
From hidden states to the predictive distribution
How do representations become probabilities? At each position the output head gives one score per vocabulary token. Softmax converts the scores into probabilities that total 100% at that position.
Formal view
\[ \begin{aligned} z_t &= W_\theta h_t + b_\theta, \\ p_t &= \operatorname{softmax}_{\mathrm{vocab}}(z_t). \end{aligned} \]
\(h_t\) is the state at the output head’s input, after final normalization in the project’s GPT. For an unpadded prefix of \(T\) tokens, \(p_T\) predicts the token after the full prefix. The entropy of that distribution depends on the probabilities of all candidates.
Stage objective. Trace the projection from final hidden states to logits and the conditional next-token distribution; interpret its entropy before any token selection or observed target.
Compute the probabilities and find the next-token row
Distinguish attention weights from next-token probabilities
Compare greedy selection and sampling with a fixed distribution
Compare two distributions that assign the same probability to the observed token
Logits: scores before normalization
Logits: scores before normalization · Review — Output logits
- Prior learning — The Transformer in a GPT: architecture and computation
- Scope — Explains how the output head projects a final state into vocabulary-indexed scores.
- Learning outcome — Identify the shape and axes of the logits, then read the ranking of candidates at one position.
- What the sheet covers — Projection from a hidden state to one raw score per candidate token, distinguished from probabilities and attention scores.
Output probabilities: from logits to a distribution
Output probabilities: from logits to a distribution · Review — Next-token probabilities
- Prior learning — Logits: scores before normalization
- Scope — Builds the next-token distribution with softmax and distinguishes normalization, calibration, and factual interpretation.
- Learning outcome — Turn logits into probabilities over the vocabulary and distinguish a normalized distribution from a calibrated prediction.
- What the sheet covers — Softmax over the vocabulary, conditional distributions, and the distinction between normalization, calibration, and factual truth.
Entropy: uncertainty over the next token
Entropy: uncertainty over the next token · Review — Predictive entropy
- Prior learning — Output probabilities: from logits to a distribution
- Scope — Measures uncertainty in the predictive distribution for a fixed context. Compression is a complementary application.
- Learning outcome — Compare the entropy of two distributions over the same vocabulary and distinguish that average from one observed token’s surprisal.
- What the sheet covers — Uncertainty in a distribution at fixed context, one token’s surprisal, and the distinction between them.
Run inference and generate text
How does a prediction become a continuation? A rule selects a candidate. The token is appended to the sequence and the process repeats until the stopping criterion is met.
Formal view
\[ \begin{aligned} x_t &\sim \pi(\cdot \mid p_\theta(\cdot\mid c_t)), \\ c_{t+1} &= c_t \Vert x_t. \end{aligned} \]
The symbol \(\Vert\) denotes concatenation. The parameters \(\theta\) stay fixed. The decoding policy \(\pi\) gives the selection probabilities. A deterministic choice assigns selection probability 1 to the chosen candidate.
Stage objective. Distinguish prompt prefill from iterative decode, select a token with a decoding policy, feed it back into the context, and stop generation without updating parameters.
Compare greedy selection and sampling with a fixed distribution
Trace the generated and observed prefixes
Trace what carries over to the next call
Generating text: inference step by step
Generating text: inference step by step · Review — Autoregressive generation
- Prior learning — Output probabilities: from logits to a distribution
- Scope — Traces free-running generation from prompt processing to stopping. Latency and scheduling are covered as optional depth.
- Learning outcome — Trace selection of the first token from prefill, then the feedback of selected tokens until generation stops.
- What the sheet covers — From prompt prefill to stopping generation, including token selection and feedback.
Use and design context
What changes when an instruction or document is added? The application chooses the context for the next call. The model computes its prediction from the tokens in that context.
Formal view
\[ \begin{aligned} c &\longmapsto p_\theta(\cdot\mid c), \\ c' &\longmapsto p_\theta(\cdot\mid c'). \end{aligned} \]
The two inputs are compared at fixed parameters \(\theta\). The effect of added material depends on what actually reaches the context.
Stage objective. Extend inference to the application level. Explain the effect of examples supplied in the prompt, then choose what information a system passes to the model.
Trace what carries over to the next call
In-context learning
In-context learning · Review — In-context learning
- Prior learning — Generating text: inference step by step
- Scope — Examines how examples in the prompt affect the response of a model with fixed parameters.
- Learning outcome — Distinguish zero-shot, one-shot and few-shot, then explain how behavior can change without a parameter update.
- What the sheet covers — How examples, instructions and documents in a prompt influence a model with fixed parameters.
Context engineering
Context engineering · Review — Context engineering
- Prior learning — In-context learning
- Scope — Moves from model behavior to system-level context design under budget and reliability constraints.
- Learning outcome — Choose what information to supply for a task and diagnose a failure by inspecting the context actually passed to the model.
- What the sheet covers — Selecting, organizing and validating context under budget and reliability constraints.
Score observed tokens
What probability did the model assign to a known continuation? At each step, we read the probability of the observed token given the prefix before it. The product of these probabilities gives the likelihood of the continuation.
Formal view
\[ \begin{gathered} \log p_\theta(x_{1:n}\mid c) \\ = \sum_{t=1}^{n} \log p_\theta(x_t \mid c \Vert x_{<t}). \end{gathered} \]
With parameters fixed, each term uses the initial context \(c\) followed by the observed tokens before target \(x_t\). For a one-hot target, the cross-entropy at that position is the negative of the corresponding term.
Stage objective. Evaluate the probability assigned to a known target, build a sequence likelihood, and connect negative log-likelihood to cross-entropy without selecting a token or changing parameters.
Compare two distributions that assign the same probability to the observed token
Trace the generated and observed prefixes
Calculate two updates at equal loss
Likelihood and log-likelihood
Likelihood and log-likelihood · Review — Sequence likelihood
- Prior learning — Output probabilities: from logits to a distribution
- Scope — Scores an already-observed sequence with a fixed context and fixed parameters.
- Learning outcome — Compute continuation likelihood by multiplying conditional probabilities, then recover its log-likelihood and NLL.
- What the sheet covers — Scoring an observed continuation as a product of conditional probabilities and a sum in log space.
Cross-entropy for a token prediction
Cross-entropy for a token prediction · Review — Cross-entropy
- Prior learning — Output probabilities: from logits to a distribution
- Scope — Defines the local penalty of a prediction against a target distribution. The one-hot case connects it to one token’s NLL.
- Learning outcome — Compute H(q,p) at a single position and recover −log p(y) when the target is concentrated on y.
- What the sheet covers — Prediction versus target, the computation at one position, and the one-hot case.
Learn and update parameters
How do examples inform parameter updates? Predictions and targets give a loss. The optimizer uses its gradients to update the parameters.
Formal view
\[ \begin{aligned} g &= \nabla_\theta \mathcal{L}(\theta), \\ \theta' &= \theta - \eta g \quad \text{(SGD)}. \end{aligned} \]
With teacher forcing, prefixes and targets come from the observed examples. The loss \(\mathcal{L}\) aggregates losses at valid target positions. Computing \(g\) leaves the parameters fixed. The second line gives a stochastic gradient descent step with learning rate \(\eta\). Validation measures loss with the parameters fixed.
Stage objective. Connect observed targets to the aggregated loss, gradients, and parameter updates, then to the repeated training loop and validation loss; understand teacher forcing conceptually without making shifted-example preparation a stage of the Theory path.
Trace a token visible as input and ignored as a target
Calculate two updates at equal loss
From token penalties to batch loss
From token penalties to batch loss · Review — GPT loss function
- Prior learning — Output probabilities: from logits to a distribution
- Scope — Turns local penalties and a mask of valid targets into a scalar objective for a batch.
- Learning outcome — Construct batch loss and explain the effect of choosing between a sum, a mean over valid tokens and a weighted mean.
- What the sheet covers — The target-token penalty, aggregation over valid positions and the role of the resulting scalar.
Gradients: connecting loss to parameters
Gradients: connecting loss to parameters · Review — Gradients and parameter updates
- Prior learning — From token penalties to batch loss
- Scope — Propagates local loss sensitivity through the logits to the parameters. Places the parameter update in the optimizer.
- Learning outcome — Trace a derivative through the computation graph and compute one plain descent step from a given gradient.
- What the sheet covers — Local loss sensitivity, backpropagation and one gradient descent update.
The training loop: from gradients to a trained model
The training loop: from gradients to a trained model · Review — Training loop
- Prior learning — Causal masking, From token penalties to batch loss, Gradients: connecting loss to parameters
- Scope — Assembles the computations into repeated training steps and distinguishes batch optimization from monitoring on held-out data.
- Learning outcome — Order the operations in one iteration and interpret a divergence between training and validation curves.
- What the sheet covers — The steps of one iteration, teacher forcing and interpreting validation loss.