Manuscript Offprint

arXiv:2610.30465

Flow-based Spectral Kernel Learning for Nonstationary Attention

Zi Yang, Ying Li, Alejandro Lancho, Darío C. Larese, Pablo M. Olmos, Michael Minyi Zhang

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

Abstract

Kernelized attention provides a useful perspective for understanding self-attention as a similarity-based aggregation mechanism, but existing approaches often rely on fixed or stationary kernels, limiting their ability to adapt the similarity structure to complex token interactions. In this paper, we propose flow-based spectral kernel attention (FSKA), a framework for learning expressive nonstationary attention kernels. FSKA formulates kernelized attention through spectral density learning and parameterizes the resulting bivariate spectral density with normalizing flows. This design enables flexible and regularizable kernel learning while remaining compatible with scalable linear-attention computation. We further show that expressive kernel learning enables a simplified attention design with removed query-key projections and fixed orthogonal value projections, resulting in a more parameter-efficient architecture. Controlled experiments on classification, ablation, and scalability profiling show that FSKA achieves competitive or improved performance over existing attention mechanisms, while reducing projection-related trainable parameters by approximately 40%–47% compared with most baselines and maintaining favorable linear-attention memory scaling. Code Available: https://github.com/ziyang18/FSKA.

1 Introduction

Transformers have become the dominant architecture for sequence modeling in natural language processing, vision, and multimodal learning, largely due to the success of self-attention [Vaswani et al., 2017, Brown et al., 2020, Dosovitskiy et al., 2021]. At its core, self-attention computes pairwise token similarities and uses them to aggregate information. This similarity-based view has motivated a growing line of work that interprets attention as a kernel machine [Tsai et al., 2019]. Under this kernel perspective, different kernel choices induce different similarity measures for token aggregation, with standard softmax attention corresponding to one particular kernel.

This kernel view has led to substantial progress on efficient attention. Methods such as random feature attention (RKA) and the Performer approximate the softmax kernel using random features, enabling linear-time attention with respect to sequence length [Peng et al., 2021, Choromanski et al., 2021]. However, these approaches typically rely on fixed or stationary kernels, whose similarity measures do not adapt to the input data. As a result, they are often limited in modeling complex or context dependent (nonstationary) interactions between tokens.

40th Conference on Neural Information Processing Systems (NeurIPS 2026).

To overcome the rigidity of fixed kernels, several recent works have explored learnable kernel attention under the Bochner's theorem. These methods learn the spectral density of the kernel and approximate the resulting kernel using random Fourier features (RFFs) for scalable attention. For example, GMM-RKS parameterizes the spectral density with Gaussian mixtures, while implicit kernel attention (IKAN) learns the spectral density through neural-network (NN) [Pal Chowdhury et al., 2022, Song et al., 2021, Li et al., 2019]. Although these methods improve flexibility, GMM-RKS can become costly when many components are needed to model complex spectra, and IKAN lacks an explicit density for principled spectral regularization and may suffer from overfitting or spectral collapse (see Figure 1). In summary, existing approaches often fall between one of two extremes: fixed kernels are efficient but too restrictive, whereas highly flexible kernels are more expressive but often lack explicit spectral densities for regularization or can become computationally burdensome.

In this paper, we address this gap by proposing “flow-based spectral kernel attention” (FSKA), a flexible and efficient framework for learning nonstationary attention kernels. Our main contributions are summarized as follows:

• We formulate nonstationary attention kernel learning as spectral density learning. To obtain flexible and stable kernels, we parameterize the spectral density with normalizing flows and regularize it with a structured spectral prior. The resulting kernel remains compatible with RFF-based linear attention.

• We show that expressive kernel learning enables a simplified attention design with removed query-key projections and fixed orthogonal value projections, resulting in a more parameter-efficient architecture.

• We conduct experiments across regression and classification tasks, together with ablation and scalability studies. FSKA achieves competitive or improved performance across these settings, reduces projection-related trainable parameters by approximately 40%–47% compared with most baselines, and maintains a low-growth memory profile close to linear-attention baselines.

