Networks for images: convolutions
An ordinary layer connects every input to every neuron. For a photo with a million pixels, that is a million weights per neuron, and the network would have to learn separately what an edge looks like at every position in the image. That is wasteful: an edge is an edge wherever it appears.
A convolutional neural network (CNN) uses a small filter instead, say 3 × 3 pixels with 9 weights, and slides it across the whole image, computing the same dot product at every position. One filter might light up wherever there is a vertical edge. Stack layers of filters and the network builds up from edges to textures to parts to whole objects, the ladder you saw in the neural networks lesson.
- 1989–1998: Yann LeCun’s LeNet reads handwritten digits; versions of it read millions of bank cheques.
- 2012: AlexNet, a much bigger CNN trained on two gaming GPUs, wins the ImageNet contest by a huge margin and starts the deep-learning boom.
- 2015: ResNet’s residual connections make CNNs 152 layers deep.
Networks with memory: RNNs
Text has an order, and the meaning of a word depends on what came before. A recurrent neural network (RNN) handles this by reading one token at a time and carrying a hidden state: a vector that acts as its memory of everything so far. At each step it combines the new token with the old state to make a new state.
- state₀Empty memory
- + “the” → state₁Remembers: a noun is probably coming
- + “cat” → state₂Remembers: the subject is a cat
- + “sat” → state₃Remembers: the cat did something; predict what comes next
stateₜ = bend(W · stateₜ₋₁ + U · tokenₜ)The same two matrices, W and U, are used at every step: weight sharing again, this time across time.
RNNs had two big problems. First, they forget: the whole past has to squeeze into one fixed-size vector, and the slopes for early tokens vanish as they pass back through many steps. A 1997 design called the LSTM (long short-term memory) added gates that decide what to keep, forget and output, and it powered speech recognition and, from 2016, Google Translate. Second, and worse, RNNs are slow to train: step 100 cannot start until step 99 is done, so the thousands of cores of a GPU sit waiting.
Quick check
Translation, and a bottleneck
In 2014, researchers at Google built a translator from two LSTMs, an idea called sequence to sequence (seq2seq). The encoder reads the whole English sentence and ends with one vector. The decoder starts from that vector and writes the French sentence one token at a time.
It worked surprisingly well, with one weakness you can probably guess: the entire meaning of the sentence, however long, had to pass through that one vector. Long sentences came out worse. The vector was a bottleneck.
The fix: attention
Also in 2014, Dzmitry Bahdanau, Kyunghyun Cho and Yoshua Bengio proposed a fix. Keep the encoder’s state for every source word, not just the last one. Then, each time the decoder writes a word, let it look back at all of them and decide how much each one matters right now. It scores every source word, turns the scores into weights with softmax, and takes a weighted average of their vectors. This is attention.
Three years later came the decisive step. If attention can connect any word to any other directly, why keep the slow, forgetful recurrence at all? The 2017 paper “Attention Is All You Need” dropped it entirely. Every token looks at every other token at once, so a whole sentence can be processed in parallel, exactly what GPUs are good at. That is the transformer, the subject of part 4.
RNN with attention (2014)
- Reads tokens one after another.
- Memory is a hidden state, plus attention over the source sentence.
- Training is slow, because the steps run in order.
Transformer (2017)
- Every token looks at every other token directly, through attention.
- No recurrence: the whole text is processed at once during training.
- Scales to huge data on GPUs, which is how today’s models were possible.
The comeback: recurrence returns
Transformers have a cost of their own. Every token attends to every earlier token, so the work grows with the square of the text length, and the memory each conversation needs (the KV cache) grows with every token. At a million tokens of context, that hurts. So researchers went back to the RNN’s great strength: a fixed-size state that does not grow, however long the text.
The new versions are designed so they can still be trained in parallel, which fixes the RNN’s old weakness. They go by names such as state space models and linear attention:
- Mamba (2023): a selective state space model with about 5 times the throughput of a transformer of the same size.
- Gated DeltaNet (2024): used in
Qwen3.8-27B, where 48 of its 64 layers are Gated DeltaNet and only 16 use full attention. - Kimi Delta Attention (2025): in Kimi Linear it cut the KV cache by 75 % and decoded up to 6 times faster at a million tokens; Kimi K3 uses it.
- Lightning attention: MiniMax-M1 mixes it with ordinary attention to reach a million-token context.
The winning recipe today is a hybrid: mostly cheap recurrent-style layers, with a few full attention layers mixed in to keep precise recall. Old ideas rarely die in AI; they wait for the right hardware and the right problem.
Which kind of network is described?
-
Slides a small filter across an image
Answer: CNN
-
Carries one hidden state from token to token
Answer: RNN
-
Lets every token look at every other token at once
Answer: Transformer
-
Won the ImageNet contest in 2012
Answer: CNN
-
Cannot start step 100 until step 99 is done
Answer: RNN
-
Introduced in “Attention Is All You Need”
Answer: Transformer
Remember
- CNNs slide small shared filters across images, building from edges to objects. AlexNet (2012) started the deep-learning boom.
- RNNs read text token by token with a hidden state as memory. They forget, and they are slow to train because the steps run in order. LSTMs helped with forgetting.
- Seq2seq translation squeezed a sentence into one vector, a bottleneck.
- Attention (2014) lets the decoder look back at every source word. The transformer (2017) kept attention and dropped recurrence, so everything runs in parallel.
- For very long contexts, linear attention and state space layers bring back a fixed-size state; models like Qwen3.8 and Kimi K3 are hybrids.
Words to know
- Convolutional neural network (CNN)
- A network that slides small shared filters across an image to detect patterns anywhere.
- Filter
- A small grid of weights, such as 3 × 3, applied at every position of an image.
- Recurrent neural network (RNN)
- A network that reads a sequence one step at a time, carrying a hidden state as memory.
- Hidden state
- The vector an RNN carries from step to step, summarising everything so far.
- LSTM
- An RNN with gates that decide what to remember and forget. Standard for text and speech before transformers.
- Encoder and decoder
- The part that reads the input, and the part that writes the output.
- Attention
- Scoring every earlier item, turning the scores into weights, and taking a weighted average, so a model can look where it needs to.
- Linear attention / state space model
- Newer layers with a fixed-size, RNN-like memory that can still be trained in parallel.
- Hybrid model
- A model that mixes cheap linear-attention layers with a few full attention layers.
Go to the source
This lesson is built on these papers and documents. Paper links open arxiv.org, a separate site.
-
Neural Machine Translation by Jointly Learning to Align and Translate
The paper that introduced attention. Look at Figure 3, the alignment pictures.
-
Sequence to Sequence Learning with Neural Networks
Encoder, decoder and the one-vector bottleneck that attention fixed.
-
Understanding LSTM Networks (C. Olah)
The clearest explanation of LSTM gates, with diagrams that half the field has borrowed since.
-
The Unreasonable Effectiveness of Recurrent Neural Networks (A. Karpathy)
A small character-level RNN writes fake Shakespeare and code. A charming look at language modelling before transformers.
-
Mamba: Linear-Time Sequence Modeling with Selective State Spaces
The model that made recurrent-style layers competitive again.
-
Gated Delta Networks: Improving Mamba2 with Delta Rule
The layer type used in most of Qwen3.8’s layers.
Check yourself
5 questions. Tap the answer you think is right.
0 of 5 answered
Lesson complete
Answer every question above to complete this lesson.
Your progress is saved on this device only.
Next lessonTokens: how a model reads