Position Problem › What We Need from Positional Information

Michael BrenndoerferUpdated June 5, 20257 min read
Language AI HandbookAll chapters
Part 14 of 67Positional Encoding
Chapter 96Position Problem › What We Need from Positional Information
Reading section 4 of 11 · What We Need from Positional Information · 7 minSection 4 of 11 · 7 min

Book contents

Section 4 of 11 · 7 min read

Position Problem › What We Need from Positional InformationOne section · Sections in this chapter4 / 11 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Understanding why position matters helps us identify what properties any positional encoding scheme must have. The ideal solution must satisfy several requirements, and each requirement rules out simple approaches you might first consider.

Unique Position Identification

Each position in a sequence needs a distinct representation. If positions 3 and 7 have identical positional signals, the model cannot distinguish tokens at those positions based on their locations. This requirement seems obvious, but it rules out the simplest possible approaches. Using a constant vector (the same positional signal everywhere) provides no information. Using a random vector assigned at initialization but not varied across positions gives each position a signal, but that signal is arbitrary and meaningless to the model.

The uniqueness requirement means the positional representation must vary systematically with position. The question is how.

Bounded and Stable Values

Whatever numerical representation we use for position, it must have bounded, well-behaved values throughout. If position 1 is encoded as 1, position 1000 as 1000, and position 1 million as 1 million, the scale differences will overwhelm the semantic content of token embeddings. Neural networks are sensitive to the magnitudes of their inputs. Unbounded positional representations would create training instabilities and force the model to learn very different weight scales to handle early versus late positions in a sequence.

The key insight is that the positional representation should live in the same numerical space as the token embeddings it is being combined with. Token embeddings are typically distributed with mean near zero and standard deviation near one, thanks to embedding initialization schemes and layer normalization. Positional representations should match this scale.

Consistency Across Sequence Lengths

The encoding for position 5 should be the same whether it appears in a 10-token sequence or a 10,000-token sequence. If positional representations change based on sequence length, the model must learn different positional patterns for every possible length it might encounter. This would make it impossible to transfer knowledge from short sequences to long ones, and vice versa.

This requirement rules out a common naive approach: normalizing the position by the sequence length. Position pp in a sequence of length nn might be represented as p/np/n, giving values between 0 and 1. This is bounded, which is good. But it violates consistency: position 5 in a 10-token sequence gets value 0.5, while position 5 in a 100-token sequence gets value 0.05. The model learns that "0.5" means "halfway through," but the absolute meaning of position 5 changes with sequence length.

Relative Position Accessibility

Many linguistic relationships depend on relative rather than absolute position. A verb typically appears near its subject and object, regardless of where they fall in the sentence. An adjective typically immediately precedes the noun it modifies. A relative clause immediately follows the noun it modifies. These are all relative positional relationships. The model needs to compute "token A is 3 positions before token B," rather than only "token A is at position 7 and token B is at position 10."

Ideally, the positional encoding should make it easy to determine that position 7 is "2 steps after" position 5, rather than only showing that both are somewhere in the sequence. This is a stronger requirement: each position needs a unique signal, and the relationship between signals needs to encode relative distance in a way the model can exploit.

Generalization Beyond Training

Models trained on sequences of length 512 may encounter sequences of length 1024 at inference time. The positional encoding should degrade gracefully (or not at all) when extrapolating to positions not seen during training. This requirement is especially important for applications where input length is unpredictable, such as processing documents of arbitrary length.

Fixed mathematical functions (like sinusoids) can extrapolate naturally, because the formula applies to any position, including ones never seen during training. Learned embeddings, by contrast, have no entry in their lookup table for positions beyond the training maximum. Handling this gracefully requires interpolation, extrapolation heuristics, or other architectural choices.

Compatibility with Attention

The positional information must integrate with the attention mechanism in a way that allows position to influence attention patterns. If a query cannot distinguish nearby keys from distant keys, positional information is not flowing into the core computation. This requirement means we cannot just append position indices somewhere; the position information must be in a form that the dot-product attention can use.

The standard approach is to combine positional representations with token embeddings before computing QKV representations. This way, when the model computes dot products between queries and keys, those dot products depend on position as well as content.

In[9]:
Code
# Illustrate the problem with naive positional representations

positions_naive = np.arange(1, 513)

# Naive approach 1: Raw position index
naive_index = positions_naive

# Naive approach 2: Normalized position (0 to 1)
naive_normalized = positions_naive / 512

# Naive approach 3: Log-scaled position
naive_log = np.log(positions_naive)
Out[10]:
Visualization
Line plot showing raw position indices growing linearly from 1 to 512.
Raw position indices grow linearly and without bound. At position 512 the value is 512, which is hundreds of times larger than typical token embedding values near zero, causing the positional signal to overwhelm semantic content.
Line plot showing normalized positions from near 0 to 1.
Normalized positions change meaning with sequence length. Position 256 maps to 0.5 in a 512-token sequence but to 0.25 in a 1024-token sequence, so the model cannot generalize positional patterns across different sequence lengths.
Line plot showing log-scaled positions with diminishing growth rate.
Log scaling compresses distant positions, causing poor discrimination between later positions. Positions 400 and 500 differ by only about 0.22 in log scale, while positions 1 and 2 differ by 0.69, creating highly unequal positional resolution.

None of these naive approaches satisfy our requirements. Raw indices are unbounded, growing to hundreds or thousands while token embeddings remain in a range around zero. Normalized positions change meaning with sequence length: position 0.5 is location 256 in a 512-token sequence but location 512 in a 1024-token sequence, making the learned positional patterns non-transferable. Log scaling compresses distant positions so tightly that the model can barely distinguish position 400 from position 500, creating highly unequal positional resolution across the sequence.

The requirements we have identified describe a multi-dimensional representation with bounded values, stable meaning across sequence lengths, and enough variation to distinguish positions. This is the problem that sinusoidal encodings and learned embeddings were designed to solve, and we will explore both in detail in subsequent chapters.