Positional Encodings: Sinusoids, Rotations, and RoPE
A positional encoding is a kernel over offsets: sinusoids are a fixed stationary kernel that rules distance logarithmically, RoPE rotates queries and keys so every learned score sees only the offset, and ALiBi multiplies in an exponential kernel that extrapolates in length because it cannot look far
Overview & Motivation
The attention topic read attention as a kernel smoother: a weighted average over a set of keys. A set has no order, and that topic’s Proposition 3 drew the consequence. At the last word, one layer of attention reads the dog bit the man today exactly as it reads the man bit the dog today. A positional encoding supplies the order. The question this topic asks is what kind of object it supplies.
The answer we develop is that every positional encoding is a kernel over offsets: a rule for how much the distance between two positions should change their score. Then length generalization, the ability to read sequences longer than any seen in training, becomes a question about what that kernel does past the training window. Here is the experiment the topic builds toward. We train single attention heads, with each of five ways of adding position, to answer which marked token came last? in sequences of tokens, and read them on sequences of :
| scheme | accuracy at 32 | at 256 |
|---|---|---|
| no position at all | ||
| sinusoidal code, added | ||
| RoPE (rotations) | ||
| RoPE, positions interpolated | ||
| ALiBi (a linear penalty on distance) |
Each row is taken up below.
- Sinusoids are a stationary kernel. The sinusoidal code turns the hands of clocks. Shifting every position is one rotation, and the inner product of two positions depends only on their offset. As grows it becomes a ruler that is logarithmic in distance.
- Adding a stationary code does not make attention relative. Only a -dimensional family of score matrices sees offsets alone, and trained heads sit as far from it as random matrices. The added code collapses at twice its training length, because absolute positions it never saw enter the score, through this term and through the content–position terms.
- ALiBi is a product kernel. Its weights are the attention topic’s smoother with a content kernel times an exponential kernel in time. One inequality says both why it extrapolates and why it cannot look far.
- RoPE is relative by construction, and up to the learned projections it is the only linear encoding that is. Its score is a trigonometric polynomial in the offset, and past the training window the polynomial does what training never constrained it to do.
Then we take the heads to text. Synthetic company filings name a parent and its subsidiaries and then refer back to “the company”. Asked at every position which company was named most recently, heads trained on -token windows read whole filings. Past the training window, RoPE with interpolated positions reads of the answers, and ALiBi, which held at through the length tournament, reads .
Order, and how a mask leaks it
The attention topic’s Proposition 3 says bidirectional attention is permutation-equivariant, and that one causal layer, which reads only earlier positions, depends on its prefix only through the prefix’s multiset. A multiset has no order, but it has a size.
Proposition 1 (A causal layer counts but does not order).
(i) Suppose a causal attention layer’s scores are all equal, the value at position is a vector (a beginning-of-sequence token’s), and every other value is . Then its output at position is , so is recovered exactly from when .
(ii) In general, given the token at , one causal layer’s output at is a function of the multiset of its prefix. The multiset’s size is the position, and its order is invisible.
Proof.
For (i), equal scores make the weights uniform over the positions , and only the value at position is nonzero. For (ii), the attention topic’s Proposition 3 (ii) gives the dependence on the multiset, given the token at , and the number of its elements is a function of it.
∎So the causal mask itself leaks position, as Haviv and colleagues (2022) observed: a causal stack without any positional encoding can write absolute position into its first layer’s output and use it in the second (Kazemnejad et al. 2023 give a construction). A single causal head cannot. On the task of the overview, where the target is the symbol on the most recent marked token, a head without positions sees a bag of tokens. Every ordering of a bag is equally likely, so the best it can do is guess the most frequent marked symbol. That reader’s accuracy, computed exactly by counting, is at length and at ; the trained heads without positions reach and , matching it within sampling error at every length.
Position as a set of clocks
Let be even and split into coordinate planes . Give plane the frequency , for a base that is unless stated, so the frequencies fall geometrically from to nearly . Write for the rotation of a plane by the angle , , and for the block-diagonal rotation that turns plane by .
Definition 1 (Absolute additive encoding).
An absolute additive encoding adds a vector to the embedding of the token at position : the layer reads . The code is either a learned table, one trained vector per position up to the training length and undefined beyond it, or a fixed function of .
Definition 2 (Sinusoidal code).
The sinusoidal code is
This is Vaswani and colleagues’ (2017) code. They put the sine first in each plane, which is a fixed reflection of every plane and changes no inner product. The attention topic’s circle features are its one-plane case. Picture plane as a clock whose hand points at angle : the first hand turns one radian per position, the last almost not at all.
Proposition 2 (Shift is a rotation).
(i) For all integers and , .
(ii) The map is a homomorphism from into the rotation group : and .
(iii) Every position lies on the same sphere, .
(iv) The code is injective: only if .
Proof.
For (i), the angle-addition formulas give in each plane. For (ii), rotations of one plane compose by adding angles, and ; each block has determinant . For (iii), each plane contributes . For (iv), plane alone has , so forces to be a multiple of , which for integers means , since is irrational.
∎Vaswani and colleagues chose the code because, they wrote, a shifted position is a linear function of the original; (i) is that claim, and the linear function is a rotation that does not depend on . In the language of Linear Systems (its Example 5), with the block-skew generator . Since every is orthogonal, the inner product of two positions cannot depend on where they are.
Theorem 1 (The stationary kernel, and the logarithmic ruler).
(i) For all and , , where
Every Gram matrix is positive semidefinite, and Toeplitz over consecutive or evenly spaced positions, and is the characteristic function of a random frequency uniform on the points .
(ii) Fix and . As ,
where is the cosine integral, and
with Euler’s constant.
Proof.
For (i), angle subtraction gives in each plane. A Gram matrix of vectors is positive semidefinite, since , and over consecutive or evenly spaced positions depends only on , which is the Toeplitz form. The characteristic-function form is the average of over the points.
For (ii), write with a fair sign and uniform on the grid . The grid’s uniform law converges to the uniform law on , so by continuous mapping converges in distribution to , uniform on . Since is bounded and continuous, . Substituting , so , and then ,
For the bound, integration by parts gives , so . The integral form (DLMF 6.2.12–13), with , gives with . Put in the second and in the first, and divide by .
∎Two readings. First, by Herglotz’s theorem (Brockwell and Davis 1991, §4.3), every positive-definite function of an integer offset is the characteristic function of some measure on the circle, so a stationary position code is a choice of spectral measure. The sinusoidal code chooses atoms at geometric frequencies, and Rahimi and Recht’s (2007) random features, which the attention topic set aside for positive ones, would sample them instead. Positive definiteness, stationarity, and the spectral picture are the ones formalML builds for Gaussian processes (Gaussian Processes: positive definiteness is its Definition 2, and the other two come later in that article).
Second, (ii) says the similarity of two positions is a logarithmic ruler: past a few positions it is a straight line in , and each doubling of the distance costs the same of similarity, because geometric frequencies give every octave of distance its own few planes. The notebook computes:
| limit | ||||||
| ruler |
The convergence in is not uniform in : at , is farther from the limit than is. Large offsets need many planes. Note also what the table says against a common claim. Stack the code’s vectors as the rows of a matrix . The Gram matrix of the positions is , not a multiple of the identity, which is what the table shows. The columns are a separate matter, and is not diagonal either: at the largest cosine between two columns exceeds over positions and is still over . The orthogonality of sines and cosines (Fourier Series, its Theorem 1) holds for integer harmonics over a full period; these frequencies are geometric, and a window is not a period.
The kernel is stationary, but attention does not compare positions directly. A head with query map and key map scores position against position by , with and . With , the score is the sum of four terms, content against content, content against position, position against content, and . Is that last term at least a function of the offset?
Theorem 2 (Which score matrices see only offsets).
Let be distinct numbers in . For , the following are equivalent.
(a) depends only on , for all integers and .
(a′) The same holds for all and in one window of consecutive integers.
(b) commutes with .
(c) : block-diagonal, with one rotation-scaling block per plane.
The matrices in (c) form a -dimensional subspace of the -dimensional space of score matrices. On it, with , a trigonometric polynomial in the offset.
Proof.
Write and . By Proposition 2, . So depends only on , which is to say for all and , exactly when for all and .
The vectors , for any consecutive , span . In complex coordinates their entries are , and the matrix over consecutive and the distinct points is a Vandermonde matrix, hence invertible. So the condition holds on a window of positions, or on all of , exactly when , that is, . This proves (a) ⇔ (a′) ⇔ (b).
For (b) ⇔ (c), has the distinct eigenvalues , so a matrix commuting with it preserves each of its two-dimensional real eigenplanes, which are the coordinate planes. is then block-diagonal, and its block commutes with the rotation . Writing out with forces . Conversely, commutes with every rotation of its plane. The formula for the score follows by angle subtraction, since .
∎The theorem says that adding a stationary code to the content does not make attention relative. The position-against-position term is relative only if the learned lands in a -dimensional subspace of a -dimensional space, and the content-against-position terms are not relative at all (Ke, He, and Liu 2021). The relativity defect , with the orthogonal projection onto the subspace (keep each diagonal block’s , zero the rest), measures the miss. For a random Gaussian , has a Beta distribution with mean , so , and at a random matrix has . The three sinusoidal heads of the tournament, after training, have , , and . Training barely moved them: at initialization they were , , and . Within the training window, nothing rewards relativity.
The attention topic’s trained circle denoiser is the opposite case. Its task was rotation-invariant, and it learned , which lies in the commutant of a single plane. Exactness is also fragile in another way: over a window short against the slow planes’ wavelengths, the window’s vectors are nearly dependent. The -dimensional code over positions has numerical rank . Its exact condition number falls from over positions, through over , to over and over . The first two are past what double precision resolves, so the notebook computes them in -digit arithmetic. A window constrains a slow plane only once the window has watched it turn.
Relative position: biases and the ALiBi kernel
Since the score should depend on the offset, several schemes put the offset into the score directly.
Definition 3 (Relative-position schemes).
For a causal head scoring position against , with offset :
- Shaw, Uszkoreit, and Vaswani (2018) add a learned vector to the key, , one vector per offset up to a clip .
- T5 (Raffel et al. 2020) adds a learned scalar , with buckets that are exact for small offsets and logarithmically spaced up to .
- ALiBi (Press, Smith, and Lewis 2022) subtracts a fixed linear penalty, , with slope for head of .
T5’s buckets show the pattern of the section in miniature. With buckets, offsets below get their own bucket and the rest share log-spaced ones, the last of which holds every offset from on (the logarithmic map reaches it at , not at ). Offsets that far back are indistinguishable. Transformer-XL (Dai et al. 2019) puts relative terms into the score in yet another way. ALiBi is the cleanest, because its penalty multiplies the attention topic’s kernel by a second kernel. Our single head uses , ALiBi’s first slope at .
Theorem 3 (ALiBi is a product kernel).
Let one causal ALiBi head with slope have content scores lying in an interval of width . Write for the weight on offset from a fixed query .
(i) : a Nadaraya–Watson smoother whose kernel is the product of a content kernel and an exponential kernel in time. In bidirectional form, is a positive-definite kernel, and so is its product with any positive-definite content kernel.
(ii) At every length, the weight on offsets is at most .
(iii) For every offset , . A key farther back than gets less weight than the query’s own position, whatever its content.
Proof.
Part (i) is the softmax of . The bidirectional kernel is the Matérn kernel with smoothness , positive definite (Gaussian Processes, its Definition 3), and a product of positive-definite kernels is positive definite (that topic’s Proposition 2). The content kernel has to be one for this to apply. With the scores are a Gram matrix and is positive definite, but with the matrix is not even symmetric, and only the time factor is a kernel in this sense. For (iii), , since the two content scores differ by at most . For (ii), sum (iii) over and use : the sum is at most .
∎Parts (ii) and (iii) are one inequality read two ways. Read as (ii), it is a guarantee: no matter how long the sequence, the head’s weight stays within a band of offsets fixed by and , so its behavior at length is its behavior at length . That is why ALiBi extrapolates, and Chi and colleagues (2023) trace its length extrapolation to exactly such a bounded receptive field. Read as (iii), it is a limit: a key past the horizon is outweighed by the query’s own position, so the head cannot retrieve it on weight alone. The bound in (ii) is vacuous inside the horizon. With and it is at , then at and at . Inside the horizon the content decides; past it the position does. In formalML’s terms, this is Nadaraya–Watson in time with bandwidth (Kernel Regression, its Definition 2).
Rotations: RoPE
Theorem 2 says an added code makes the score relative only if is special. Rotary position embedding removes the condition by moving the code from the inputs to the queries and keys, and from addition to rotation.
Definition 4 (Rotary position embedding (RoPE)).
With frequencies , rotate the query at position and the key at position by their positions:
and score . In complex form, each plane’s coordinates are multiplied by .
This is Su and colleagues’ (2024) RoPE. Its frequencies are Definition 2’s, so it is the sinusoidal code, applied by multiplication instead of addition.
Proposition 3 (RoPE is relative by construction, and isometric).
(i) .
(ii) .
(iii) For fixed and , the offset score is the trigonometric polynomial
with amplitudes and phases the angle from the component of in plane to that of .
Proof.
For (i), by Proposition 2 (ii). Part (ii) holds because rotations are orthogonal. For (iii), in plane write and . Then points at angle , and its inner product with is .
∎Part (ii) matters for the kernel reading. The attention topic factored the kernel into a Gaussian in times design weights (its Proposition 1). RoPE leaves every norm alone, so the design weights carry no position: RoPE moves only angles. A rotation applied to both vectors would preserve their inner product, as formalRAG uses for quantization (Optimized Product Quantization, its Theorem 1). RoPE applies different rotations to the two, and what survives is exactly the rotation by the offset.
Is RoPE one clever choice among many? The next theorem says it is the only linear one.
Theorem 4 (RoPE is the general linear relative encoding).
Let , for , with . The following are equivalent.
(a) depends only on , , and , for all , , , and .
(b) for some orthogonal matrix .
(c) There are an orthogonal , angles , and integers with
Proof.
(a) ⇒ (b): The bilinear form determines the matrix , so (a) says for some function . Taking gives , so every is orthogonal. Taking gives . Then , so , and by induction for all , with .
(b) ⇒ (c): An orthogonal matrix is normal, and its real normal form (Horn and Johnson 2013, §2.5) is with orthogonal and . Raise it to the -th power.
(c) ⇒ (a): , a function of .
∎The orthogonal is absorbed by the learned maps and , so up to the projections every linear encoding that makes scores relative is RoPE with some frequencies. It may also leave planes unrotated, as partial rotary embeddings do, or flip a coordinate’s sign at every step, since can have odd size. RoPE’s only free choice is the spectrum, and it takes Definition 2’s. Su and colleagues derive the two-dimensional case under further assumptions on the encoding; (b) needs none.
Su and colleagues also argue that RoPE gives a “long-term decay” of scores with distance. The argument is a bound, and it is worth seeing exactly what it bounds.
Proposition 4 (What long-term decay means).
In complex form, let for planes , let , and let . The offset score is .
(i) .
(ii) If and each plane has , then .
(iii) If and are independent, and the planes of are independent and each rotation-invariant in distribution, then the distribution of does not depend on .
Proof.
For (i), sum by parts: , since and , and bound each term. For (ii), in each plane, so the expectation is . For (iii), independence lets each plane turn on its own, so has the same distribution as , and it is independent of .
∎The bound in (i) depends on through the envelope , which falls with distance on average. At its mean over each octave of falls from at to over offsets to , or from to per plane, though not monotonically within an octave. That is a measurement, not a theorem. The independence in (iii) is needed: take , with uniform, and . Each plane of is rotation-invariant, but the score has variance . Parts (ii) and (iii) say what the envelope is about. A key that matches its query decays as Theorem 1’s logarithmic ruler, and a key unrelated to its query does not decay at all. “Long-term decay” is a property of envelopes and matched pairs, and a trained head decays only where it has learned to.
Past the training window
Now train. The task needs both content and order. Each sequence holds tokens, each carrying one of symbols and, with probability , a mark; a query token ends the sequence, and the target is the symbol on the most recent marked token. One causal head of width reads it at the query, with each of five schemes: no position, the added sinusoidal code, an added learned table, RoPE, and ALiBi. Each is trained from scratch in NumPy with hand-written gradients for Adam steps at length , three seeds per scheme, and tested on fresh sequences at each length. Accuracy, as the mean of three seeds:
| scheme | 32 | 64 | 128 | 256 |
|---|---|---|---|---|
| no position | ||||
| sinusoidal, added | ||||
| learned table, added | — | — | — | |
| RoPE | ||||
| ALiBi |
Every scheme but the first reads the task within the window. Past it, the learned table has nothing to say, and the added sinusoidal code collapses at twice the length: its trained score depends on absolute position, and the absolute positions are new. Theorem 2 accounts for one part of that dependence, not all of it. Replace only the position-against-position term with its projection onto the commutant, and the head still reads , , and at , , and , because the position-against-content term separates keys as strongly: at length their spreads across keys are within of each other in every seed. Training always put the query at position . Shift a long sequence so that the query sits there again, keeping every offset, and the head reads at , but only at , where older keys land on positions training never saw. ALiBi holds, as Theorem 3 (ii) predicts. RoPE degrades steadily, from to , and at its three seeds range from about to .
Why does a relative encoding fail to generalize in length? Because “relative” constrains the score to be a function of the offset, not to be a sensible one. Training sees offsets to only. By Proposition 3 (iii), the head’s score for a marked token at offset is a trigonometric polynomial, and training pins it down on alone. In seed the score falls from at to a first trough of at , as the task rewards. Past the window it dives to at , and only then climbs, to at , higher than the score of any recent marked token sixteen or more back. All three seeds behave alike: first troughs at to , deepest points of , , and at to , peaks at to , and the largest amplitude in plane . The census in Theorem 5 explains the shape. Only planes and turn a whole circle in positions, so the head carries its sense of recency in planes and , whose wavelengths, and , are long enough that half a turn spans the window. A causal head reads the score at , so where a plane bottoms depends on its trained phase, not on its half wavelength of alone. Plane bottoms near in seed , and plane , still falling, carries the sum to the first trough. One turn later plane bottoms again, near , which is the dive. After three turns of plane ( positions) and one of plane (), the two come back toward phase, and both crest near .
The fixes that practitioners use to extend RoPE’s context change the angles the head sees.
Definition 5 (Context-extension maps).
To read a head trained at length on length :
- Position interpolation (PI; Chen et al. 2023) maps positions .
- NTK-aware scaling (bloc97 2023) changes the base, .
- YaRN (Peng et al. 2024) gives plane the frequency , where rises linearly from to as , the number of turns the plane made in training, goes from to . It also multiplies the scores by .
Theorem 5 (Wavelength census and rescalings).
Let be the wavelength of plane .
(i) Over the training offsets , plane turns through a whole circle exactly when . Any other plane sees only the arc , and past it produces angles the head never saw.
(ii) PI maps test offsets into , within one position of the trained range, and shrinks the angle between neighbors -fold in every plane.
(iii) NTK-aware scaling gives plane the frequency : plane is unchanged, and the slowest plane is divided by exactly .
(iv) For , which with Proposition 4’s is the offset score, and integers , the linear interpolation of between them satisfies
and .
Proof.
Part (i): the angles for sweep the arc , which is a whole circle exactly when its length reaches . Part (ii): the largest test offset maps to , and neighbors differ by in plane . Part (iii): , which is times at and at . Part (iv): the interpolation remainder is for some between and , and . The sum is geometric.
∎At and the wavelengths are , , , , , , , and , so two planes of eight complete a turn. PI keeps every angle in range at a cost in resolution. NTK-aware scaling keeps the fast planes’ resolution and interpolates the slow ones. At its per-plane factors run , , , , , , , and . YaRN, at this small , is nearly PI: its factors are , , then in every other plane.
Part (iv) is the reason interpolation is safer than extrapolation. Between trained positions the score is pinned by its curvature, and past them nothing pins it, so can reach . Chen and colleagues (2023, their Theorem 2.1) state this bound with the constant in place of . Their proof bounds by using for , which is the reverse of what convexity gives, so the stated constant is too small. It is times too small at and times at . The stated bound then fails: for on at , the interpolation error at is , while the stated bound is and the corrected one is . With the corrected constant, their conclusion, that interpolated scores are far more stable than extrapolated ones, stands.
Re-reading the trained RoPE heads with each map, with no further training:
| RoPE head read with | 64 | 128 | 256 |
|---|---|---|---|
| nothing | |||
| PI | |||
| NTK-aware | |||
| YaRN |
Each map rescues the head, and on this task NTK-aware scaling rescues it best at , where its ties ALiBi’s within sampling error on the same test sequences: it stretches the slow planes just enough to push the rebound past the longest sequence while keeping the fast planes sharp. The next section’s task ranks them differently.
Kernels over offsets, side by side
The laboratory has two figures. Figure A is the geometry. Drag two positions and watch the clocks of the sinusoidal code turn, then lock the offset and see the kernel stay put. The ruler view compares the kernel at three dimensions with its limit, and the last view shows a trained sinusoidal head’s score drifting with absolute position where a relative one would be flat. Figure B is the training. It shows the tournament with every scheme’s learned score against offset, the wavelength census with each rescaling’s factor per plane, and one held-out filing from the case study below, with every reader’s answer at every position.
Plane j turns at rate b^(−2j/d): the first hand at one radian per step, the last almost not at all. Lock the offset and move either slider: every hand turns, each by its own rate, and the readout does not move. The inner product of two positions depends only on how far apart they are (Proposition 2 and Theorem 1).
Training only sees offsets 0 to 31. The RoPE head's score is a trigonometric polynomial in r (Proposition 3): it falls across the window, as the task rewards, dives past it, and then the planes that never completed a turn bring it back up, until a cue 181 positions back outscores a recent one. ALiBi's score is a straight line down. The absolute codes' curves are drawn for a query at the end of a 256-token sequence; the learned table has nothing past 31.
Finance case study: which company was named last?
Where this goes next
- The transformer block. Proposition 1’s counter is one way a causal stack writes position into its residual stream, and a block runs many heads, which can carry many slopes and many frequencies at once. The transformer-block topic assembles them.
- Contextual embeddings. BERT adds a learned table (Definition 1), which is undefined past its length. The contextual-embeddings topic trains with it.
- Long contexts. formalRAG’s long-context topic models a passage buried in a long context as softly erased (its Proposition 3). Theorem 3’s horizon is one mechanism for such burial, a recency kernel under which far tokens weigh less than near ones, though not the only one, and this page does not model that topic’s U-curve.
- Graphs and grids. On a cycle the sinusoids are the eigenvectors of the shift, and a stationary kernel is diagonalized by the discrete Fourier basis, as for the abelian Cayley graphs of formalML’s expander-graphs topic (its Proposition 2).
Honest caveats
Implementation
The companion notebook (notebookPath) imports positional_encodings_geometry.py, which owns every number on this page. That module imports the attention topic’s module for its attention function and its harness conventions, the neural-language-models topic’s gradient checker and Adam constants, and the shared finance corpus. It trains single-head models from scratch in NumPy, for the tournament and for the filings, and runs a harness of assertion-based tests in about half a minute on a laptop CPU. The tests cover:
- Proposition 1 exactly, and the heads without positions against the best multiset reader, computed exactly.
- Proposition 2 and Theorem 1 on random instances, the cosine-integral limit at , and the logarithmic ruler.
- Theorem 2: the window’s null space at random frequencies, a random matrix’s defect, the trained heads’ defects before and after training, and the condition numbers in -digit arithmetic; what projecting one term and moving the query do to the added code.
- T5’s buckets, and Theorem 3 on random instances up to length .
- Proposition 3 against the attention topic’s attention function; Theorem 4 through scipy’s real Schur form; Proposition 4 by Monte Carlo, including the counterexample that makes (iii) need independent planes.
- Theorem 5’s census and rescalings, the interpolation bound on random instances, and the counterexample to the stated constant.
- Every hand-written gradient against central differences; the tournament, the RoPE rebound through its dive, and the filings, including the one-pass filing reader against the plain forward pass at every position and the case study’s one filing.
The laboratory reads its data from a JSON file that one of those tests requires to equal the module’s viz_payload() exactly, so the figure cannot drift from the code.
References & Further Reading
- paper Attention Is All You Need — Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Łukasz Kaiser, and Illia Polosukhin (2017) NeurIPS 30. The sinusoidal code, Definition 2, and its claim that a shifted position is a linear function of the original, Proposition 2
- paper Self-Attention with Relative Position Representations — Peter Shaw, Jakob Uszkoreit, and Ashish Vaswani (2018) NAACL-HLT 2018. Learned vectors for clipped relative offsets, Definition 3
- paper Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer — Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, and Peter J. Liu (2020) Journal of Machine Learning Research 21. T5's log-spaced relative-position buckets, Definition 3
- paper Transformer-XL: Attentive Language Models beyond a Fixed-Length Context — Zihang Dai, Zhilin Yang, Yiming Yang, Jaime Carbonell, Quoc V. Le, and Ruslan Salakhutdinov (2019) ACL 2019. Relative position terms inside the attention score, beside Definition 3
- paper Rethinking Positional Encoding in Language Pre-training — Guolin Ke, Di He, and Tie-Yan Liu (2021) ICLR 2021. The content–position cross terms of an added code, Theorem 2's reading
- paper RoFormer: Enhanced Transformer with Rotary Position Embedding — Jianlin Su, Murtadha Ahmed, Yu Lu, Shengfeng Pan, Wen Bo, and Yunfeng Liu (2024) Neurocomputing 568. Rotary position embedding, Definition 4, and its long-term-decay bound, Proposition 4 (i)
- paper Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation — Ofir Press, Noah A. Smith, and Mike Lewis (2022) ICLR 2022. ALiBi, Definition 3 and Theorem 3
- paper Dissecting Transformer Length Extrapolation via the Lens of Receptive Field Analysis — Ta-Chung Chi, Ting-Han Fan, Alexander I. Rudnicky, and Peter J. Ramadge (2023) ACL 2023. ALiBi's extrapolation traced to a bounded receptive field, Theorem 3's reading
- paper Transformer Language Models without Positional Encodings Still Learn Positional Information — Adi Haviv, Ori Ram, Ofir Press, Peter Izsak, and Omer Levy (2022) Findings of EMNLP 2022. The causal mask leaks position, Proposition 1
- paper The Impact of Positional Encoding on Length Generalization in Transformers — Amirhossein Kazemnejad, Inkit Padhi, Karthikeyan Natesan Ramamurthy, Payel Das, and Siva Reddy (2023) NeurIPS 36. A causal stack without positions can recover absolute position, Proposition 1
- paper Extending Context Window of Large Language Models via Positional Interpolation — Shouyuan Chen, Sherman Wong, Liangjian Chen, and Yuandong Tian (2023) Position interpolation, Definition 5, and the interpolation bound of their Theorem 2.1, corrected in Theorem 5 (iv)
- blog NTK-Aware Scaled RoPE Allows LLaMA Models to Have Extended (8k+) Context Size without Any Fine-Tuning and Minimal Perplexity Degradation — bloc97 (2023) Reddit, r/LocalLLaMA. The NTK-aware change of base, Definition 5
- paper YaRN: Efficient Context Window Extension of Large Language Models — Bowen Peng, Jeffrey Quesnelle, Honglu Fan, and Enrico Shippole (2024) ICLR 2024. Per-plane interpolation by wavelength and a logit scale, Definition 5
- book Time Series: Theory and Methods — Peter J. Brockwell and Richard A. Davis (1991) 2nd ed., Springer. Herglotz's theorem (§4.3), the converse in Theorem 1 (i)
- book Matrix Analysis — Roger A. Horn and Charles R. Johnson (2013) 2nd ed., Cambridge University Press. The real normal form of an orthogonal matrix (§2.5), Theorem 4
- documentation NIST Digital Library of Mathematical Functions, §6 — F. W. J. Olver et al., eds. The cosine integral (6.2.11) and its integral form (6.2.12–13), Theorem 1 (ii)
- paper Random Features for Large-Scale Kernel Machines — Ali Rahimi and Benjamin Recht (2007) NeurIPS 20. A stationary kernel as an average of sinusoids at random frequencies, the reading of Theorem 1 (i)