The Rabbit Hole / AI and machine learning
AI and machine learning
Explore how models learn, process language and work with images and sound. Visual explanations and experiments, from the first neuron to the latest architectures.
Start with a neuron
Try a small network, watch it learn, and build up from there.
Take the first step →See the ideas in actionExplore model architectures
Open a real model’s diagram and follow the parts you want to understand.
Browse 137 architecture maps →Model benchmarks
See where open and closed models sit. Explore capability, coding, reasoning and memory results, then compare performance against model size.
Explore the benchmark charts →Neural networks
Build an intuition for learning, layers and recognising patterns.
How neural networks learn
Start with one neuron, then explore layers, learning and recognising patterns.
- A neuron that learns
Teach one neuron from its mistakes, then discover gradient descent and backpropagation.
- Neural network layers: more inputs, more neurons
Why neural networks need non-linear activation functions such as ReLU. Can extra neurons learn a curve that one neuron cannot?
- Convolutional neural networks (CNNs): from pixels to a digit
Build a convolutional network for MNIST digits. How do learned filters and pooling turn pixels into a vote?
- Image classification: recognising more than digits
Reading a digit is one thing. Recognising a dog in a photograph is another. How far can the same idea take us?
- Residual connections: when more layers made things worse
ResNet made deeper networks work with residual connections. Why did adding layers make a plain network worse?
Language models
Start with the complete path from text to prediction, then explore how models extend it.
Inside a language model
A reading path from tokens and embeddings to attention, one transformer layer and the whole model.
Read in order · 6 articles
- Tokenisation and BPE: cutting text into tokens
Byte-pair encoding (BPE) turns text into reusable token pieces. How should a language model split words before calculating with them?
- Embeddings: giving every token a meaning
We gave every token a number. But why should hare be closer to rabbit than to Tuesday?
- Next-token prediction: why only the last column predicts
Every token gets an output. So why do we read only the last one when a language model writes?
- Attention, from scratch
Self-attention lets the same token gather different clues from its context. How does a model tell a living rabbit from a chocolate one?
- Transformer layers: attention is only half of what you need
Explore the feed-forward network (FFN or MLP), from activations to gated linear units (GLU) such as SwiGLU and GeGLU.
- A whole LLM, layer by layer
A large language model (LLM) combines tokens, attention and feed-forward networks. How do those parts become a model that writes?
Giving tokens a sense of position
Start with RoPE, then stretch it to longer texts and explore other ways to bring token order into attention.
- RoPE: position as a rotation
Rotary positional embeddings (RoPE) encode position through rotations. Could they tell attention how far apart two tokens are?
- RoPE scaling: stretching context beyond the training length
Position interpolation, NTK-aware scaling and YaRN extend rotary embeddings. What changes when an 8,000-token model reads 60,000 tokens?
- Partial RoPE: rotating only part of each head
If position helps attention, why give it to only part of each head? What might the remaining coordinates be useful for?
- NoPE: attention with no position information at all
No positional embeddings (NoPE) removes explicit position information. Can attention still keep track of the order of the text?
Keeping values in range
Normalise vectors, place the norm, and stop attention scores and activations from growing too large.
- RMSNorm: keeping a token's scale under control
Root mean square layer normalisation (RMSNorm) controls vector scale. How does it work, and what does it simplify compared with LayerNorm?
- Pre-norm and post-norm: follow the residual path
Pre-norm (Pre-LN) and post-norm (Post-LN) change where normalisation sits around the residual branch. What does that do to the layer?
- QK normalisation (QK-Norm) and soft-capping
Query-key normalisation (QKNorm) and logit soft-capping control attention scores. What happens when one score overwhelms the others?
- Gated RMSNorm: controlling the layer's output
Gated RMSNorm combines RMS normalisation with a SiLU gate. Could the current token control how much of each coordinate reaches the residual stream?
The residual stream
Change how layers read from and write to the stream: wider streams, scaled skips and extra paths.
- Parallel layers: does feed-forward have to wait?
Attention runs, then feed-forward runs. Could we let them start together?
- Hyper-connections: more than one residual stream
Hyper-connections and manifold-constrained hyper-connections (mHC) give the residual stream multiple paths. How should those paths mix?
Inside attention
Small changes inside attention: gates, bias terms and the tokens that collect spare attention.
- Attention sinks: where does unused attention go?
What could a token that appears in every sentence learn to contribute?
- Attention gating: should this head add anything?
A head has collected information. How does the model decide how much of it to use?
Tokens and embeddings
Other ways to turn text into vectors: extra lookups per layer, n-gram tables and bytes instead of tokens.
- Per-layer embeddings (PLE): could each layer look up the token again?
Could each layer look up static information about a token, leaving more feed-forward capacity for other concepts?
Remembering context efficiently
Understand the KV cache and how sharing, compression and quantisation make it smaller.
- The KV cache: why LLMs remember every key and value
A model has already read your sentence. Why should writing the next token make it read everything again?
- Multi-query attention (MQA): one key and value for every head
Our cache grows with every token. How much of it does each head need to keep for itself?
- Grouped-query attention (GQA): sharing keys and values in groups
One shared set of keys and values saved a lot of memory. Do all the heads have to share the same set?
- Multi-head latent attention (MLA): caching a compressed latent
The heads need keys and values. Do we have to store them in that form?
- KV cache quantisation: storing keys and values in fewer bits
Every cached number takes 16 bits. How many could we drop before the model stops noticing?
- PagedAttention: managing the KV cache like virtual memory
Some chats stay short; others run on for pages. How does a server make room for both without leaving most of its memory empty?
- Shared K/V: could one entry do both jobs?
MQA already shares the cache across query heads. Could tying K and V reduce its memory further?
- Heavily compressed attention (HCA): keeping a compressed history
Keep recent tokens individually, learn what to preserve from each older block, and discover heavily compressed attention.
- Compressed sparse attention (CSA): keeping more detail and reading less
Start with the information lost by heavy compression, emit summaries more often, then select which ones each query reads.
- Compressed sparse attention 2 (CSA2): keep detail, narrow the search
A query needs a detail that compression may have mixed away. Could we keep finer history without making every layer search it all again?
- KV sharing across layers: could later layers reuse an earlier cache?
Cross-layer attention (CLA) shares cached keys and values between layers. Could later queries reuse history that an earlier layer already prepared?
Working with longer context
Keep a local window, mix local and global layers, or learn which entries or blocks attention should read.
- Sliding-window attention (SWA): a cache that stops growing
A conversation never stops growing, and neither does its cache. Does every token need to see all of it?
- Sparse attention and the lightning indexer
DeepSeek Sparse Attention (DSA) uses a lightning indexer to choose which cached entries to read. Must every query inspect the whole history?
- IndexShare: could neighbouring layers reuse the search?
An indexer has already found candidate positions. Discover what another layer can reuse, what it must recompute, and when the selection needs refreshing.
Choosing and combining experts
Learn how mixture-of-experts models route work and balance their specialists.
- Mixture of experts (MoE): a big model that uses only part of itself
A model can hold hundreds of billions of weights. Does every token really need to use all of them?
- Shared experts: a path every token takes
Every token chooses its specialists. What about the work that almost every token needs?
- Routing: selecting experts and weighting their work
A token has hundreds of experts to choose from. Who gets the job, and what if everyone chooses the same few?
Generating text
Explore predicting several tokens, speculative decoding and text generation through diffusion.
- Multi-token prediction (MTP): learning to look further ahead
Each column learns to predict one token. Would asking it to look one step further change what it learns, or how fast it writes?
- Speculative decoding: guessing ahead and checking in one pass
Writing one token at a time is slow. Could a model check several guesses faster than it can make them?
- Text diffusion: writing a block of tokens by cleaning up noise
Must a language model write from left to right? What if it could fill in a whole block of text at once?
Running models efficiently
Store weights in fewer bits, read prompts faster, overlap expert communication and grow trained models.
- Weight quantisation: could we store the model in fewer bits?
Low-bit weight quantisation, including GPTQ and MXFP4: could nearby weights share fewer stored representations without losing useful behaviour?
- Encoder-decoder prefill: must every layer read the whole prompt?
Prepare a shared history in the encoder, let the decoder read it, and discover why a short local replay is still needed before generation.
Alternative language-model architectures
Explore recurrent models, state-space models and architectures that combine approaches.
- Linear attention: a fixed-size memory instead of a growing cache
Can we collect the writes before a query arrives, so the conversation grows without growing a cache in every layer?
- Gated DeltaNet: write the correction, not the whole fact
Linear attention averages the writes it receives. Could a later write correct an existing association instead?
- Mamba: letting each token control what the state keeps
Mamba uses selective state-space models (SSMs) to carry a fixed-size memory. Could each token control what it writes and keeps?
- Hybrid attention and SSM models: different kinds of memory
Combine attention with state-space models (SSMs): some layers retain separate cache entries, while others carry a fixed-size state.
- Short convolution: what if a layer only mixed nearby tokens?
A short causal depthwise convolution mixes nearby tokens. Could some layers do useful work using only the current token and a few neighbours?
Understanding images and sound
Discover how language models represent visual and audio inputs.
- Vision encoders: how can image patches join the text?
Text has token embeddings. Could a Vision Transformer (ViT) give images something similar, without fixing their shape or discarding too much detail?
- Audio inputs: how can a language model listen?
A recording is a stream of measurements, not words. What should an audio position contain so a language model can use it?
More articles are on the way, from here towards how large language models work.