Phase 3: LLM concepts
Understand what happens inside the model. Once you know how a model reads and picks the next word, its behaviour stops being magic. You can predict why it forgets, why temperature changes the style, why long prompts cost more, and how to debug a bad answer.
After this phase you can
- Follow one sentence through a tiny transformer, step by step
- Explain queries, keys and values with real numbers
- Choose temperature, top-k and top-p on purpose, not by guessing
Before you start: Basic Python and school maths. The idea of a probability is enough. No machine-learning background.
Lessons in this phase
- Transformer Architecture Beginner · 9 min
A transformer is a neural network that reads a whole sequence of tokens at once and lets every token look at every other token (attention) to decide what it means.
- Self Attention Intermediate · 10 min
Self-attention lets each token build its new meaning as a weighted average of all the tokens in the same sentence, with weights based on how relevant each one is.
- Multi Head Attention Intermediate · 9 min
Multi-head attention runs several smaller attention operations side by side, so different heads can track different kinds of relationships at once.
- Positional Encoding Intermediate · 8 min
Positional encoding adds information about each token's position, so the model can tell "dog bites man" from "man bites dog".
- Decoder Only Models Intermediate · 8 min
A decoder-only model is a transformer that reads text left to right and is trained to predict the next token; this is the design behind GPT, Claude, Llama, and most chat LLMs.
- Encoder Decoder Models Intermediate · 8 min
An encoder-decoder model first reads the whole input with an encoder, then writes the output with a decoder that looks back at the encoded input through cross-attention.
- KV Cache Advanced · 9 min
The KV cache stores the key and value vectors of tokens already processed, so each new token only computes its own instead of recomputing the whole prefix.
- Context Window Beginner · 7 min
The context window is the maximum number of tokens a model can handle in one request, counting your input and its output together.
- Temperature Beginner · 7 min
Temperature is a number that controls how random the model's word choice is: low values make it pick the most likely token, high values spread the choice out.
- Top-k Beginner · 6 min
Top-k sampling keeps only the k most likely next tokens, throws the rest away, and samples from what is left.
- Top-p Intermediate · 7 min
Top-p (nucleus) sampling keeps the smallest group of most-likely tokens whose probabilities add up to at least p, then samples only from that group.
- Beam Search Intermediate · 8 min
Beam search keeps the few best partial sentences at each step instead of only the single best token, so it can find a more likely full sentence than greedy decoding.
- Hallucination Intermediate · 8 min
A hallucination is when a model produces fluent, confident text that is false or not supported by its sources.
- Prompt Engineering Beginner · 9 min
Prompt engineering is writing and testing the instructions, examples, and context you give a model so it reliably produces the output you need.
- Fine-Tuning (the overview) Intermediate · 9 min
Fine-tuning means training an existing model a little more on your own examples, so it picks up a style or a narrow skill, and it is usually the last thing to try after prompting and RAG.
- Calling an LLM API Beginner · 8 min
Calling an LLM API means sending a list of role-tagged messages over HTTPS and getting back text plus a count of the tokens you used, and a production call also needs a timeout, retries and a cost check.
- Structured Outputs Intermediate · 7 min
Structured outputs make an LLM return data your code can parse, such as JSON that matches a schema, and you still validate every reply, because even a well-formed answer can be wrong.
- Quantization (shrinking a model) Intermediate · 8 min
Quantization stores a model's weights as small integers (8-bit or 4-bit) instead of 16-bit decimals, so the model needs far less memory and often runs faster, at the cost of a small rounding error.
- LoRA and PEFT (cheap fine-tuning) Advanced · 9 min
LoRA freezes the big model and trains two tiny matrices whose product is added to each chosen weight matrix, so you train well under 1% of the parameters and still change the model's behaviour.
- Inference Serving and Batching Advanced · 10 min
Serving an LLM is a scheduling problem: a GPU is only efficient when it works on many requests at once, and good servers keep it busy by swapping finished requests out and new ones in at every step.
- How an LLM Works End to End Beginner · 10 min
An LLM turns text into numbers, runs those numbers through a stack of identical blocks, scores every word in its vocabulary as the possible next token, picks one, and repeats, one token at a time.
- Q, K and V Explained From Scratch Intermediate · 12 min
Each token's vector is multiplied by three different learned matrices to make a Query (what I am looking for), a Key (how I advertise myself) and a Value (what I hand over).
- Inside a Transformer Block: Residuals, LayerNorm and the Feed-Forward Network Intermediate · 11 min
A transformer block is attention plus three supporting parts: residual connections that carry the signal past each step, a normalisation layer that keeps numbers in a healthy range.
- How LLMs Are Trained: Loss, Backprop, Pretraining, SFT and RLHF Intermediate · 12 min
An LLM first learns language by guessing the next token over a huge pile of text (pretraining), then learns to follow instructions from example answers (SFT).
- Modern Attention: MQA, GQA, FlashAttention, Sliding Window and RoPE Advanced · 12 min
Modern LLMs keep the attention idea from self-attention but change how it is stored and computed (shared K/V heads, tiled exact math, local windows, rotary positions) so long contexts and many users fit on a GPU.
- Mixture of Experts and Scaling Laws Advanced · 11 min
A Mixture of Experts (MoE) model has many specialist feed-forward blocks but runs only a few per token, and scaling laws tell us how much model size, data and compute we need for a given quality.