Chapter 3

Position and Sequence Order

Explain why content-only attention does not independently represent token order. Compare learned absolute positions, sinusoidal encodings, relative ideas, RoPE, and ALiBi through small calculations and explicit limitations.

Self-attention compares token representations and combines values. The same projection matrices are used at every position. If an unmasked input is reordered, content-only attention follows that reordering: its output rows are reordered in the same way. The operation has no separate record of which row was first, second, or third.

Decoder attention already contains one position-dependent object: the causal mask. A query at index 0 may read one position, while a query at index 5 may read six. The mask therefore breaks the full reordering symmetry and can supply some implicit position information. It does not provide the same mechanism as an explicit position method.

This distinction matters. It is too broad to say that every Transformer without position embeddings treats its input as an unordered bag. It is also too broad to infer that explicit position methods are unnecessary because some causal models work without them.

This chapter compares four ways to make order or distance affect a Transformer:

  • learned absolute vectors added to token representations;
  • fixed sinusoidal vectors added at each position;
  • relative information inserted into pairwise attention interactions;
  • RoPE rotations or ALiBi biases applied to queries, keys, or scores.

The location of the change is part of the method. Adding a vector to the input, rotating query-key coordinate pairs, and biasing a score before softmax are not interchangeable operations.

After this chapter

  • Demonstrate the permutation problem in content-only self-attention.
  • Compute small absolute, sinusoidal, and rotary position examples.
  • Compare position methods and state their context-length limits carefully.

Lessons

  1. 01
    What Content-Only Attention Preserves Under Reordering

    Distinguish invariance from equivariance, derive the unmasked reordering property, and qualify it for causal attention and NoPE language models.

    1 exercise
  2. 02
    Learned Absolute Position Vectors

    Add learned absolute position vectors to token embeddings and audit table shapes, parameters, padding, ranges, and interventions.

    1 exercise
  3. 03
    Sinusoidal Position Encodings

    Calculate sinusoidal position encodings, inspect their frequencies and rotation property, and state their length boundary carefully.

    1 exercise
  4. 04
    Relative Position Changes Pair Interactions

    Introduce signed relative offsets through Shaw-style attention scores and values, finite relation tables, and clipping conventions.

    1 exercise
  5. 05
    RoPE Rotates Query and Key Pairs

    Apply rotary position embedding to query-key coordinate pairs and audit rotation geometry and implementation conventions.

    1 exercise
  6. 06
    RoPE Dot Products Depend on Relative Offset

    Derive RoPE's relative-dot-product identity, test shift behavior, and define cached-position and length-generalization boundaries.

    1 exercise
  7. 07
    ALiBi Adds Distance Bias to Scores

    Calculate ALiBi score penalties and head slopes, separate content from distance bias, and bound extrapolation claims.

    1 exercise
  8. 08
    Compare and Audit Position Methods

    Compare absolute, sinusoidal, relative, RoPE, and ALiBi mechanisms and perform a position-aware implementation audit.

    1 exercise

Review and practice

  1. Review

    Review Transformer position mechanisms, equations, distinctions, implementation conventions, and debugging checks.

  2. Exercises

    Solve position-method conceptual, numerical, geometric, score-bias, and debugging exercises.

Chapter progress