Manuscript Offprint

arXiv:2609.37879

Retrieval Capacity of Self-Attention Under Competition

Timur Mudarisov, Mikhail Burtsev, Radu State

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

How many tokens from its context does a language model actually use, and what determines that number? We study this question through self-attention. Without retraining, we retain only the tokens with the highest attention weights at each head, layer, and query, keeping their original weights unchanged. By varying the selected set size and measuring the increase in negative log-likelihood (NLL), we estimate the effective attention set size needed to stay within a chosen loss tolerance. Relatively small selected sets can keep NLL close to the full-attention baseline, although the required size varies across models. Attention-based selection substantially outperforms random selection. Selected sets exhibit geometric structure, although geometric separation alone does not establish that model loss is preserved. Extending context while evaluating the same prediction targets increases the required set size, while its fraction of context decreases over the tested range. Experiments with a fixed supporting fact show that additional background pushes its tokens down the attention ranking and reduces their attention mass. Renormalizing the retained weights can substantially reduce the required set size, showing that it also depends on how selected representations are combined. Conditional theoretical models explain how competition and attention-mass retention can produce growing set sizes without more distinct information to retrieve. These results provide a way to measure effective attention set size in language models and investigate its dependence on context, competition, and aggregation.

1 Introduction

How many tokens from its context does a language model actually use, and what determines that number? Self-attention provides a natural setting for studying this question because it explicitly scores context tokens and combines their value vectors. Previous work by Mudarisov et al. [2026] found that sets selected by the largest attention weights exhibit stronger geometric separation than random sets of the same size in the space of weighted value vectors. This observation suggests a structured selection process and motivates examining whether the selected tokens are sufficient to preserve model performance.

We develop this perspective through a useful-token hypothesis. For each local context C=(X,ℓ,h,t)C = (X, \ell, h, t), we posit an unknown useful set whose size K(C)K(C) can vary with the sequence, layer, head, and query position. Attention provides an imperfect ranking of this set, with useful tokens assumed to rank above other tokens with relatively few errors on a reference distribution. Recovering the useful set therefore depends on both its size and the quality of the ranking. Even when the useful set remains fixed, ranking errors can require retaining additional tokens. This framework guides our analysis of observable selected sets while leaving their relationship to the unknown useful set to be investigated.

We first examine the geometric separation of selected and unselected tokens under Euclidean and cosine distances, using random sets of the same size as controls. We then test the selected sets

Preprint.

through their effect on language-modeling loss. At every query, head, and layer, we retain up to N tokens ranked by attention weight or contribution magnitude, keeping their original attention weights unchanged. Selection is recomputed throughout the intervened forward pass without retraining. By varying N and measuring the increase in average negative log-likelihood (NLL), we estimate the effective attention set size Nτ∗N_{\tau}^{*} needed to remain within a chosen loss tolerance τ\tau. The same size limit applies throughout the model, while each attention operation selects its own tokens. Comparing geometric separation with NLL degradation then tests whether the observed structure indicates functional sufficiency.

We study what affects the required set size through two complementary experiments. In language modeling, we extend the available context while evaluating the same prediction targets. The required set size increases with context length, although its fraction of the context decreases over the tested range. Additional natural context also improves the full model's predictions, so this experiment can reflect changes in both useful information and competition. We therefore complement it with BABILong experiments that add background text around a fixed annotated supporting fact. These experiments track changes in support ranking, attention mass, and recall alongside the selected-set size needed to preserve answer loss.

The treatment of retained attention weights provides a further explanation of the measured set sizes. Renormalizing these weights can substantially reduce the number of tokens required, showing that functional sufficiency also depends on how selected representations are combined. We develop conditional theoretical models of ranking competition and attention-mass retention to explain how required set sizes can grow with context, including settings with a fixed required set or identical value vectors. These results connect the useful-token framework to the functional measurements while accounting for the effect of the intervention on the attention output.

Our contributions are:

  1. A useful-token framework for attention selection. We distinguish the unknown useful set from observable selected sets and derive recovery bounds connecting ranking errors to the number of tokens that must be retained.

  2. Geometric and functional analysis of selected sets. We compare geometric separation with loss preservation and estimate effective attention set sizes across nine checkpoints, using attention, contribution, and random selection.

  3. Evidence for context-dependent set sizes. We measure the effect of context extension with fixed prediction targets and examine competition through background addition at fixed annotated support.

  4. Aggregation controls and conditional explanations. We compare deletion with renormalization and develop theoretical models showing how ranking competition and preservation of attention mass can make required set sizes grow with context.

