A transformer is a neural network architecture that keeps token information separate while progressively contextualizing each token. This helps an LLM distinguish “the dog’s bark was barely” from “the tree’s bark was barely,” leading to “audible” versus “visible.” section 1.18
The high-level flow is straightforward:
- Map input tokens to embedding vectors. section 1.18
- Contextualize those embeddings using the preceding tokens instead of compressing the entire prompt into one summary vector. section 1.18
- Use the improved embeddings to predict the next token. section 1.18
Earlier LSTM-based language models summarized all preceding context in one fixed-size embedding. That made variable-length inputs convenient but could erase the fine-grained information needed to resolve ambiguity. Transformer layers instead calculate attention scores and use them to update embeddings. section 1.18 section 1.24
Disambiguating “bark”
Given “the dog’s bark was barely,” the model predicts “audible.” Given “the tree’s bark was barely,” it predicts “visible.” The surrounding noun changes the token’s contextual meaning. section 1.18
Figure 1.9 LLM overview. In step 1, the tokens are mapped to embeddings one by one. In step 2, each embedding is improved by contextualizing it using the previous tokens in the prompt. In step 3,
the much-improved embeddings are used to make predictions about
the next token.
Use the overview figure to trace the three-stage path from tokens to embeddings, contextualized representations, and next-token predictions. section 1.18



























