TL;DR
This paper introduces KL-TRANSFORMER, a novel framework that learns the kernel function within Transformer models. By learning the spectral distribution of the kernel, KL-TRANSFORMER achieves linear time and space complexity, matching the performance of existing efficient Transformer architectures while offering greater flexibility.
What Problem Does This Paper Address?
Transformers have revolutionized NLP and other fields, but their self-attention mechanism has a quadratic time and memory complexity with respect to sequence length. This limits their application to long sequences. While many efficient Transformer variants exist, they often rely on hand-picked, fixed kernel functions. This paper hypothesizes that the choice of kernel significantly impacts performance and proposes a data-driven approach to learn the kernel, aiming to bridge the performance gap between fixed-kernel efficient Transformers and the original quadratic Transformer.
Methods
The core of KL-TRANSFORMER is learning the kernel's spectral distribution. This is achieved by approximating the Transformer kernel as a dot product of spectral feature maps. The authors explore several methods for learning this spectral distribution:
- GMM-RKS (Gaussian Mixture Model - Random Kitchen Sinks): Models the spectral distribution using a Gaussian Mixture Model, allowing for a learnable kernel.
- FASTFOOD-RKS: An optimization of GMM-RKS that uses Hadamard matrices to speed up computation, achieving log-linear time complexity with respect to the number of samples.
- GENERATIVE-RKS: Employs deep generative models (DGMs) to learn a more flexible spectral distribution, moving beyond the limitations of GMMs.
- Positive Random Features (PRF): Leverages a specific type of random feature map that has been shown to provide better approximations for Gaussian and Softmax kernels, aiming for improved accuracy and strictly non-negative kernel estimates.
These methods are integrated into the Transformer architecture, allowing the kernel to be learned end-to-end alongside other model parameters.
Datasets
The authors evaluate their KL-TRANSFORMER architectures on several benchmarks:
- Long Range Arena (LRA): A diverse benchmark for long-context scenarios, including tasks like Text (sentiment prediction), Retrieval (document similarity), and ListOps (pre-order arithmetic calculations).
- GLUE benchmark: A collection of tasks for evaluating language understanding systems, typically involving short sequences (one or two sentences).
- Synthetic dataset: Used to specifically test the models' performance on sparse data.
- Image dataset (CIFAR10): Used for image classification by flattening images into sequences.
Key Insights and Ideas
- Kernel learning is crucial: The paper strongly suggests that the performance of efficient Transformers is significantly influenced by the choice of kernel, and learning this kernel from data can lead to substantial improvements.
- Bridging the performance gap: KL-TRANSFORMERs demonstrate that it's possible to achieve linear complexity without sacrificing performance, effectively closing the gap between efficient but potentially less accurate models and the original Transformer.
- Flexibility of learned kernels: By learning the kernel, KL-TRANSFORMERs can adapt to specific datasets and tasks, offering a more tailored and potentially more powerful attention mechanism than fixed-kernel approaches.
- PRF vs. RKS: Positive Random Features (PRF) generally outperform Random Kitchen Sinks (RKS) in terms of accuracy, especially when multiple inference steps are used. However, RKS might be preferred for consistency or on less sparse tasks.
Key Results
- Competitive performance: KL-TRANSFORMER variants achieve performance comparable to, and in some cases exceeding, existing efficient Transformer architectures on LRA tasks. For example, FASTFOOD-PRF is highlighted as the best-performing model on average for LRA.
- Linear scaling: All KL-TRANSFORMER models exhibit linear scaling of memory consumption with sequence length, a significant improvement over the quadratic scaling of standard Transformers.
- Short sequence performance: On GLUE tasks, KL-TRANSFORMERs perform on par with Softmax Transformers, demonstrating their effectiveness even when long-context capabilities are not strictly necessary.
- Variance control: The learned kernels can control variance, and PRF-based models, especially those with Generator or FastFood components, show reduced variance.
- Turing completeness: The paper proves that GMM-RKS and GMM-PRF Transformers with positional embeddings are Turing complete, suggesting they possess significant expressive power.
Limitations and Future Work
- Computational complexity of GMM-RKS/GENERATIVE-RKS: While linear in sequence length, these models can have quadratic complexity in the query size ($d_q$), which FASTFOOD and GMM-PRF address.
- Sampling frequency: The paper notes that sampling frequency for $\Omega$ is a critical hyperparameter that affects both speed and bias.
- Generative models' parameter count: While flexible, DGMs can increase the number of parameters, though sharing the generator across heads mitigates this.
- Future work: The authors suggest exploring which models are best suited for different scenarios (e.g., PRF for accuracy, RKS for consistency) and further investigating the trade-offs between accuracy, efficiency, and sparsity. They also hint at the potential for further improvements by combining different kernel learning techniques.
Summary updated