Chapter 7 II.7
Encoder, Decoder, and Encoder–Decoder
Encoder, decoder and encoder–decoder differ only in what each stack may look at, and a mask is how that is enforced.
Three architectures, one difference: who is allowed to see whom.
How this chapter is built
M3Load-bearing
The content is mathematics. Understanding is demonstrated by computation, not recall.
Five strands, not one. Mathematics is the spine; the other four are the body. A chapter cannot pay its way out of teaching with problems, nor out of problems with teaching.
Before you start
The problem
The same block can be wired three ways, and the wiring decides whether the model classifies, generates, or translates. The whole difference is a matrix of zeros and minus infinities.
Apparatus
The mathematics this chapter leans on, held in Book 0 so it can be assumed here without being taught here. Not a gate — follow a link when a step stops making sense.
Distributions, discrete and continuous 0.PR.01 · Cross-entropy 0.IT.02
Notation
- TSequence length in tokens
- dModel width
- softmaxThe normalised exponential, applied row-wise unless stated
- LNumber of layers
Propositions
- Prop. 1A causal mask is what turns a transformer into a language model.Setting the future to minus infinity before the softmax lets every position in a sequence be trained as its own prediction problem, in a single forward pass.
- Prop. 2Encoder, decoder and encoder–decoder differ only in what each stack may look at.The block is unchanged in all three. What differs is the mask, and whether a second stack supplies the keys and values.
Worked problems
0/5 problems0/4 variants0/10 exercisesowes 15 more
Not yet written. At M3 this chapter owes 5 worked problems across 4 distinct variants, and 10 exercises, every one with a published solution. The build enforces that from the day the chapter is marked published.