Manuscript Offprint

arXiv:2610.20586

Continuum Attention

Afshin Khadangi

Afshin Khadangi

SnT, University of Luxembourg

afshin.khadanki@uni.lu

afshin.xyz

Figure

oi=∫−1/2i+1/2pi(t)v(t)dt\mathbf{o}_{i}=\int_{-1/2}^{i+1/2}p_{i}(t)\mathbf{v}(t)dt

MEMORY CONTINUUM

Figure 1: Overview of Continuum Attention. Adjacent key and value representations define a continuous memory trajectory. Each query induces a relevance density pi(t)p_i(t) and determines adaptive retrieval positions μ(Δij)\mu(\Delta_{ij}) within memory segments. Exact integration, including the half token boundary extensions, produces the attention output.

Abstract

We introduce Continuum Attention (CA), a causal Transformer attention operator that replaces discrete key and value lookup with integration over a continuous, piecewise linear memory curve. Each query induces an exponential relevance density along the curve. Integrating the density and interpolated values yields exact normalized attention from closed form exponential moments, including half token boundary contributions. The gradients follow analytically from moments of order at most two, enabling parallel GPU implementations while retaining quadratic sequence complexity and the standard Transformer decoder. Compared with ordinary softmax and focal attention, CA reduces mean validation negative log likelihood by 0.0200 and 0.0480 nats per byte, respectively, winning all paired comparisons. An additional disjoint validation slice yields a 0.0457 nats per byte advantage over the strongest selected softmax baseline, with a paired 95% confidence interval. These findings motivate continuous integration as a promising attention alternative while leaving larger scale generalization open.

Working Paper.

1 Introduction

Attention mechanisms have become a fundamental component of modern neural networks, enabling representations to be constructed through content dependent interactions between queries, keys, and values [1, 13]. In the Transformer, scaled dot product attention assigns a normalized exponential weight to each available key and aggregates the corresponding value vectors. For a causal query at position i, this operation takes the form

oi=∑j=0iexp⁡(sij)vj∑j=0iexp⁡(sij),sij=qi⊤kjτdh,(1)\mathbf{o}_{i}=\frac{\sum_{j=0}^{i}\exp(s_{i j})\mathbf{v}_{j}}{\sum_{j=0}^{i}\exp(s_{i j})},\qquad s_{i j}=\frac{\mathbf{q}_{i}^{\top}\mathbf{k}_{j}}{\tau\sqrt{d_{h}}}, \tag{1}

where τ>0\tau > 0 controls the sharpness of the attention distribution and dhd_h denotes the attention head dimension.

This formulation represents memory through a finite collection of key and value vectors. Each memory position contributes through its individual relevance score, and normalization is performed over discrete positions. Although learned projections produce continuous vector representations, the aggregation operator evaluates these representations only at the sampled token positions. This distinction motivates an alternative representation in which adjacent memory vectors define a continuous trajectory and the query retrieves information through integration along that trajectory.

Previous research has explored alternative attention distributions [6], adaptive receptive fields, and computationally efficient attention operators [12, 2, 3]. Continuous domain attention has also been studied through exponential families, sparse probability densities, and analytical differentiation [7, 8]. A complementary mathematical perspective describes attention through integral operators acting on probability measures [14]. These developments motivate further investigation of the relationship between the geometry of stored representations and the measure used to retrieve information from them.

Prior work established a general framework for continuous attention through probability densities over continuous domains, including continuous softmax and sparse distributions with analytical gradients [7]. Building on this foundation, Continuum Attention specifies a causal, content dependent construction directly from Transformer key and value representations. Adjacent memory vectors define piecewise linear trajectories, and each query induces an exponential relevance density whose segment integrals admit exact evaluation through exponential moments. This construction avoids fitting a separate continuous value function and supports direct integration into standard autoregressive Transformer layers.

We introduce Continuum Attention (CA), a causal attention operator that constructs a continuous memory trajectory from the key and value representations of a Transformer. Consecutive vectors are connected through piecewise linear interpolation, defining continuous functions k(t)\mathbf{k}(t) and v(t)\mathbf{v}(t) over memory position tt. Each query induces an exponential relevance density along this trajectory, and its output is obtained through normalized integration:

∣oiCA=∫−1/2i+1/2exp⁡(qi⊤k(t)τdh)v(t)dt∫−1/2i+1/2exp⁡(qi⊤k(t)τdh)dt∣.(2)\left|\mathbf{o}_{i}^{\mathrm{C A}}=\frac{\int_{-1/2}^{i+1/2}\exp\left(\frac{\mathbf{q}_{i}^{\top}\mathbf{k}(t)}{\tau\sqrt{d_{h}}}\right)\mathbf{v}(t)d t}{\int_{-1/2}^{i+1/2}\exp\left(\frac{\mathbf{q}_{i}^{\top}\mathbf{k}(t)}{\tau\sqrt{d_{h}}}\right)d t}\right|. \tag{2}

The integration domain includes constant extensions of the first and last visible memory vectors over half unit intervals. These boundary contributions preserve the intended token mass convention, including uniform weighting when all relevance scores are equal.

The defining property of CA is its query adaptive retrieval geometry. Within each Transformer layer and attention head, independently learned projections define a distinct memory trajectory. Each query determines a relevance density over that trajectory and thereby controls the effective retrieval locations within individual memory segments. Consequently, different queries can retrieve different interpolated values from the same stored key and value sequence. This adaptation emerges directly from the query dependent score function and remains present when the attention temperature is fixed.

The piecewise linear construction also provides an analytical advantage. Along each memory segment, the relevance score is an affine function of the interpolation coordinate. The exponential integrals therefore admit exact expressions in terms of moments

Jn(Δ)=∫01unexp⁡(Δu)du,(3)J_{n}(\Delta)=\int_{0}^{1}u^{n}\exp(\Delta u)d u, \tag{3}

where moments of orders zero and one determine the forward aggregation, and the second order moment completes the analytical score derivatives. The resulting operator can be evaluated using finite algebraic expressions, allowing implementation through parallel GPU operations. CA retains the quadratic sequence complexity of conventional dense attention and can be incorporated into a standard causal Transformer decoder.

We investigate CA through byte level language modeling on TinyStories [4]. The experiments use a six layer Transformer with approximately five million parameters, five independent training seeds, and context lengths of 192 and 512 tokens. We compare CA against conventional softmax attention under matched model configurations, training budgets, and attention temperatures. With a fixed temperature of 0.30, CA reduces mean validation negative log likelihood by 0.0200 and 0.0480 nats per byte at the two context lengths, respectively, with improvements in all five paired seed comparisons at each length. On an additional disjoint evaluation slice, CA achieves an improvement of 0.0457 nats per byte at 512 tokens over the development selected softmax baseline, with a paired 95% confidence interval of [0.0316, 0.0598]. This additional evaluation is exploratory because the slice was previously examined during model comparisons. The results demonstrate promising small scale language modeling performance while motivating further evaluation at larger model sizes and on additional datasets.

The contributions of this work are an exact formulation of causal attention over interpolated memory trajectories, a query adaptive retrieval mechanism with analytical forward and backward expressions, parallel GPU implementations validated against numerical reference calculations, and controlled empirical comparisons with conventional softmax attention across multiple training seeds and context lengths.

References (15)