Part II · ML foundations · Chapter 14
From perceptron to transformer: the bottlenecks
The road from a single artificial neuron to the transformer is a chain of bottlenecks, each removed by one idea. Knowing the chain explains why today's models look the way they do, and which limits they still have.
The transformer's design is a list of answers to old problems: residual connections for vanishing gradients, attention for the fixed-size memory of recurrent networks, parallel processing for slow training. Its own bottleneck, the cost of attention over long inputs, is why context windows are limited and why context engineering exists.
The chain at a glance
| Era | Idea | The bottleneck it hit | What removed it |
|---|---|---|---|
| 1958 | Perceptron: one neuron with a learning rule | Only straight boundaries; cannot learn XOR | Hidden layers trained by backpropagation |
| 1986 | Backpropagation through multilayer networks | Deep stacks of sigmoids stop learning (vanishing gradients) | ReLU, careful initialisation, normalisation, residual connections |
| 1990s | Recurrent networks (RNNs) for sequences | Forget anything more than a few steps back | LSTM gates |
| 2014 | Sequence-to-sequence: one network reads, another writes | The whole input squeezed into one fixed-size vector | Attention |
| 2017 | The transformer: attention without recurrence | Attention cost grows with the square of the input length | Still open: longer windows, cheaper attention, retrieval |
The perceptron and XOR
The perceptron of 1958 is one neuron with a step activation: output 1 if w1x1 + w2x2 + b > 0, else 0. Its learning rule is simple: when it is wrong, add (target − prediction) × input to the weights. For AND it finds a line within a few passes. For XOR, which outputs 1 when exactly one input is 1, it never settles.
Why XOR is impossible for one line: we would need (0,1) and (1,0) above the line, so w2 + b > 0 and w1 + b > 0, and (0,0) and (1,1) below, so b ≤ 0 and w1 + w2 + b ≤ 0. Add the first two: w1 + w2 + 2b > 0. But the last two give w1 + w2 + 2b ≤ b ≤ 0. A contradiction. The 1969 book "Perceptrons" made limits like this famous, and funding for neural networks dried up for years.
A hidden layer solves it
Two hidden neurons are enough. Let h1 compute OR (fire if x1 + x2 − 0.5 > 0), let h2 compute AND (fire if x1 + x2 − 1.5 > 0), and let the output fire if h1 − h2 − 0.5 > 0: "OR but not AND".
| x1, x2 | h1 (OR) | h2 (AND) | h1 − h2 − 0.5 | output |
|---|---|---|---|---|
| 0, 0 | 0 | 0 | −0.5 | 0 |
| 0, 1 | 1 | 0 | 0.5 | 1 |
| 1, 0 | 1 | 0 | 0.5 | 1 |
| 1, 1 | 1 | 1 | −0.5 | 0 |
The hidden layer moves the points into a new space where one line works. But a step function has zero slope, so these weights cannot be learned by gradient descent. The 1986 paper "Learning representations by back-propagating errors" popularised smooth activations and backpropagation (chapter 12), so hidden layers could be trained. The trainer in chapter 12 learns XOR this way.
Vanishing gradients and ReLU
With backprop, people tried deeper networks and found the early layers barely learned. The chain rule multiplies one factor per layer, and a sigmoid's slope is at most 0.25. Through 10 sigmoid layers the gradient shrinks by up to 0.2510 ≈ 10−6. The early layers, which should learn the basic features everything else builds on, receive almost nothing. The opposite problem, exploding gradients, happens when the factors are larger than 1.
The fixes arrived over a decade:
- ReLU (widely adopted around 2010 to 2012): its slope is exactly 1 for positive inputs, so it does not shrink the gradient where it is active.
- Initialisation that keeps signal sizes steady (chapter 13).
- Normalisation layers (2015 and 2016) that keep each layer's inputs well scaled.
- Residual connections, from "Deep Residual Learning for Image Recognition" (2015), which add a direct path for the gradient around each layer. Networks of over a hundred layers became trainable.
Two outside changes mattered as much: large labelled datasets such as ImageNet, and GPUs. In 2012 a deep convolutional network trained on GPUs won the ImageNet image-recognition competition by a wide margin, and the field turned towards deep learning.
Sequences: recurrent networks and LSTMs
Text is a sequence. A recurrent neural network reads it one token at a time and carries a hidden state forward, a vector that is meant to summarise everything so far:
Training it means backpropagating through time, and the same multiplication problem returns, now along the sequence. If each step back multiplies the gradient by about 0.5, the signal from 20 tokens ago arrives scaled by 0.520 ≈ 0.000001. In "The money I lent to my sister, who lives in Lisbon and works as a nurse, has not been paid back", a plain RNN struggles to connect "paid back" to "money".
The LSTM ("Long Short-Term Memory", 1997) adds a separate cell state updated by addition rather than repeated multiplication, with learned gates that decide what to forget, what to write and what to read. When the forget gate is near 1, the gradient passes back almost unchanged, the same trick as a residual connection. LSTMs powered machine translation and speech recognition through the mid-2010s.
Two bottlenecks remained. Every step depends on the previous one, so an RNN cannot process the tokens of a sentence in parallel, and training on huge text collections is slow. And in sequence-to-sequence translation ("Sequence to Sequence Learning with Neural Networks", 2014), the encoder squeezes the whole source sentence into one fixed-size vector before the decoder begins. A 5-word sentence and a 50-word sentence get the same few hundred numbers.
Attention
"Neural Machine Translation by Jointly Learning to Align and Translate" (2014) let the decoder look back at every encoder state when producing each word, weighting them by relevance. To translate one word, the model scores each source position, turns the scores into weights with a softmax (chapter 9), and takes the weighted average of the source states. Nothing has to be squeezed into one vector; the model learns where to look.
The transformer
"Attention Is All You Need" (2017) removed recurrence entirely. Every token attends to every other token directly, and a whole sequence is processed in parallel, which suits GPUs perfectly. Residual connections and layer normalisation, the fixes for deep training, are built into every block. This made it practical to train on far more text than before, and the GPT line of models followed: "Language Models are Few-Shot Learners" (2020) showed a model that could do new tasks from a few examples in its prompt, and "Training language models to follow instructions with human feedback" (2022) described the tuning that turned such models into assistants (chapter 19).
The transformer has its own bottleneck. Attention compares every token with every other, so its cost grows with the square of the input length: doubling the input from 1,000 to 2,000 tokens quadruples the attention work from 1 million to 4 million comparisons. That is why context windows have limits, why long prompts cost more and slow down, and why systems retrieve a few relevant passages instead of pasting in every document (chapter 24).
A gradient passes back through 15 layers, each multiplying it by 0.6. Roughly how much of it is left? What if each layer had a residual connection and its own factor of 0.6 were added to 1 instead?
Answer
Without: 0.615 ≈ 0.00047. With residuals each factor is 1 + 0.6 = 1.6, so nothing vanishes (in practice normalisation keeps it from exploding instead).
Keeping inputs bounded
Almost every model a developer calls today is a transformer: the hosted language models and the embedding models alike. Well-built applications keep each call's input bounded, which keeps that quadratic cost small. They reject or shorten an overlong question (a cap of 2,000 characters is typical for a chat box), and they retrieve a handful of passages, three to five, rather than reading whole documents.
In Lab 3 you retrieve only the best few passages for each question instead of pasting in the whole document set.
Self-check
Why can a single perceptron not learn XOR?
Its decision boundary is one straight line, and no straight line puts (0,1) and (1,0) on one side with (0,0) and (1,1) on the other.
What problem did ReLU help with, and how?
Vanishing gradients. Its slope is 1 for positive inputs, so it does not shrink the gradient the way a sigmoid (slope at most 0.25) does.
What was the bottleneck of 2014 sequence-to-sequence models, and what removed it?
The whole input had to be compressed into one fixed-size vector. Attention removed it by letting the decoder look at every encoder state directly.
What is the transformer's own bottleneck?
Attention cost grows with the square of the sequence length, which limits context windows and makes long prompts slow and expensive.
Further reading
- Perceptron (Wikipedia) article beginner
History and mechanics of the perceptron, including the XOR limitation that stalled early neural network research. - Why are deep neural networks hard to train? (Neural Networks and Deep Learning, chapter 5) article intermediate
Michael Nielsen's free chapter showing the vanishing gradient problem with experiments and a derivation. - Deep Sparse Rectifier Neural Networks (2011) paper advanced
Early paper arguing for ReLU units over sigmoid and tanh in deep networks. - The Unreasonable Effectiveness of Recurrent Neural Networks article intermediate
Karpathy's classic post on what character-level RNNs can learn, a snapshot of the pre-transformer era.
Free, checked on 2026-10-21. All resources for this chapter and 3 more.