Skip to main content
QUICK REVIEW

[Paper Review] Relative Positional Encoding for Transformers with Linear Complexity

Antoine Liutkus, Ondřej Cífka|arXiv (Cornell University)|May 18, 2021
Music and Audio ProcessingComputer Science67 references14 citations
TL;DR

This paper introduces Stochastic Positional Encoding (SPE), a novel method that enables relative positional encoding (RPE) in linear-complexity Transformers by filtering random noise through learnable filters, thereby achieving RPE-like inductive bias without explicit attention matrix computation. SPE provably emulates cross-covariance structures of correlated Gaussian processes and improves performance on Long-Range Arena and music generation tasks compared to sinusoidal PE.

ABSTRACT

Recent advances in Transformer models allow for unprecedented sequence lengths, due to linear space and time complexity. In the meantime, relative positional encoding (RPE) was proposed as beneficial for classical Transformers and consists in exploiting lags instead of absolute positions for inference. Still, RPE is not available for the recent linear-variants of the Transformer, because it requires the explicit computation of the attention matrix, which is precisely what is avoided by such methods. In this paper, we bridge this gap and present Stochastic Positional Encoding as a way to generate PE that can be used as a replacement to the classical additive (sinusoidal) PE and provably behaves like RPE. The main theoretical contribution is to make a connection between positional encoding and cross-covariance structures of correlated Gaussian processes. We illustrate the performance of our approach on the Long-Range Arena benchmark and on music generation.

Motivation & Objective

  • Address the lack of relative positional encoding (RPE) in linear-complexity Transformer variants, which avoid computing the full attention matrix.
  • Bridge the gap between RPE’s known benefits and the scalability of linear-attention mechanisms.
  • Develop a differentiable, parameter-efficient positional encoding method that mimics RPE behavior without requiring explicit attention computation.
  • Establish a theoretical link between positional encoding and cross-covariance structures in Gaussian processes.
  • Demonstrate that SPE generalizes RPE and improves performance in long-sequence modeling tasks.

Proposed method

  • Propose Stochastic Positional Encoding (SPE) as a replacement for sinusoidal positional encoding, using filtered random noise to generate position-aware queries and keys.
  • Model SPE as a filtering process on white noise using learnable filters, where the cross-covariance of the filtered noise approximates the desired RPE structure.
  • Theoretical foundation: connect SPE to the cross-covariance of correlated Gaussian processes, showing that SPE can emulate any prescribed cross-covariance structure.
  • Implement two variants: sinusoidal SPE (SPE-S) and convolutional SPE (SPE-C), where the latter convolves random noise with learnable filters.
  • Integrate SPE directly into queries and keys, avoiding position-content interaction in values, following the disentangled attention paradigm.
  • Train the filters end-to-end via backpropagation, enabling the model to learn position-dependent attention patterns without computing the full attention matrix.

Experimental results

Research questions

  • RQ1Can relative positional encoding (RPE) be effectively incorporated into linear-complexity Transformers that avoid explicit attention matrix computation?
  • RQ2Is there a differentiable, parameter-efficient method to generate positional encodings that emulate the inductive bias of RPE without requiring full attention computation?
  • RQ3Can the cross-covariance structure of filtered random noise be used to model the desired inductive bias of RPE in attention mechanisms?
  • RQ4Does SPE generalize the benefits of RPE in terms of performance on long-range sequence modeling tasks?
  • RQ5Can SPE be extended to arbitrary attention kernels beyond dot-product attention, particularly in implicit kernel methods like Performer?

Key findings

  • SPE successfully enables relative positional encoding in linear-complexity Transformers by avoiding explicit attention matrix computation.
  • The convolutional variant of SPE (SPE-C) achieves state-of-the-art performance on the Long-Range Arena benchmark, outperforming both sinusoidal PE and baseline models.
  • On music generation tasks with long sequences (e.g., 3,072 tokens), SPE improves generation quality and coherence compared to sinusoidal PE.
  • Theoretical analysis shows that SPE’s cross-covariance structure can be made to match that of RPE, providing a principled foundation for its design.
  • Empirical results suggest that SPE generalizes beyond dot-product attention, indicating potential for extension to other implicit kernel methods like Performer.
  • Removing absolute positional encoding in favor of SPE leads to improved performance in some settings, supporting the idea that RPE-like inductive bias is more effective than APE in long-range modeling.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.