CNNs to transformers
Convolutions, embeddings, attention, and why transformers ate everything. Be able to explain self-attention with shapes, not hand-waving.
The mental model
The arc from convolutions to transformers is a story about how a model decides which other parts of the input to look at. A convolution is a stencil that only sees its immediate neighbors — it slides a small window across an image and detects local patterns (edges, then textures, then shapes as you stack layers). Its superpower is a strong prior: nearby pixels are related, and the same feature detector is reused everywhere (translation invariance). Its limitation is that anything far apart only gets combined after many layers, and it cannot flexibly decide that pixel A matters to pixel Z.
Attention is a spotlight operated by the content itself. For every position, the model asks "which other positions are relevant to me right now?" and computes a weighted blend of them — where the weights are computed from the data, not fixed by the architecture. A word representing "it" can look directly at "the trophy" three words back, in a single layer, regardless of distance. That is the one idea: attention replaces a fixed locality prior with a learned, content-dependent, all-to-all routing of information.
The WHY transformers ate everything: convolutions and RNNs bake in assumptions (locality, sequential order) that are helpful when true and a straitjacket when not. Attention makes almost no structural assumption — it lets the model learn what to attend to — and, crucially, it is fully parallel across positions (an RNN must process token 1 before token 2; a transformer processes all tokens at once). That parallelism is what let transformers scale to enormous data and parameter counts on GPUs, and scale is what produced the capabilities. The cost is that attention is O(n²) in sequence length and, having weak priors, it needs a lot of data to learn what a CNN gets for free. Being able to explain self-attention with shapes — not hand-waving about "the model pays attention" — is the line between a candidate who read a blog and one who understands the mechanism.
- Deep dive
- Internal architecture
- Real-world use cases
- Best practices
- Common mistakes
- Performance
- Security
- Production troubleshooting
- Advantages & disadvantages
- Alternatives
- Interview expectations
- Interview questions
- Facts to remember
- Cheat sheet
- Quick revision