An encoder transforms a token sequence into contextual representations by passing embeddings through a stack of reusable transformer layers. section 9.2.2
The input receives positional encoding before entering the encoder. Each encoder layer combines multi-head attention with a positionwise fully connected feedforward network, while linear projections and layer normalization help organize the outputs. section 9.2.2
Its place in transformer designs is easiest to see through these contrasts:
- The original Transformer used six encoder layers alongside six decoder layers. section 9.2.2
- Decoder layers share the encoder’s attention, normalization, and feedforward structure but add mechanisms for generated-token input. section 9.2.2
- Later GPT architectures removed encoder layers and instead stacked many decoder layers. section 9.2.2
BERT as a bidirectional encoder
BERT stacks encoder transformers and trains them with masked language modeling: randomly masked tokens are predicted from both left and right context. Fine-tuning then adapts the resulting representations to sentence-level and token-level tasks. section 9.3
Figure 9.5 Transformer architecture
Use the transformer architecture diagram to trace positional encoding, encoder layers, decoder layers, normalization, and output-token flow. section 9.2.2




















