ALiBi adds no positional embedding. It adds a bias to the attention score between query position and key position , with a head-specific slope . For a query at position 4 whose four raw scores are all equal, what attention weights result when and when ? Give the slopes for 8 heads, and explain why ALiBi can help a model run on longer sequences than it was trained on?
Sequence models and transformers, Positional encoding
Level L3 Intermediate. Length Medium. Nature Th+Mat Both.
What's being asked
Whether you can read a relative-position bias as a change to the softmax, and see why it behaves well beyond the training length.
Key idea
ALiBi uses . Since the softmax is shift-invariant, equal raw scores give weights proportional to , so each head has a built-in recency preference that decays geometrically with distance.
Steps
- With equal raw scores the distances from position 4 to keys are , so weights are .
- For : , , , . The sum is , so the weights are . A strong recency bias.
- For : , , , . The sum is , giving . Almost uniform, so this head looks far back.
- Slopes for heads form a geometric sequence , which is . Steep slopes give local heads and shallow slopes give long-range heads.
- Extrapolation. The bias depends only on the distance , and no position index is ever fed into the network. At test time with longer sequences, distances simply grow, and the penalty keeps growing linearly, so far tokens get small weight. Learned or sinusoidal absolute embeddings meet position values never seen in training.
- The slopes are fixed, not learned, and the bias is added only to the scores (not to the values), so there is no extra parameter or memory.
Common mistakes
- Saying the bias is added to the token embeddings. ALiBi acts on the attention scores in every layer.
- Getting the sign wrong. The bias is a penalty, so more distant keys must get lower scores.
- Claiming ALiBi guarantees good long-context quality. It extrapolates in perplexity, but the model may still not use information far away.
How long your answer should be
Half a page; 4–5 minutes.
Last checked on 4 December 2026.
Read this
Previous in Sequence models and transformers: In connectionist temporal classification (CTC), an acoustic model gives, for each of frames, a distribution over the symbols . How are alignments mapped to labels, how many alignments of length 4 collapse to the label "ab", how many to "aa", and what is the probability of "ab" if every frame is uniform over the three symbols?
Next in Sequence models and transformers: A unigram language-model tokeniser has the vocabulary and probabilities h , u , g , s , hu , ug , hug , gs , ugs . Which segmentation of "hugs" does it choose, how is it found efficiently, and how does this differ from BPE?