An embedding layer converts discrete token identities into vectors: numerical representations that place related concepts near one another in a learned semantic space. “Dog” and “wolf” can therefore receive more similar representations than “red” and “France.” The layer does not discover timeless truth; its relationships can reflect patterns and biases in the training data. section 3.1.1 section 3.2.1
A transformer also needs to know where each token occurs. The layer creates a word embedding for token identity and a positional embedding for sequence location, then adds them together. Without the positional part, rearranged tokens would look identical even when word order changes the meaning. section 3.2.1
A token passes through the embedding stage in a small pipeline:
- The token identity is mapped to a meaning-oriented vector. section 3.1.1
- The token’s position is mapped to a position vector. section 3.2.1
- The two vectors are added, producing one representation that carries identity and location into the transformer layers. section 3.2.1
Meaning and order
A model can place “doctor” and “nurse” in a relationship shaped by the text used for training, but that relationship may reproduce social stereotypes rather than describe reality. Separately, shuffling the tokens in a sentence demonstrates why positional information is necessary: the same words in a different order are not necessarily the same statement. section 3.2.1 section 3.2.1
Figure 3.7 Word embeddings do not capture the fact that input tokens appear in a specific order. This information is captured by a positional embedding. The position embeddings work the same way as word embeddings and are added together. The resulting combined embeddings have the information the model needs to understand the order of tokens.
Shows how word and position embeddings are added so the resulting vector carries both token identity and sequence order. section 3.2.1



