Manuscript Offprint
arXiv:2609.07314Content-Based Addressing for Long Context
Abstract
Rotary position embedding (RoPE) uses each token's integer position to determine the rotation applied inside attention. This works well for local token order, but increasing context length creates a positional train-test mismatch: RoPE produces relative rotations at offsets not seen during training. Methods that rescale, interpolate, randomize, or bias positions specify how attention handles those offsets, but still derive positional information from a growing token counter. We instead divide a token stream into units, retain ordinary RoPE positions within each unit, and assign every completed unit an address computed from its content. Adding units then applies the same learned map to new content rather than extending a positional range or an identifier table. We prove that this construction preserves local RoPE exactly, leaves the attention comparison between two fixed tokens unchanged when other units are inserted or reordered, and does not create new relative rotations merely because more units are added. In a character-level Tiny Shakespeare diagnostic, a model trained on 256-character contexts has validation perplexity 4.04 at 256 characters and 3.82 at 4096, while continuous RoPE changes from 4.71 to 12.09. A second diagnostic shows that content-based addressing can retrieve and use information from multiple serialized facts. These are controlled shallow experiments, not scale benchmarks, but they support a direct prescription: use position to address locally and content to address across units.
Keywords: long context, content-based addressing, positional encoding, rotary position embedding, distribution shift, attention
1 Introduction
Long-context Transformers usually assign every token one global position. At evaluation lengths beyond those used in training, this creates a positional train-test mismatch. RoPE turns a position difference into a relative rotation (Su et al., 2021). Attention with Linear Biases (ALiBi) downweights tokens according to distance (Press et al., 2022). Position interpolation and YaRN rescale RoPE coordinates or frequencies (Chen et al., 2023; Peng et al., 2023). Randomized positions expose training to a broader offset distribution (Ruoss et al., 2023). These methods can improve behavior beyond the training length, but they still derive each token's rotation from its location in one serialized sequence.
We separate two jobs that global position currently performs. Within a local text unit, position is the correct address: characters and tokens have an order, and nearby offsets recur across examples. Across completed units, the unit's integer position in the serialized sequence need not determine its attention rotation. Using that position makes the rotation between two fixed units depend on how many unrelated tokens were serialized between them. It also creates new relative rotations solely because more units were placed in context.
We propose content-based addressing. Each token has a bounded position within a unit, such as a line, sentence, paragraph, chunk, or record. Each completed unit receives an address , an
Preprint.
orthogonal matrix computed by a shared neural map from its content. Attention combines the local position and unit address in the same query/key rotation used by RoPE. The resulting token address is : captures local order within the unit, and is the content-based address of unit . There is no global distance penalty or global unit counter. The causal mask still determines which units are available, while the attention score determines which available content is relevant.
The paper makes three contributions. First, it gives a small modification of rotary attention that computes unit addresses from content and can be added to an existing RoPE model. Second, Theorem 1 proves that adding units does not create new relative rotations solely because the context is longer. Third, two controlled diagnostics test complementary properties: stable language-model behavior as more text units are added, and retrieval from content-addressed units when the prediction depends on one of several serialized facts.
Content-based addressing prevents context growth from creating relative rotations unseen during training. It does not reduce attention cost or softmax competition, and the shared content map must still generalize to new unit contents.
For a completed unit, we first form a content descriptor
This descriptor is sensitive to token order because each embedding is rotated according to its local position before pooling. For example, when “man” and “dog” have different embeddings, swapping them changes the descriptor because each embedding receives a different local-position rotation. The learned map can therefore assign the two sentences different unit addresses. A shared map produces one angle per rotary block,
where LN is LayerNorm and is a two-dimensional rotation. The address of token is therefore
Because the implementation uses rotations in the same fixed two-dimensional blocks, the two factors commute and can be implemented by adding their angle vectors.
Queries and keys are rotated exactly as in RoPE:
Their score contains the relative operator
During causal generation, only completed units receive content addresses. The current incomplete unit uses because its complete content descriptor is not yet available. Let denote the space of content descriptors .
Theorem 1 (Context-size invariance of content-based addressing). Let every unit have local positions in , let be any shared map, set and , and define . Then:
- Within one unit, the relative operator is ordinary local RoPE:
Table 1: Validation perplexity after training on 256-character Tiny Shakespeare chunks. The diagnostic is not a conventional comparison of length-extrapolation methods. It tests whether text units can be added while their local positions remain bounded.
| Addressing scheme | Evaluation context | ||||
|---|---|---|---|---|---|
| 256 | 512 | 1024 | 2048 | 4096 | |
| Continuous RoPE | 4.71 | 5.78 | 7.56 | 9.62 | 12.09 |
| ALiBi | 4.96 | 4.94 | 4.96 | 4.93 | 4.93 |
| Reset-only RoPE | 5.18 | 5.63 | 7.77 | 10.51 | 12.70 |
| Random line address | 4.89 | 4.88 | 4.93 | 4.94 | 4.98 |
| Content-based address | 4.04 | 3.85 | 3.78 | 3.75 | 3.82 |
-
Inserting, deleting, or reordering other units does not change the relative operator between two fixed tokens.
-
For any number of units, every relative operator belongs to the fixed family
which does not depend on the number or serialized locations of the units. By contrast, global RoPE on a serialized context of length produces the family , which expands with .
Proof. Substitution in Equation (5) gives . When , the content factors cancel, giving . The expression contains only the two tokens, so other units and their serialized locations cannot affect it. All possible values lie in the displayed family, whose definition contains and , but not the number of units. The global-RoPE statement follows because serialized position differences range from to .
The theorem does not claim that the map will generalize to arbitrary content absent from training. It states a different guarantee: increasing the number of units does not itself create a new coordinate range. The shared map also has a parameter count independent of the number of units, unlike a learned identifier table.
3 Controlled Diagnostics
The diagnostics ask whether the construction can be implemented and used inside standard Transformer attention. They are single-run, shallow experiments, not comparisons among tuned long-context systems.
Plain-text context growth. We train five character-level causal Transformers on Tiny Shakespeare using 256-character chunks and evaluate the same trained models with windows from 256 to 4096 characters. All models have four layers, four heads, and embedding dimension 128. Continuous RoPE uses one global position counter. ALiBi replaces rotary position information with a linear distance bias in each attention head. Reset-only RoPE resets the counter after each newline, giving characters at the same local position in different lines identical addresses. Random line address assigns each completed line one independently sampled angle that remains fixed for that line. The content-addressed model instead computes each completed line's angle using Equations (1) and (2).
Table 1 shows how perplexity changes as lines are added. Resetting local position alone does not prevent perplexity from increasing. ALiBi and random line addresses produce approximately constant curves. Content-based addresses also produce an approximately constant curve and have lower perplexity in this run. A flat curve does not by itself show how much distant information the model uses.
Retrieval from serialized facts. A second diagnostic tests retrieval from an otherwise unchanged serialized input. A three-layer character model reads facts serialized with role markers and entity strings, then generates a sentence stating the target fact. Training examples contain one fact, while
Table 2: Test hit@5 and perplexity (PPL) on target entity-name characters. Same-entities distractors change the relation. Same-relation distractors change the entities.
| Prefix | Task | hit@5 | PPL | ||||||
|---|---|---|---|---|---|---|---|---|---|
| ALiBi | ALiBi | RoPE | ALiBi | ALiBi | Content | ||||
| RoPE | (.004) | (.25) | RoPE | (.004) | (.25) | ||||
| Single fact | chain2 | .359 | .008 | .005 | .925 | 6.22 | 29.97 | 49.51 | 1.58 |
| Single fact | chain3 | .126 | .000 | .000 | .912 | 8.64 | 31.53 | 52.06 | 1.66 |
| Same entities | chain2 | .411 | .000 | .005 | .872 | 6.23 | 2507.34 | 48.25 | 2.35 |
| Same entities | chain3 | .030 | .000 | .000 | .525 | 29.83 | 1635.72 | 51.56 | 3.35 |
| Same relation | chain2 | .109 | .000 | .005 | .122 | 20.49 | 3014.05 | 48.22 | 41.08 |
| Same relation | chain3 | .000 | .000 | .000 | .028 | 101.94 | 2158.83 | 51.58 | 56.09 |
evaluation uses either the true fact alone or the true fact plus four distractors. The chain2 facts contain two entities, and the chain3 facts contain three. Hit@5 requires every generated entity-name character to be among the model's five highest-probability predictions. The baselines use continuous RoPE or replace it with ALiBi using slope 0.004 or 0.25. The content-addressed model resets local position at each fact boundary and computes a content address for every completed fact using the same pooling and projection as above. All four models receive the same serialized tokens in the same order. They differ only in how position or content changes the attention scores.
The content-addressed model has higher hit@5 in all six test rows, but the same-relation setting remains largely unsolved and its chain2 perplexity is worse. Neither ALiBi slope learns even the single-fact training task. At distance 100, the attention bias is −0.4 with slope 0.004 and −25 with slope 0.25. The weak slope leaves distant facts accessible but does not help the model select the correct fact, while the strong slope suppresses the distant fact prefix. Thus, a flat context-growth curve does not establish retrieval, and we report ALiBi as a control rather than a tuned retrieval comparison. The multi-fact conditions require the model to retrieve the relevant fact from the serialized prefix and use it to generate the entity name. They show that content-based addresses can support retrieval from the same serialized input without changing the Transformer architecture.
4 Related Work and Discussion
Contextual Position Encoding (CoPE) makes position increments depend on context, allowing the model to count selected tokens or higher-level units (Golovneva et al., 2024). PaTH Attention accumulates content-dependent Householder transformations along the token sequence (Yang et al., 2025). Both retain an address obtained by accumulating changes through intervening tokens. Our construction instead gives every completed unit a direct content-based address, so adding unrelated intervening units does not change the attention comparison between two fixed tokens.
The pooling and projection in Equations (1) and (2) add to existing RoPE without changing attention heads, Transformer blocks, or the key/value cache format. Appendices A and B give implementation details and report measured training overhead from 10.3% at 0.8M parameters to 2.0% at 680M parameters.
A unit can be a completed sentence, paragraph, chapter, document, or book, with computed from its content. Our experiments use lines and serialized facts. The causal mask preserves which units precede the query and Equation (1) preserves internal token order, but does not encode ordinal distance between units. Attention remains finite, the shared map must generalize to new content, and the model designer must choose unit boundaries. In the same-relation evaluation, different entity content can give facts different addresses, but one-fact training never teaches the model to distinguish several facts that share one relation. The next tests are multi-fact training and fine-tuning this address computation in an open-weight RoPE model.
5 Conclusion
Long context need not use one growing positional range. Content-based addressing preserves local RoPE and gives completed units content-based addresses, so adding units creates no new relative rotations. Our diagnostics implement this construction in standard Transformer attention.
References
Chen, S., Wong, S., Chen, L., and Tian, Y. (2023). Extending context window of large language models via positional interpolation. arXiv preprint arXiv:2306.15595.
Golovneva, O., Wang, T., Weston, J., and Sukhbaatar, S. (2024). Contextual position encoding: Learning to count what's important. arXiv preprint arXiv:2405.18719.
Peng, B., Quesnelle, J., Fan, H., and Shippole, E. (2023). YaRN: Efficient context window extension of large language models. arXiv preprint arXiv:2309.00071.
Press, O., Smith, N. A., and Lewis, M. (2022). Train short, test long: Attention with linear biases enables input length extrapolation. In International Conference on Learning Representations.
Ruoss, A., Delétang, G., Genewein, T., Grau-Moya, J., Csordás, R., Bennani, M., Legg, S., and Veness, J. (2023). Randomized positional encodings boost length generalization of transformers. In Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 2: Short Papers), pages 1889–1903, Toronto, Canada. Association for Computational Linguistics.
Su, J., Lu, Y., Pan, S., Murtadha, A., Wen, B., and Liu, Y. (2021). Roformer: Enhanced transformer with rotary position embedding. arXiv preprint arXiv:2104.09864.
Yang, S., Shen, Y., Wen, K., Tan, S., Mishra, M., Ren, L., Panda, R., and Kim, Y. (2025). PaTH attention: Position encoding via accumulating householder transformations. In Advances in Neural Information Processing Systems.
A Experimental Details
Implementation. Zero-initializing the weights and bias of the final angle projection gives initially, preserving the original model before fine-tuning. When a unit completes, its cached keys, initially rotated by only, are rotated once by and then reused without changing the cache format.
A.1 Tiny Shakespeare
All models are character-level causal Transformers with a 65-token vocabulary, four layers, four attention heads, embedding dimension 128, pre-norm residual blocks, Gaussian error linear unit (GELU) activations, and scaled dot-product attention. Parameter counts range from approximately 810K to 819K. Training uses one million characters with a 90/10 train/validation split, 256-character chunks, 5,000 iterations, batch size 64, AdamW with learning rate , a cosine learning-rate schedule, weight decay 0.1, and gradient clipping at 1.0. Validation perplexity is measured with windows of 256, 512, 1024, 2048, and 4096 characters.
Newlines determine unit boundaries. The ALiBi condition uses slopes , and for its four attention heads. For query position and key position , head adds to the attention score before softmax. The random-line condition samples one angle vector per completed line, keeps it fixed for that line, and draws its entries independently from . The content-addressed condition rotates token embeddings by within-line RoPE, uses a vectorized scatter-add to sum them by line, divides each sum by the line length, and applies LayerNorm followed by a linear map to angles. All operations are vectorized. Because its complete content descriptor is not yet available, the current incomplete line uses , implemented as a zero content angle.
A.2 Retrieval from Serialized Facts
Data and prediction task. The data contain five domains: family, work, military, school, and church. Each domain has six ordered roles. For example, the family roles run from great-grandson through son and father to great-grandfather. Each domain receives a random permutation of 3,000 lowercase training names of length 2–8. Consecutive pairs form chain2 facts, and consecutive triples form chain3 facts. A chain2 example gives one entity and requires the model to generate the other. A chain3 example gives one entity and requires it to generate two. The data contain 25 chain2 relations, 20 chain3 relations, 134,935 facts, and 6.1M sentences. Each fact can be stated with twelve text templates.
Each training example contains one role-marked serialized fact followed by one randomly chosen text rendering. For example, a two-entity prefix and sentence can have the form <son> adam <father> brian | if adam is the son, the father is brian. The entity order in the fact prefix is shuffled, so the model must use the role markers rather than prefix order. During evaluation, the text template is supplied character by character, and only the entity-name characters are scored. Hit@5 requires every scored character to be among the model's five highest-probability predictions. Perplexity is computed over those same characters. Rows labeled train use names seen during training, while rows labeled test use 100 disjoint names.
Evaluation conditions. The single-fact condition supplies only the correct fact. The same-entities condition adds four facts containing the same entity names under different relations, so the model must select the relation requested by the sentence. The same-relation condition instead adds four facts with the same relation and different entities, so the model must use the given entity to select the correct fact. The four distractors are sampled uniformly from the facts that satisfy each condition. Training contains only one fact per example. It therefore never requires the model to choose among several facts with the same relation. Content-based addressing gives those facts different addresses, but learning to use those addresses for this choice requires multi-fact training.
Models and training. All four models are three-layer, single-head causal Transformers with embedding dimension 60, softmax attention, batch size 32, learning rate , and 100K training iterations. Continuous RoPE uses one position counter across the fact prefix and sentence. The content-addressed model sees the same serialized tokens, resets local position at each fact and text boundary, and assigns every completed fact a content-based address. The two ALiBi models replace RoPE with slopes and . Because this diagnostic uses one attention head, each ALiBi model uses one slope rather than the set of slopes distributed across heads in a multi-head model. The two runs use the weakest and strongest slopes from the four-head Tiny Shakespeare condition.
Table 3 gives the complete train and test results. The content-addressed model leads on hit@5 in every test row. The same-relation rows remain difficult, as expected from the difference between one-fact training and multi-fact evaluation described above. The ALiBi models do not learn the single-fact training task: their chain2 training hit@5 scores are .022 and .016, and both score .000 on chain3.
Table 3: Complete results for retrieval from serialized facts. Higher hit@5 and lower perplexity are better. The best value in each metric and row is bold.
| Prefix | Fact | Set | hit@5 | PPL | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| RoPE | ALiBi (.004) | ALiBi (.25) | Content | RoPE | ALiBi (.004) | ALiBi (.25) | Content | |||
| Single fact | chain2 | train | .907 | .022 | .016 | .970 | 2.28 | 26.75 | 14.91 | 1.42 |
| Single fact | chain2 | test | .359 | .008 | .005 | .925 | 6.22 | 29.97 | 49.51 | 1.58 |
| Single fact | chain3 | train | .743 | .000 | .000 | .994 | 2.75 | 28.09 | 13.49 | 1.50 |
| Single fact | chain3 | test | .126 | .000 | .000 | .912 | 8.64 | 31.53 | 52.06 | 1.66 |
| Same entities | chain2 | train | .853 | .004 | .017 | .973 | 2.58 | 2497.93 | 14.53 | 1.91 |
| Same entities | chain2 | test | .411 | .000 | .005 | .872 | 6.23 | 2507.34 | 48.25 | 2.35 |
| Same entities | chain3 | train | .126 | .000 | .000 | .714 | 15.37 | 1846.91 | 13.25 | 2.50 |
| Same entities | chain3 | test | .030 | .000 | .000 | .525 | 29.83 | 1635.72 | 51.56 | 3.35 |
| Same relation | chain2 | train | .368 | .005 | .017 | .163 | 6.72 | 2743.78 | 14.53 | 18.53 |
| Same relation | chain2 | test | .109 | .000 | .005 | .122 | 20.49 | 3014.05 | 48.22 | 41.08 |
| Same relation | chain3 | train | .005 | .000 | .000 | .032 | 51.44 | 2056.06 | 13.25 | 28.03 |
| Same relation | chain3 | test | .000 | .000 | .000 | .028 | 101.94 | 2158.83 | 51.58 | 56.09 |
B Timing Benchmark
We measured one complete training step for the continuous-RoPE baseline and content-addressed model on an NVIDIA Tesla T4 using PyTorch 2.6.0, CUDA 12.4, and Python 3.12. Context length was fixed at 1024. Each result averages ten timed steps after one warmup step, with CUDA synchronization around the timed region. Batch size was reduced for larger models to fit device memory.
Table 4: Training-step timing at context length 1024. The baseline time includes the forward pass, backward pass, and optimizer update. Overhead is the content-addressed model's increase relative to the baseline.
| Parameters | Layers | Heads | Batch | RoPE ms | Overhead | |
|---|---|---|---|---|---|---|
| 0.8M | 128 | 4 | 4 | 8 | 42 | +10.3% |
| 85M | 768 | 12 | 12 | 4 | 702 | +4.4% |
| 302M | 1024 | 24 | 16 | 2 | 1215 | +3.5% |
| 680M | 1536 | 24 | 16 | 1 | 1428 | +2.0% |
The content-addressed model adds vectorized boundary detection, local rotation before pooling, scatter-add mean pooling, and a LayerNorm followed by a -to- linear projection. These operations require work for fixed hidden size. Transformer training includes attention and feed-forward network work of order .
C Continuity of Content-Derived Scores
Context-size invariance removes growth caused by the number of units, but it does not by itself constrain how addresses vary with content. The following standard bound states one sufficient condition.
Proposition 2 (Content-derived addresses change scores continuously). Let be a metric space and let be -Lipschitz in operator norm. For unit-norm , define
Then
Proof. Insert and subtract . The triangle inequality, orthogonality of all surrounding factors, and give the result.
This stability bound does not require or guarantee that distinct descriptors receive distinct addresses.