A transformer is a neural-network architecture for processing sequences. It represents tokens as numbers, compares their relationships, and predicts useful outputs. In language models, it predicts tokens rather than literally understanding language or reasoning like a person. section 3.1 section 3.1.1
The basic pipeline has three parts: an embedding layer maps tokens to meaning-bearing vectors; repeated transformer layers relate those vectors; and an output layer converts numerical results into readable words. Position information is added because word order does not arise naturally from token representations. section 3.1.1 section 3.5
Attention supplies the architecture’s flexible way to connect sequence elements:
- Treat a query as what the model is looking for, keys as possible matches, and values as information associated with those matches. section 3.2.2
- Compare every key with a query by similarity, weighting stronger matches more heavily instead of requiring an exact dictionary lookup. section 3.2.2
- Use attention to emphasize relevant information and reduce the influence of distracting information; what matters changes with the available alternatives. section 3.2.2
- Feed previously generated tokens back into the model at each step, then produce probabilities for every possible next token before selecting one. section 3.5
A fuzzy dictionary
A Python dictionary needs an exact key to return a value. A transformer instead compares a query with all available keys and combines their values according to similarity. In next-token prediction, the current token acts as the query and preceding words provide keys. The result is not a guaranteed answer: it is a probability distribution from which a token can be selected, with randomness affecting consistency and creativity. section 3.2.2 section 3.5
Figure 3.1 The basic components of the transformer model, consisting of the embedding layer, multiple transformer layers, and the output layer
Use the architecture diagram to trace tokens through embeddings, multiple transformer layers, and the output layer. section 3.1.1
Transformer variants serve different jobs. Encoder-only models create representations for machine-learning tasks; decoder-only models generate continuations; and encoder-decoder models transform one passage into another, often helping with translation or summarization. Larger transformers can scale efficiently, but they demand more resources, increase prediction time, and may require remote hardware or continuous connectivity. section 3.1 section 4.5



























