arXiv:2610.10690cs.LGOct 2026

Manuscript Offprint

arXiv:2610.10690

Learning infinite context windows in recurrent architectures via spatial neural computing

Aleix Salvador-Pomarol, Arthur N. Montanari, Earl K. Miller, Adilson E. Motter, Jorge Cortés

Aleix Salvador-Pomarol

UC San Diego

asalvadorpomarol@ucsd.edu

Arthur N. Montanari

Northwestern University

arthur.montanari@northwestern.edu

Earl K. Miller

Massachusetts Institute of Technology

ekmiller@mit.edu

Adilson E. Motter

Northwestern University

motter@northwestern.edu

Jorge Cortés

UC San Diego

jcortes@ucsd.edu

Abstract

Recurrent neural networks (RNNs) offer linear-time scaling with sequence length while requiring only constant memory, yet they struggle to capture long-range dependencies due to vanishing gradients and limited receptive fields. To address these limitations, we introduce a second-order recurrent model in which the standard neuron-to-neuron communication is replaced by a spatially evolving field governed by (discretized) partial differential equations. Drawing inspiration from the role of cortical waves in brain computation, this mechanism allows structured spatiotemporal patterns to serve as an implicit, high-capacity memory. We show that the resulting model is equivalent to a structured infinite-order RNN in which the current state depends explicitly on its entire history of past states, yielding an effectively unbounded receptive field with a fixed number of parameters. We further derive constructive conditions to ensure marginal stability, constraining the gradient spectrum on the unit circle and thereby eliminating vanishing and exploding gradients. Empirically, the proposed architecture outperforms other recurrent models on long-horizon benchmarks while using substantially fewer parameters, demonstrating that spatial dynamics can effectively bridge the gap between efficient inference and long-term memory.

1 Introduction

For decades, recurrent neural networks (RNNs) have served as the cornerstone of sequence modeling. These models rely on hidden states that are recurrently updated to process sequential inputs, acting as a dynamical memory of past information. In contrast to stateless architectures, RNNs offer the theoretical promise of compressing an unbounded context into a fixed-size state, resulting in O(1)O(1) memory cost with respect to the sequence length T and O(T)O(T) computational complexity. However, the practical efficacy of classical RNNs is severely constrained by the vanishing and exploding gradient problem (Bengio et al., 1994). From a dynamical systems perspective, this issue stems from the spectrum of the recurrence matrix. When its eigenvalues are stable ( ∣λ∣<1|\lambda| < 1) or unstable ( ∣λ∣>1|\lambda| > 1), perturbations respectively decay or grow exponentially, leading to a loss of long-term dependencies during training. While unitary and orthogonal RNNs (Arjovsky et al., 2016; Ceni, 2025; Henaff et al., 2016; Kerg et al., 2019; Le et al., 2015) can mitigate this problem by constraining the eigenvalues to be marginally stable ( ∣λ∣=1|\lambda| = 1), the nonlinearities of the activation functions perturb the effective dynamics away from the unit circle, reintroducing vanishing/exploding gradients. Moreover, such constraints limit the model expressivity and convergence speed (Kerg et al., 2019; Ribeiro et al., 2020). To bypass these spectral issues, architectures such as the long short-term memory (LSTM) (Hochreiter & Schmidhuber, 1997) and gated recurrent unit (GRU) (Cho et al., 2014) introduce gating mechanisms with linear gradient updates. These additive gates prevent gradients from exponentially decaying due to repetitive multiplicative operations, but they also come at the cost of increased architecture complexity and parameter count, leading to higher computational overhead (Chung et al., 2014), limited parallelization (Li et al., 2018), and implicit timescale biases (Neil et al., 2016).

Recently, the transformer architecture has largely supplanted RNNs due to its ability to model long-range dependencies via self-attention. However, the transformer's supremacy comes at a steep cost: the key-value memory grows linearly, O(T)\mathcal{O}(T), during inference and the attention mechanism scales quadratically, O(T2)\mathcal{O}(T^{2}) (Kwon et al., 2023; Vaswani et al., 2017). These scaling properties effectively reintroduce the “von Neumann gap” in modern artificial intelligence (AI) as a significant portion of inference time and energy is spent on memory access rather than computation (Dao et al., 2022). This computational bottleneck has renewed interest in dynamical-systems-based architectures (Sieber et al., 2024), such as state-space models (SSMs) (Gu & Dao, 2024; Gu et al., 2022; Somvanshi et al., 2025) and oscillator networks (Effenberger et al., 2025; Keller & Welling, 2023; Keller et al., 2024; Rusch & Rus, 2025; Rusch et al., 2022). Although these approaches improve memory-computation trade-offs, they typically rely on dissipative dynamics. As a result, they do not provide mechanisms to maintain nonvanishing gradients over arbitrarily long horizons (Gu & Dao, 2024; Rusch & Mishra, 2021a). Moreover, controlling memory-retention and forgetting mechanisms in these models remains challenging, often requiring increased parameterization or complex hybrid architectures to achieve sufficient expressivity (Karuvally et al., 2026; Wang et al., 2025).

Taken together, these limitations raise a fundamental question: What structural features allow recurrent architectures to maintain nonvanishing gradient modes over long horizons despite input-dependent nonlinear perturbations? Through a spectral analysis of the gradient dynamics, we show that the answer lies in how the nonlinearity enters the gradient equations, rather than in the spectrum of the recurrence matrices. In conventional first-order recurrent architectures (e.g., RNNs), these perturbations directly affect the coefficients that control modal decay, making robust marginal stability impossible regardless of the parameterization. In contrast, a second-order recurrent architecture can have additional, input-independent coefficients that selectively fix the magnitude of gradient modes to enforce marginal stability while allowing inputs to perturb the remaining dynamics. Such a separation arises naturally, for example, in wave propagation dynamics, since its inertial term is determined by the medium itself rather than by the input signal driving it. This connection suggests that wave dynamics may be potentially used as a natural computational substrate for memory retention—an idea further motivated by increasing evidence on the role of cortical traveling waves in encoding, maintaining, and transforming information through distributed spatiotemporal activity patterns (Benigno et al., 2023; Davis et al., 2021; Ermentrout & Kleinfeld, 2001; Singer, 2021).

In this paper, we propose a spatial computing model, called SpatialRNN, in which recurrent neuron-to-neuron communication is mediated through a spatially evolving medium governed by (discretized) partial differential equations (PDEs). This mechanism allows structured spatiotemporal patterns to be encoded and processed directly in the state of the medium, providing a dynamical substrate for retaining long-term temporal dependencies. In fact, we rigorously prove that the SpatialRNN is mathematically equivalent to an RNN in which the current state hth_t depends explicitly on all its past states {ht−1,ht−2,ht−3,…}\{h_{t-1}, h_{t-2}, h_{t-3}, \ldots\}. The SpatialRNN therefore provides an implicit and parameter-efficient realization of an unbounded receptive field. Crucially, the second-order gradient recurrence induced by the spatial medium can be designed to support nonvanishing gradient modes over arbitrarily long time horizons, ensuring robust marginal stability. To achieve this, we derive constructive conditions that constrain the (frozen-time) gradient modes on circles of prescribed radii for every admissible nonlinear perturbation, providing explicit control over memory retention (unit radius) and forgetting (smaller radii) through tunable decay rates. Our empirical results show that the gradient norms of trained SpatialRNNs remain nearly constant over long input trajectories and that the SpatialRNN achieves competitive performance on long-horizon benchmarks while often requiring considerably fewer parameters, highlighting the role of spatial computing as an efficient computational paradigm.

References (49)