References (93)

  • On identifiability in transformers
  • Gemma: Open Models Based on Gemini Research and Technology
  • Gemma 2: Improving Open Language Models at a Practical Size
  • OpenWebText corpus
  • The Llama 3 Herd of Models
  • Active-dormant attention heads: Mechanistically demystifying extreme-token phenomena in LLMs (opens arXiv in a new tab)
  • Mistral 7B
  • BABILong: Testing the limits of LLMs with long context reasoning-in-a-haystack (opens arXiv in a new tab)
  • From softmax to sparsemax: A sparse model of attention and multi-label classification
  • Pointer sentinel mixture models
  • Geometric analysis of token selection in multi-head attention (opens arXiv in a new tab)
  • Sparse sequence-to-sequence models
  • Hopfield networks is all you need
  • OrthoRank: Token selection via sink token orthogonality for efficient LLM inference (opens arXiv in a new tab)
  • Llama 2: Open Foundation and Fine-Tuned Chat Models
  • Attention is All you Need
  • Efficient Streaming Language Models with Attention Sinks
  • Qwen2.5 Technical Report
  • We give the recovery bounds behind the useful-token framework, specify the geometric construction, and derive local output-error identities for the two interventions
  • For an observable score $r_{i}$, define
  • At $N = K$, precision, recall, and their harmonic mean relative to $\mathcal{S}^*(C)$ satisfy
  • Increasing the selected-set size can therefore compensate for ranking errors while $K(C)$ remains fixed
  • The extremal metrics are
  • This convention counts an unselected boundary point as contamination and excludes a selected point tied with the nearest unselected point from recall
  • Consequently, the geometric metrics need not be monotone in N. Random controls use sets of the same size and recompute all quantities around each random set's own aggregate
  • For positive $\alpha_{i}$ and nonzero $v_{i}$ and $s_{N}$, unregularized cosine similarity satisfies
  • Full-model interventions can also change the inputs to later attention operations
  • Neither bound generally orders the actual errors of different subsets, because discarded vectors can cancel
  • The exploratory analysis in Appendix E.4 uses the corresponding coherence statistic
  • We specify the sampling, scoring, intervention, and uncertainty procedures for each experiment
  • The selected-set sizes are $N \in \{1, 2, 4, 8, 16, 32, 64, 128, 256\}$
  • Logits at positions 0, ..., L - 2 predict the 1023 target tokens at positions 1, ..., L - 1
  • Relative degradation is computed from the corpus means in Equation 8
  • The search initializes all powers of two through L, bisects a failure/pass bracket, checks $h - 3$ through $h + 3$ within $[1, L]$, and checks the predecessor of the first tested pass
  • WikiText preparation retains 2044 of 2048 rows after removing four duplicates with identical IDs and text
  • Mistral-7B-v0.3 has complete OpenWebText results through $L = 1024$, partial attention-ranking refinement at $L = 2048$, and no WikiText results
  • All 28 saved numerical parity checks pass, with maximum NLL discrepancy $5.76 \times 10^{-7}$
  • The resulting intervals are conditional on the evaluated selected-set sizes and do not account for unmeasured crossings
  • Return only the short answer
  • There is no trailing space after the final colon
  • Accuracy normalizes case, exterior whitespace, repeated whitespace, and terminal punctuation
  • The configured competence screen requires full-model accuracy at least $1/6 + 0.05$ and loss at most $\log 6 - 0.05$
  • If N is at least the prompt length, the intervention is an exact no-op
  • Fast-tokenizer offsets $[a_j, b_j)$ map a character span $[a, b)$ to tokens satisfying $b_j > a$, $a_j < b$, and $b_j > a_j$
  • Cross-model displacement and mass ratios average $\bar{q}_{m,4K}/\bar{q}_{m,0K}$
  • For Gemma-2, it applies the model's final-logit tanh softcapping before cross-entropy
  • This section extends those comparisons across corpora and rankings, examines sensitivity to geometric boundaries, and reports the complete set-size estimates and uncertainty
  • The Euclidean singleton identity in Appendix A.2 motivates checking whether small selected sets dominate the correlations in Figure 4
  • The correlations use 9, 8, or 6 selected-set sizes from the same trajectories
  • The columns use 9, 8, and 6 measured powers-of-two sizes, respectively
  • Figure 14 shows that $N^{*} / L$ decreases at the $5\%$ tolerance over the measured range
  • Bootstrap intervals conditional on the evaluated sizes include one for Gemma/OpenWebText and for Llama on both corpora
  • At $L = 2048$, the $5\%$ attention estimates and $95\%$ intervals on OpenWebText are 78 [72, 102] for Qwen, 504 [480, 640] for Gemma, and 57 [54, 96] for Llama
  • At $L = 2048$, $5\%$ attention estimates for final-128-target and all-token scoring are 78/51, 504/394, and 57/30 on OpenWebText, and 70/48, 423/332, and 66/36 on WikiText-103, for Qwen, Gemma, and Llama
  • Figure 16 reports full-model NLL on the matched final 128 targets
  • Mean support recall@64 falls by 63.8 percentage points
  • The mean non-support count increases by approximately $108-111\times$ from 0K to 4K
  • This identity requires no independence assumption
  • Gemma at 2K and Mistral at 4K remain unresolved on the evaluated sizes through 256
  • The main text accordingly reports increasing requirements in several models over the tested range
  • Llama improves at 1K, and its paired 0K-to-4K accuracy-change interval is approximately $[-22, +2]$ percentage points, which includes zero
  • These are the baselines for the loss curves in Figure 20
  • This limits how much net accuracy can decrease under intervention and makes a small accuracy-based set-size estimate difficult to interpret as successful multi-fact retrieval
  • The controls below examine these factors by rescaling retained weights, comparing related checkpoints, localizing interventions, and testing functional predictors and positional selection
  • Both rankings are shown
  • ><tr><td rowspan=
  • The effect depends on the model, ranking, and tolerance
  • Dashes indicate background conditions that were not evaluated for this control
  • >Model</td><td rowspan=
  • (a) Ratios of renormalized to deletion estimates on OpenWebText from Table 9
  • The approximately 19–29-fold differences show that model-family identity and parameter count alone do not account for the Gemma-7B requirement
  • Every query head in these layers is tested separately
  • The layer and head estimates use different sample sizes and baseline averages, so their ratio cannot assign a share of the layer effect to that head
  • The results reveal variation within models, while comparisons across models remain conditional on these different intervention sizes
  • Reference selected-set sizes are 128 for Gemma, 16 for Qwen, and eight for Mistral
  • This exploratory analysis uses the four geometry models, 20 OpenWebText documents per model, $L = 1024$, both rankings, selected-set sizes $N \in \{8, 16, 32, 64, 128, 256\}$, and relative NLL tolerances of 5% and 10%
  • They include geometric separation and margins, discarded mass, discarded-vector norms and energy, tail coherence from Appendix A.3, and the sensitivity statistic below
  • These statistics are then averaged across layers and documents
  • Dense probabilities are computed before masking, as in the main intervention
  • The positional mask retains one initial source and N - 1 recent sources
  • Earlier representations can still carry support information, and other prompt cues can affect the answer
  • We develop conditional models that connect these observations to useful-set recovery and preservation of the weighted sum
  • Bounded expected set size at fixed $K$ requires $Dp_L = O(1)$
  • If $m(\rho_{\varepsilon}) = 1 - \varepsilon$, then
  • Finite expectation implies continuity, and positivity implies strict increase
  • Growing loss-based set size can therefore arise from preserving output amplitude even when every value carries the same representation
  • This is an assumed common degradation profile across query positions
  • These satisfy $\rho_{\text{all}} \leq \rho_{\text{tail}}$
  • Although 128 targets form a fixed-size tail asymptotically, they occupy approximately half of a 256-position window
  • It supports treating the target population as part of the measurement definition
  • It does not collect new personal data, involve human participants, or infer properties of individual users
  • The supplementary tables report corpus-specific estimates and distinguish incomplete searches from unmeasured conditions
  • The authors are responsible for the mathematical statements, experimental design, data analysis, citations, and final text