A transformer is an encoder–decoder sequence-to-sequence model that uses attention in both branches instead of relying on recurrent neural networks. Self-attention is its central component: it lets the model weight information from different parts of a sequence. section 11.3 section 11.7
Attention relates queries Q to key–value pairs K and V. A normalized similarity score determines how strongly each query weights the values; softmax makes those weights sum to one. In neural machine translation, target-sequence queries attend to source-sequence keys and values. section 11.3
The architecture combines attention with components that preserve and process sequence information:
- Multihead attention runs attention in parallel, then concatenates and transforms the resulting heads. section 11.3
- Positional encodings are added to input embeddings so token representations reflect sequence position. section 11.3
- Dense and normalization layers accompany residual connections, which ease gradient backpropagation. section 11.3
Figure 11.10 Transformer architecture
The architecture diagram locates the encoder and decoder branches and their attention and positional-encoding components. section 11.3
Text classification
A transformer can be implemented for text classification with Keras/TensorFlow. The accompanying training and validation plots track classifier loss and accuracy; this application is distinct from the encoder–decoder translation example used to explain attention. section 11.0 section 11.3



























