How neural architectures evolved
Architectures differ in how information can move between positions. Track which inputs can influence each output and you can see why different designs suit different data.
Open this chapter with experiments and audio
What does a shared filter detect?
Take four consecutive brightness readings, [2, 2, 8, 8]. Slide a filter with weights [−1, 1] across adjacent pairs. It computes the difference between neighbours. The outputs are 0, 6 and 0. A bright edge has a strong response at exactly one position. Moving the edge moves that response. The same two weights are used at every position.
Inspect each neighbouring pair. Try reversing the signs of the weights, then select the averaging filter.
Reversing the filter changes a positive edge response into a negative one at the same position. With weights 0.5 and 0.5, the output becomes a local average. The architecture is the same, while its parameter values select a different operation.
pixels = [2, 2, 8, 8] print([right - left for left, right in zip(pixels, pixels[1:])])
A convolutional neural network learns many local filters from data. A second layer can combine edge responses into corners and textures. Stacking layers increases the region that can influence each output. This local structure is helpful for images and can also be used with audio or text.
How does a recurrent network carry context?
An RNN receives one token and its previous hidden state. It computes a new state, then uses that state for the next token. In the phrase “the small red box”, information about “small” can reach “box” by travelling through successive states. The operations on these states have a dependency across time. State three needs state two first.
During training, a distant signal travels backwards along that chain as well. Gradients may shrink or grow repeatedly, making long dependencies hard to learn. An LSTM adds gates that regulate what is stored, retained and read out. That gives information a more direct route through time.
How did sequence-to-sequence translation change?
An early encoder–decoder could read a whole sentence into a final state and start the translation from there. Longer sentences put pressure on that fixed-size summary. Attention lets the decoder consult multiple source positions while producing a word. Different output words can draw different amounts of information from the same source sentence.
Which dependency changes in a Transformer?
The original Transformer introduced an attention-based encoder–decoder for translation. Self-attention gives each position a direct path to other allowed positions in the same layer. During training, the input sequence is already available, so many positions in a layer can be computed in parallel. During ordinary autoregressive generation the next sampled token must still be known before predicting the one after it.
Does this history imply that a Transformer is always the best choice for an image or a stream?
No. Local filters, recurrent states and attention make different trade-offs in memory, parallelism and how much data is needed. The useful inductive bias and constraints depend on the task.
How far back can one output receive a signal?
A vibration sensor produces five readings in time order. You want the output at the fifth reading to respond to a disturbance at the first. Ask which earlier inputs have a path to that output. In a causal convolution of width three and stride one, an output combines its current reading with the two immediately previous ones. With one layer the fifth output can depend on readings 3, 4 and 5. Reading 1 is outside its reach, whatever the learned weights.
Stack two such layers. The fifth output now reads first-layer positions 3, 4 and 5. Those positions read input ranges 1–3, 2–4 and 3–5. Their union covers 1–5. A signal from reading 1 can reach reading 5 through position 3 in the middle layer. This receptive field tells you what can influence the answer. A particular setting of the weights can still suppress that signal.
How would recurrence and full causal self-attention connect those same readings?
A recurrent model passes a state from reading to reading, so information from position 1 must survive four subsequent state updates to reach position 5. One full causal attention layer lets position 5 compare directly with every position from 1 through 5. Across all five outputs the mask permits 1 + 2 + 3 + 4 + 5 = 15 query–key pairs. This counts permitted dependencies, not measured time or the number of useful relationships learned.
Inspect one permitted query–key comparison in the working decoder →
Further reading · PyTorch · Conv1d · Vaswani et al. · Attention Is All You Need, §3.2