FourierQK: Spectral Preprocessing of Query-Key Projections Improves Transformer Attention
Summary
FourierQK introduces a novel spectral preprocessing method that significantly improves Transformer attention on character-level language modeling. This technique applies FFT-based spectral preprocessing to learned query-key (Q/K) projections. On TinyShakespeare, a fixed random spectral filter achieved a validation loss of 1.031 (Delta=+0.443), while a single learned frequency at paragraph scale reached 0.608 (Delta=+0.867). Four learned frequencies, spanning paragraph to word scales (49, 27, 10, 6 tokens/cycle), yielded a validation loss of 0.309 (Delta=+1.166), representing a 79% reduction over standard dot-product attention. This gain is attributed to global frequency-domain mixing, as random orthogonal and non-orthogonal projections showed no improvement. Unlike FNet (Lee-Thorp et al., 2021), FourierQK preserves the full attention score structure, applying spectral preprocessing only to Q/K projections. The bilateral FFT kernel is structurally non-causal, coupling every position to future tokens.
Key takeaway
For Machine Learning Engineers optimizing Transformer architectures, FourierQK presents a compelling method to boost character-level language model performance. By integrating spectral preprocessing into query-key projections, you can achieve substantial reductions in validation loss, as demonstrated on TinyShakespeare. You should investigate this approach for models where non-causal attention is acceptable, especially for tasks requiring global context, and explore learning multi-scale frequencies for optimal results.
Key insights
Spectral preprocessing of query-key projections significantly enhances Transformer attention by leveraging global frequency-domain mixing.
Principles
- Global frequency-domain mixing improves Transformer attention.
- Multi-scale frequency learning optimizes attention performance.
- Bilateral FFT kernels are inherently non-causal in attention.
Method
Apply FFT-based spectral preprocessing to learned query-key projections within Transformer attention. Learn optimal frequencies across multiple scales (e.g., paragraph to word) to enhance character-level language modeling.
In practice
- Implement FFT-based Q/K preprocessing in Transformers.
- Experiment with learned multi-scale frequencies for tasks.
- Consider non-causal implications for sequence generation.
Topics
- Transformers
- Attention Mechanisms
- Spectral Preprocessing
- Fourier Transform
- Language Modeling
- Character-level NLP
Best for: Research Scientist, AI Scientist, Machine Learning Engineer, NLP Engineer
Related on AIssential
Editorial summary, takeaway, and curation by AIssential. Original article published by Machine Learning.