A transformer encoder layer combines multi-head self-attention with a position-wise feed-forward network. Layer normalization and residual connections stabilize the two-stage transformation, while stacking layers increases representation capacity and supports hierarchical feature extraction. section 3.3.4
Trace an input sequence through the layer:
- Normalize the input, then apply multi-head self-attention so each position can incorporate information from the sequence. section 3.3.4
- Add the attention output back to the original input through a residual connection. section 3.3.4
- Normalize the result and pass each position independently through a two-layer feed-forward network with an intermediate expansion and GELU activation. section 3.3.4
Vision-transformer encoder
For image classification, convert an image into patches, project each patch into an embedding, add positional encodings, and pass the sequence through four identical encoder layers. A final linear layer maps the resulting representation to ten CIFAR-10 class values. The same pattern can encode image patches for an image-captioning encoder. section 3.1.2 section 4.3.1


