A transformer is a neural network architecture for processing sequences. Unlike an RNN, which passes a recurrent state from one element to the next, it uses attention so each position can draw on information from other positions. This supports parallel processing and helps capture long-range relationships, making transformers useful for tasks such as translation and text generation. section 1.1 section 1.1.2
In the encoder–decoder design, the encoder turns an input sequence into contextual information that the decoder uses to produce an output sequence. Attention determines which parts of a sequence matter to a given position; multihead attention captures different relationships at the same time. Stacked layers combine attention with point-wise feed-forward networks, residual connections, and layer normalization. Positional encoding supplies information about token order. section 2.2 section 2.3
Figure 2.5 The encoder of the transformer architecture is depicted on the left side of the figure, and the decoder is depicted on the right side.
The architecture diagram places the encoder and decoder side by side, making their distinct roles and stacked components easier to trace. section 2.2
English-to-French translation
For “I don’t speak French” → “Je ne parle pas français,” the encoder processes the English sentence, and the decoder uses its contextual information to generate the French sentence. Attention relates each input element to the rest of the sequence rather than relying on a single state carried word by word. section 1.1.2
The design is a blueprint, not a single fixed model. Encoder–decoder variants suit translation, while decoder-only variants are common in text completion and conversational AI. Pretrained models in Hugging Face Transformers can be adapted to a task instead of trained from scratch, but model choice must account for computational and memory demands, especially at large scales. section 1.4 section 1.2 section 1.5



