References (45)

  • Advances in Neural Information Processing Systems, 33:1877–1901, 2020
  • Metala: Unified optimal linear approximation to softmax attention map
  • FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness
  • Density estimation using real NVP. International Conference on Learning Representations, 2017
  • Transformers for image recognition at scale
  • Mamba: Linear-Time Sequence Modeling with Selective State Spaces
  • Transformers are RNNs: Fast autoregressive transformers with linear attention
  • Implicit kernel learning
  • Learning question classifiers
  • Learning the transformer kernel
  • Seeing stars: Exploiting class relationships for sentiment categorization with respect to rating scales
  • Random feature attention
  • Random features for large-scale kernel machines
  • Recursive deep models for semantic compositionality over a sentiment treebank
  • Implicit kernel attention
  • Long range arena: A benchmark for efficient transformers (opens arXiv in a new tab)
  • Unveiling the hidden structure of self-attention via kernel principal component analysis
  • Transformer dissection: A unified understanding for Transformer's attention via the lens of kernel
  • Attention is all you need
  • Multi-view oriented GPLVM: Expressiveness and efficiency
  • Character-level convolutional networks for text classification
  • sampled row vectors from $p(\omega_1, \omega_2)$
  • Since $k \in C(\mathcal{U} \times \mathcal{V})$, the composition
  • The original plotting script measures the fraction of negative or relatively small denominators:
  • This statistic differs from an absolute near-zero threshold
  • Its population counterpart is
  • It compares the signed Gram matrix $S_{ij} = \phi(x_i)^\top \phi(x_j)$ with $S_{ij}^+ = g(\phi(x_i))^\top g(\phi(x_j))$
  • However, the absolute discrepancy remains approximately 0.8
  • PRF introduces a positive baseline and can compress similarity contrast; the persistent discrepancy is a limitation of interpreting the transformed affinity as the original signed spectral kernel
  • Each $s_k(t)$ uses different sinusoidal frequency/phase patterns, $m(t)$ is a position-dependent mean-shift/trend term, and $\sigma^2(t)$ introduces heteroscedastic noise
  • Qualitatively, Ours FSKA tracks regime boundaries and high-curvature regions more faithfully while preserving global phase alignment
  • All experiments are conducted on MNIST, and results are summarized in Table 5
  • >(b) RFF Dimension $M$</td></tr><tr><td>$M=32$</td><td>0.8656</td><td>69.43</td></tr><tr><td>$M=64$</td><td>0.8692</td><td>81.70</td></tr><tr><td>$M=128$</td><td>0.8822</td><td>149.20</td></tr><tr><td colspan=
  • It shares the same encoder backbone dimensions as the other baselines, but generates Fourier features through a small generator network rather than using fixed random projections
  • All datasets are lowercased and tokenized with a simple whitespace tokenizer
  • The document classification experiments in Section 4.3 cover legal opinions (SCOTUS), news articles (BBC News), newsgroup posts (20NG), and scientific papers (arXiv)
  • SCOTUS is loaded from the scotus subset of LexGLUE, BBC News from SetFit/bbc-news, and arXiv from ccdv/arxiv-classification
  • The shared text preprocessor lowercases text, normalizes whitespace, and tokenizes by whitespace splitting
  • The supplied FSKA classification configuration uses embedding and hidden dimensions of 128, four attention heads, two encoder layers, a feed-forward dimension of 256, and dropout 0.1
  • We compare Transformer, FlashAttention, Performer, Mamba, RKA, GMM-RKS, KPCA-Scaled, MIKAN, and FSKA. FSKA uses the positive random features described in Section 3.1, with learned query-key projections removed and fixed orthogonal value projections
  • The bivariate nonstationary feature construction, PRF transformation, removal of learned query-key projections, fixed value projection, and remaining experimental settings are retained
  • >Model</td><td colspan=
  • The default flow depth for these document-classification experiments is $N_{f} = 3$
  • Across the tested settings, the gap magnitude is at most 0.90 points
  • ><tr><td colspan=