Everything, in one block
This is the capstone: a Transformer encoder block that uses every idea in this track at once. It's a subclassed Layer (Lessons 1–3), it threads the training flag through its Dropout sub-layers (Lesson 4), and it's built to drop into a Functional model like any built-in (Lesson 5). The block holds four kinds of sub-layer — multi-head self-attention, a two-layer feed-forward network, two LayerNormalizations, and two Dropouts — and wires them in call() (see the Code block).
The two sub-blocks and their residuals
The shape is the original Transformer recipe: two sub-blocks, each wrapped in a residual connection. The first runs self-attention over the input, then adds the result back to the input (out1 = norm1(inputs + attn_output)) — the inputs + is the skip connection that lets gradients flow past the attention. The second runs the feed-forward network and adds its input back the same way. The two LayerNormalization layers stabilize each sub-block, and the residual adds are why a deep stack of these trains at all. This is post-norm (normalize after the add); many modern variants move the norm before the sub-layer (pre-norm) for steadier deep-stack training — a one-line change once you own the block.
Stack N of these and you have a Transformer encoder. Because you own the source, every research variant — RoPE, sparse attention, a LoRA adapter, grouped-query attention — is a small edit inside a class you control, not a fork of someone else's library.