Introduction
Large Language Models (LLMs) have revolutionized natural language processing, yet they remain constrained by the sequence lengths encountered during training. When these models are tasked with processing documents significantly longer than their training window—a challenge known as extrapolation—performance typically degrades. Traditional positional encoding methods, such as Rotary Position Embedding (RoPE), often fail to generalize to unseen positions, while alternatives like ALiBi (Attention with Linear Biases) achieve extrapolation by restricting the model's receptive field, effectively blinding it to distant tokens.
Researchers from NTT have introduced a novel solution to this dilemma: a Wavelet-based Relative Positional Representation. By leveraging the multi-scale properties of wavelet transforms, specifically the Ricker wavelet, this approach enables Transformers to handle long-context sequences far beyond their training limits without sacrificing the ability to attend to global information.
The Mathematical Insight: RoPE as a Wavelet
The foundation of this research lies in a critical mathematical observation: the popular RoPE method is actually a restricted form of a wavelet transform. Specifically, the authors demonstrated that RoPE functions as a fixed-scale wavelet transform using Haar-like wavelets. This explains its primary limitation: because it operates at a fixed scale, it cannot adapt to the "fine movements" or non-stationary signals present in much longer sequences.
In contrast, natural language is inherently non-stationary and fluid. To better capture these dynamics, the researchers proposed a multi-scale and multi-shift framework. Instead of the periodic sine waves used in standard encodings, they utilized the Ricker wavelet (often called the "Mexican Hat" wavelet). Its unique shape—a central peak flanked by negative dips—is mathematically better suited for analyzing signals that change over time and distance.
Methodology
The proposed Wavelet-based Relative Positional Representation (RPE) integrates the Ricker wavelet into the attention mechanism. Key features include:
- Multi-Scale Parameters ($a$): Different attention heads are assigned different scale parameters, allowing the model to focus on varying "window sizes," from highly localized patterns to broad, global contexts.
- Multi-Shift Parameters ($b$): These parameters allow the model to shift its focus across the sequence, ensuring comprehensive coverage.
- Relative Framework: Because the method calculates the distance between tokens rather than their absolute indices, it is inherently capable of infinite extrapolation.
Experimental Evaluation
The researchers validated the wavelet approach across several benchmarks and model scales:
- WikiText-103: Small-scale tests focused on perplexity across varying sequence lengths. When trained on a length of 512, the Wavelet method maintained low perplexity even at an inference length of 2,512 (5x extrapolation), significantly outperforming RoPE, ALiBi, and Transformer-XL.
- Llama-2-7B (RedPajama): To test scalability, a 7-billion parameter model was trained from scratch on a 4k context window. When evaluated on a 32k context, the Wavelet-based model achieved a perplexity of 8.60, notably better than the 8.90 achieved by the RoPE-based baseline.
- LongBench: On a comprehensive suite of long-context tasks (including NarrativeQA and TriviaQA), the model consistently outperformed RoPE, demonstrating that it does not just "see" long-range information but effectively utilizes it to solve complex tasks.
Key Findings
Global Receptive Field
One of the most significant advantages of the Wavelet method is its ability to maintain a global receptive field. While ALiBi forces a model to ignore distant tokens to maintain stability, attention maps for the Wavelet method show that it continues to attend to critical "anchor" tokens—such as the beginning of a sentence or the primary subject—regardless of the distance from the current token.
Fluidity of Language
By moving away from the assumption that language is periodic (like a sine wave) and treating it as a non-stationary signal, the Ricker wavelet provides a more natural fit for the structural nuances of human communication and structured data like code (evaluated via CodeParrot).
Limitations and Future Work
The primary challenge for wavelet-based encodings is computational overhead. Relative position calculations are generally more memory-intensive and computationally expensive than absolute position methods. While the researchers implemented optimizations using torch.scatter to mitigate these costs, the method remains more demanding than RoPE for large-scale deployment.
Future research will focus on further optimizing these calculations to reduce the performance gap and testing the wavelet representation on even larger models (70B+) and extreme context lengths exceeding 100,000 tokens. Nevertheless, this work marks a significant step toward truly scale-invariant Transformers.
Summary updated