Concept library
446 concepts across 8 domains and 36 tracks. Each track is a coherent sequence — read it top to bottom or dip in wherever the gap is.
02
Transformer Internals
Open the box. How a language model actually turns text into predictions.
8tracks
89concepts
408cards
11.3hreading
Tokenisation BPE, WordPiece, Unigram, and the ways subword vocabularies quietly shape model behaviour. 11 concepts · 56 cards
- 01 Special and Control Tokens The handful of reserved vocabulary entries no amount of BPE merging could ever produce from ordinary text, and why keeping them outside the mergeable vocabulary is a real security boundary, not just bookkeeping.
- 02 Tokenisation and BPE How models turn raw text into integer tokens, and why the vocabulary choice silently shapes model behaviour.
- 03 Why LLMs Cannot Spell or Count Letters The classic "how many r's in strawberry" failure is not a reasoning gap, it is a representational one, caused by the model never seeing the individual letters that make up a compressed token.
- 04 Byte-Level BPE Why GPT-2 and its descendants tokenise raw bytes instead of characters, and how that single design choice guarantees any input string can be represented without an unknown-token fallback.
- 05 Detokenisation and Streaming Boundaries Streaming a response token by token can briefly render a garbled glyph on screen, a direct, visible consequence of a multi-byte character being split across more than one token, and a correctness problem, not just a UI quirk.
- 06 The Tokenisation Tax Two prompts with the same meaning can cost a different number of tokens under the same vocabulary, and that gap compounds into real dollars, real context budget, and real latency before the model reasons about anything at all.
- 07 Token Fertility and Multilingual Fairness The same paragraph of news text can tokenise into several times as many tokens in one language as another under a shared vocabulary, a structural cost baked in before any user sends a request, not a rounding error.
- 08 Tokenisation and Arithmetic A model can be strong at multi-step reasoning and still botch four-digit addition, not from a lack of arithmetic ability but because its tokeniser handed it two structurally unrelated token sequences for two numbers that differ by one.
- 09 Unigram LM and SentencePiece A tokeniser that builds its vocabulary top-down instead of bottom-up, assigns every segmentation of a string a real probability, and the library that made it (and BPE) usable without a language-specific pre-tokeniser.
- 10 WordPiece Tokenisation BERT's tokeniser looks like BPE on the surface, but the merge criterion it optimises is different, and that difference is why WordPiece pieces tend to track real morphemes more closely.
- 11 BPE-Dropout and Subword Regularisation A deterministic tokeniser has a blind spot no amount of extra training data fixes on its own, the model never has to be robust to an unfamiliar segmentation of a familiar word, until two techniques deliberately introduced randomness into tokenisation as a training-time fix.
Embeddings & Representations The lookup table, the residual stream, contextual vectors, geometry and superposition. 11 concepts · 47 cards
- 01 Cosine Similarity vs Dot Product Two near-identical looking formulas that answer different questions, one measures direction alone, the other measures direction and magnitude together, and picking the wrong one silently breaks a search or ranking system.
- 02 Embeddings and Semantic Search How dense vectors turn text into a geometry of meaning, and how cosine similarity lets you find related content without keywords.
- 03 Input Embeddings and the Lookup Table How a token id becomes a vector, a single row lookup into a trained matrix, and why that matrix is often the largest single block of parameters a small model spends before any real computation happens.
- 04 word2vec and GloVe The two ideas, predict-a-neighbour and factor-a-co-occurrence-matrix, that first proved dense vectors could capture enough word meaning to support arithmetic on it, years before transformers existed.
- 05 Sentence Embeddings and Pooling A transformer produces one vector per token, not one per sentence, so turning a sequence of contextual vectors into a single comparable vector requires a pooling choice that quietly changes what "similar" ends up meaning.
- 06 Static vs Contextual Embeddings The shift from one vector per word to one vector per word-in-context, and why that shift is arguably the single biggest reason transformer-based models outperformed earlier NLP.
- 07 Weight Tying of Input and Output Embeddings Why most language models score every candidate next token using the transpose of the exact same matrix that looked up the input tokens, cutting parameters and improving perplexity in one move.
- 08 Embedding Geometry and Anisotropy Learned embedding spaces are not the well-spread sphere the geometric intuition suggests, they collapse into a narrow cone, and that fact quietly breaks naive similarity comparisons built on top of them.
- 09 Superposition and Polysemantic Neurons Individual neurons in a trained network routinely fire for several unrelated concepts at once, and the leading explanation is not noise, it is a model deliberately packing more features than it has dimensions using near-orthogonal directions.
- 10 The Residual Stream Reframing a transformer's residual connections as one shared, additive vector space that every layer reads from and writes to, the lens that makes attention, MLPs, and interpretability results legible as a single system.
- 11 Unembedding and the Logit Lens Multiplying an intermediate layer's residual stream by the final unembedding matrix, as if it were the last layer, turns out to produce surprisingly sensible next-token guesses, a cheap window into what a model has committed to mid-computation.
Attention Internals Queries, keys and values, masking, multi-head and grouped-query, sinks, and the quadratic wall. 11 concepts · 49 cards
- 01 Attention as Soft Dictionary Lookup The mental model that makes attention click before the matrix algebra does - a lookup table where the key match is a matter of degree, not an exact hit or miss.
- 02 Attention Mechanism How attention lets a model focus on the relevant parts of a sequence by computing weighted dependencies between every pair of positions.
- 03 Causal Masking How a transformer trained to predict every position in parallel is stopped from cheating by looking ahead, and why the mask is applied before softmax rather than after.
- 04 Multi-Head Attention in Depth Why attention runs as several small parallel attentions rather than one large one, what each head actually gets to specialise in, and why most heads turn out to be redundant.
- 05 Queries, Keys, and Values The retrieval metaphor behind attention, made literal - what a query, key, and value actually are as learned projections, and why three separate matrices instead of one.
- 06 Self-Attention vs Cross-Attention The one-line distinction, where the queries come from versus where the keys and values come from, and why decoder-only LLMs mostly made cross-attention disappear from the mainstream architecture.
- 07 Sliding-Window Attention The simplest fix to attention's quadratic cost - cap how far back each position can look - and why stacking layers gets that fixed window back to an effectively long range.
- 08 The Quadratic Cost of Attention Where the O(n squared) in "attention is quadratic" actually comes from, why it hits both compute and memory, and what doubling the context length really costs.
- 09 Attention Sinks Why the first few tokens of almost any sequence soak up a disproportionate share of attention regardless of their content, and how that quirk becomes the key to stable infinite-length streaming generation.
- 10 Induction Heads A specific, mechanistically understood attention circuit that copies patterns it has seen once in the current context, and the closest thing the field has to a concrete explanation for in-context learning.
- 11 Multi-Query and Grouped-Query Attention Why the key and value projections, not the query projection, were the ones cut down to fix the real inference bottleneck, and the middle-ground design that most production LLMs settled on.
Positional Encoding Sinusoidal, learned, RoPE, ALiBi, and how context windows get stretched past training length. 11 concepts · 53 cards
- 01 Learned Absolute Positions The simplest positional scheme, a trainable embedding table indexed by slot number, and the hard ceiling it builds into every model that uses it.
- 02 Why Attention Needs Positions Self-attention is a permutation-equivariant set operation by default; every notion of word order a transformer has was injected as data, not built into the architecture.
- 03 ALiBi: Attention with Linear Biases A zero-parameter alternative to rotating or embedding position, a per-head linear penalty on distance, and why train-short-test-long comes at the cost of sharp long-range recall.
- 04 Effective vs Nominal Context Length The advertised context window and the length a model actually uses well are different numbers, often by a large factor, and the gap between them has several distinct, measurable causes.
- 05 Positional Encodings Why attention needs to be told where each token sits, and how RoPE, ALiBi, and the surprising NoPE result shape how far a model can read.
- 06 Relative Position Representations The 2018 idea that attention should see i-j directly rather than infer it from two absolute positions, the direct ancestor of both RoPE and T5's relative bias.
- 07 Rotary Position Embeddings (RoPE) The rotation trick behind Llama, Mistral, and Qwen, worked through in full, and why an exact algebraic guarantee beats hoping the network learns relative distance on its own.
- 08 Sinusoidal Positional Encodings The original transformer's fix for order, a fixed sin/cos signal added to every embedding, and why its elegant closed form still degrades once you run past training length.
- 09 Length Extrapolation What it actually means for a model to handle sequences longer than training, why perplexity is a necessary but misleading metric for it, and how different positional schemes fare with zero adaptation.
- 10 RoPE Scaling: NTK-aware and YaRN How a 4k-token base checkpoint becomes a 128k-token release without pretraining from scratch, by rescaling RoPE's rotation frequencies rather than its raw positions.
- 11 The NoPE Result Decoder-only transformers trained with zero positional encoding of any kind matched or beat RoPE and ALiBi on length generalisation, because the causal mask alone leaks a position signal.
Transformer Anatomy The block, the stack, encoder vs decoder, MoE, and the design choices that separate model families. 14 concepts · 58 cards
- 01 Anatomy of a Transformer Block The exact sequence of operations inside one transformer block, from tensor shapes to parameter counts, and why every frontier model is just this same function stacked dozens of times.
- 02 Decoder-Only and Why It Won Why a single causal stack with one unified training objective beat two-stack and bidirectional designs at scale, and the bidirectional context it deliberately gives up to get there.
- 03 Depth, Width, and Aspect Ratio Given a fixed parameter budget, why pretraining loss barely cares whether you go deep or wide, and the hardware and capability reasons architects still don't pick the ratio at random.
- 04 Encoder-Decoder Models (T5) T5's text-to-text framing and the extra cross-attention sublayer that lets a decoder condition on a separately-encoded input, and the real cost/benefit case for keeping two stacks instead of one.
- 05 Encoder-Only Models (BERT) BERT's bidirectional masked-language-model objective, why it makes phenomenal embeddings and classifiers, and why that same bidirectionality makes it structurally unable to generate open-ended text.
- 06 Feed-Forward Networks and SwiGLU The other half of every transformer block, where most of the parameters and arguably most of the stored knowledge live, and why the activation function quietly became SwiGLU.
- 07 Layer Normalization and Residual Connections The two pieces of transformer plumbing that make deep stacks trainable at all, why pre-norm beat post-norm, and how RMSNorm shaved the design down further.
- 08 Parallel Attention and FFN Computing attention and the feed-forward sublayer from the same normalised input instead of sequentially, trading a small representational restriction for less synchronisation on the way to more throughput at scale.
- 09 Sub-Layer Ordering and Design Choices The menu of ordering decisions inside and across transformer blocks beyond pre-norm versus post-norm, from where the final normalisation sits to why attention always runs before the feed-forward sublayer.
- 10 Transformer Architecture The encoder-decoder stack that replaced recurrence and powered every modern LLM.
- 11 Mixture of Experts Why MoE models can be 10x cheaper to serve than dense models of the same capability, and what makes them hard to train.
- 12 Prefix Language Models A single decoder-only stack that grants bidirectional attention to a prefix segment before switching to causal generation, and why the field mostly passed on this compromise anyway.
- 13 QK-Normalisation Normalising queries and keys before the attention dot product to stop logits from blowing up at scale, the fix that made 22-billion-parameter and larger transformers trainable without loss spikes.
- 14 Weight Initialisation in Transformers Why the last matrix in every attention and FFN sublayer gets shrunk by 1/sqrt(2N) at initialisation, and the more principled framework, muP, that turns hyperparameter tuning at scale into a lookup instead of a search.
Training Objectives Next-token prediction, masked LM, span corruption, fill-in-the-middle, and auxiliary losses. 13 concepts · 66 cards
- 01 Next-Token Prediction and Cross-Entropy Loss The single objective behind every LLM - predict the next token - and the cross-entropy loss that turns "predict well" into a gradient the model can descend.
- 02 Softmax and Logits How a model's raw output scores become a probability distribution, why the exponential matters, and the numerical trick that keeps softmax from overflowing.
- 03 The Causal LM Pretraining Task How a corpus of raw documents becomes millions of training examples under one masking rule, and why "causal" describes a data and attention decision, not just a loss.
- 04 Fill-in-the-Middle A way to teach a plain causal decoder to infill text by rearranging training documents, not the model, so a single architecture serves both left-to-right generation and code-editor-style completion.
- 05 Label Smoothing Softening a one-hot target so the model is never rewarded for driving a correct-class probability all the way to 1, trading a little training loss for calibration and generalisation.
- 06 Loss Masking in Fine-Tuning Supervised fine-tuning uses the same shifted next-token loss as pretraining, computed over the exact same kind of sequence; the only change is that most of the sequence is excluded from the loss entirely.
- 07 Masked Language Modelling BERT's pretraining task hides tokens instead of futures, trading the ability to generate text for representations that read both directions at once.
- 08 Pretraining Objectives Why the loss a model is trained to minimise decides what it can become, and how next-token prediction beat masked and span objectives to own the generative era.
- 09 Sequence Packing and Document Masking Concatenating short documents to fill a fixed context length eliminates padding waste, but only if the attention mask and position IDs are made document-aware; done naively, packing quietly teaches the model to attend across unrelated documents.
- 10 Span Corruption T5's pretraining task hides whole spans instead of single tokens and asks a decoder to generate only the missing pieces, trading BERT's per-token reconstruction for a shorter, cheaper target sequence.
- 11 MoE Load-Balancing Loss Without an explicit penalty, a mixture-of-experts router collapses onto a handful of favourite experts within the first few hundred steps; the auxiliary load-balancing loss is the mechanism that stops it.
- 12 The Softmax Cross-Entropy Gradient The combined derivative of softmax and cross-entropy collapses to one subtraction, predicted probability minus true label, and that simplification is why every production training loop fuses the two ops instead of computing them separately.
- 13 Z-Loss and Logit Regularisation Softmax is shift-invariant, which leaves a direction in logit space that cross-entropy never penalises; z-loss closes that gap and is what keeps large-scale bf16 training from spiking.
Decoding & Generation Greedy, beam, temperature, top-k, nucleus, and constrained generation into structured formats. 12 concepts · 51 cards
- 01 Greedy Decoding The simplest possible decoder, take the single most probable token at every step, and why that local optimality guarantees nothing about the sentence you end up with.
- 02 Temperature Sampling Dividing logits by a scalar before softmax to sharpen or flatten a model's output distribution, and why temperature alone is a poor substitute for a real safety mechanism.
- 03 Top-k Sampling Truncating the vocabulary to a fixed-size shortlist of the k most probable tokens before sampling, and why a fixed k is systematically the wrong size for at least some fraction of every distribution.
- 04 Beam Search Keeping the k best partial sequences alive instead of committing to one token at a time, and why the strategy that dominates machine translation actively hurts open-ended generation.
- 05 Determinism and Reproducibility in Decoding Why "temperature zero" and "same seed" both promise less determinism than they sound like they do, and where the real sources of nondeterminism live in an inference stack.
- 06 Logit Bias and Masking Directly editing the logit vector before sampling, additive nudges for soft steering, hard -infinity masks for guaranteed exclusion, and why the two are not interchangeable.
- 07 Neural Text Degeneration The umbrella diagnosis behind most decoding research, why decoders that maximise sequence probability produce measurably worse text than decoders that sample from the model's actual distribution.
- 08 Nucleus (Top-p) Sampling Truncating by cumulative probability mass instead of a fixed rank, so the candidate pool automatically shrinks when the model is confident and grows when it is uncertain.
- 09 Repetition Penalty and No-Repeat N-Grams Two blunt but effective ways to stop a decoder from looping, subtracting from the logits of tokens already seen, versus hard-banning any n-gram that has already appeared.
- 10 Sampling and Decoding A language model outputs a probability distribution, not text; the decoding strategy turns that distribution into words and quietly decides whether the output is dull, unhinged, or right.
- 11 Structured Generation and Constrained Decoding How masking the logits at each decode step to only tokens a schema or grammar allows guarantees syntactically valid output, and where that guarantee stops.
- 12 Min-p and Typical Sampling Two later refinements to nucleus sampling, one that scales the truncation threshold to the top token's own confidence, one that truncates by information content rather than raw probability rank.
Context & In-Context Learning Autoregressive generation, the prompt stack, context engineering, and long-context degradation. 6 concepts · 28 cards
- 01 Autoregressive Generation How a language model turns next-token prediction into a paragraph, and why generation is a loop that feeds its own output back as input.
- 02 Context Engineering The discipline of curating exactly which tokens occupy the model's window during inference, and why it became the core skill for building agents that run longer than a single turn.
- 03 In-Context Learning How large models learn a task from examples in the prompt alone, with no weight updates, and why this emergent ability reframed how we use LLMs.
- 04 The Prompt Stack and Chat Roles What a chat prompt actually is under the hood: a single token sequence built from system, user, and assistant turns wrapped in special tokens, and why that structure is load-bearing.
- 05 Context Rot The measured fact that model accuracy falls as the input grows, non-uniformly and in cliffs, so a bigger window is a bigger desk rather than a better memory.
- 06 Context Windows and Long-Context Models Why a model advertised at a million tokens can still lose the fact in the middle, and what actually sets the limit: memory, compute, position, and attention itself.