liveBook · Manning

Positional embedding

As explained in LLMs in Production

Positional encoding is a method of adding sequence-position information to token representations in a transformer model.

Token embeddings capture what a token means, but not where it appears. Positional embedding adds sequence-position information so a transformer can distinguish identical tokens in different locations while preserving useful semantic similarity. section 2.3.1 section 2.1.1

Separating similar words by position

In “The cat in the hat rapidly leapt above the red fox and the brown unmotivated dog,” “red” and “brown” are semantically similar but occur at positions 10 and 14. Encoding separates their representations, while sine and cosine transformations restore much of their similarity. section 2.3.1

The technique works alongside embeddings and self-attention, allowing encoder models such as BERT to manipulate token vectors without losing the semantic comparisons established during embedding. section 2.3.1

Figure 2.5 An encoder visualized. Encoders are the first half of the full transformer architecture and excel in natural language understanding tasks like classification or named entity recognition. Encoder models improve upon previous designs by not requiring priors or recurrence and using clever positional encoding and multihead attention to create a vector embedding of each token.
figure

Use the encoder diagram to see positional encoding placed among token embeddings and multihead attention. section 2.3.1

How LLMs in Production covers it

How deep it goes
Explains positional separation, semantic-similarity effects, and sine-cosine recovery without deriving the encoding functions.
Examples
Uses the red-and-brown sentence example, token positions, cosine-similarity changes, and an encoder architecture diagram.
What it assumes
Assumes basic tokenization and vector embeddings while explaining how positional information supplements them.
What you can do after
Evaluate how transformer representations preserve meaning while distinguishing tokens by sequence position.
How it connects
Connects tokenization, embeddings, semantic embeddings, self-attention, encoder models, and BERT.

Also explained in

Compare how 12 books explain positional embedding →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of LLMs in Production. The section links point to the parts of the book it draws on.