liveBook · Manning

Positional embedding

As explained in Sutskever's List

A positional encoding is a representation added to sequence-element embeddings to convey their positions to a model that otherwise lacks inherent order information.

Why would a Transformer need to be told where words occur? Unlike a recurrent model, it does not step through a sentence in order; unlike a convolutional model, it does not sweep across neighboring words. Without an added position signal, self-attention cannot distinguish “cat fat” from “fat cat.” A positional encoding supplies that signal alongside each word embedding before self-attention begins. section 5.1

The original Transformer, introduced in 2017, used sinusoidal functions at different frequencies. These fixed encodings let the model infer absolute positions and relative distances while attention processes the sequence in parallel. Position did not require bringing back recurrence. section 5.0 section 5.1

Later Transformers changed how the position signal is represented:

  • BERT used learnable positional embeddings instead of fixed sinusoids, allowing training to shape the representations. section 5.1
  • GPT-2 and GPT-3 used learned absolute positional embeddings; T5 used learned relative embeddings. section 5.1
  • LLaMA used rotary positional embeddings to inject relative position into attention itself. section 5.1
Figure 5.1 A simplified schematic of the Transformer architecture. The model consists of an encoder (left) and a decoder (right), each comprising repeated stacks of sublayers, including multihead attention mechanisms, feed-forward neural networks, and postprocessing steps such as residual connections and layer normalization. Positional encodings (depicted as circled crosses) are added to the input embeddings to explicitly represent token order. The diagram emphasizes the cross-attention operation (dashed box labeled “Cross-attention”), in which the decoder’s queries (Q) interact with the encoder’s keys (K) and values (V). During cross-attention, each decoding step computes attention scores to determine the relevance of encoded input representations, producing a context vector that guides token generation. This selective alignment enables the decoder to integrate contextual information from the encoder, improving the accuracy and coherence of the output sequence.
figure

The circled crosses show where positional encodings join input embeddings before the Transformer’s attention layers. section 5.1

The solution did not end the argument about order. Critics saw positional encodings as a workaround for missing recurrence, and word-reordering tests found that self-attention could struggle with positional cues even when embeddings were present. Yet Transformers trained for word-order-sensitive machine translation outperformed recurrent models at learning positional information. The engineering lesson is narrower than either slogan: adding a position signal matters, but performance also depends on the task and training. section 5.1.2

How Sutskever's List covers it

How deep it goes
Explains placement, sinusoidal functions, and later variants, but leaves line-by-line implementation to an annotated Transformer reproduction.
Examples
Contrasts “cat fat” with “fat cat” and uses word-reordering tests to probe sensitivity to order.
What it assumes
Recaps recurrence and convolution as ways to handle sequences before contrasting them with self-attention.
What you can do after
Evaluate/understand why Transformers need position signals and why their presence alone does not guarantee sensitivity to word order.
How it connects
Connects word embeddings and self-attention to recurrence, convolution, machine translation, and absolute versus relative position.

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 Sutskever's List. The section links point to the parts of the book it draws on.