[Paper Review] KERPLE: Kernelized Relative Positional Embedding for Length Extrapolation
KERPLE introduces a kernelized relative positional embedding framework that enables length extrapolation in Transformers by leveraging conditionally positive definite (CPD) kernels, transforming them into positive definite (PD) kernels via constant offsets absorbed during Softmax normalization. The method achieves state-of-the-art extrapolation performance, particularly with the logarithmic kernel variant, on large language modeling datasets like OpenWebText2, GitHub, and ArXiv.
Relative positional embeddings (RPE) have received considerable attention since RPEs effectively model the relative distance among tokens and enable length extrapolation. We propose KERPLE, a framework that generalizes relative position embedding for extrapolation by kernelizing positional differences. We achieve this goal using conditionally positive definite (CPD) kernels, a class of functions known for generalizing distance metrics. To maintain the inner product interpretation of self-attention, we show that a CPD kernel can be transformed into a PD kernel by adding a constant offset. This offset is implicitly absorbed in the Softmax normalization during self-attention. The diversity of CPD kernels allows us to derive various RPEs that enable length extrapolation in a principled way. Experiments demonstrate that the logarithmic variant achieves excellent extrapolation performance on three large language modeling datasets. Our implementation and pretrained checkpoints are released at https://github.com/chijames/KERPLE.git.
Motivation & Objective
- To address the challenge of length extrapolation in Transformer models, where models must generalize to sequence lengths beyond their training length L.
- To overcome the limitations of existing relative positional embeddings (RPEs) that fail to generalize well beyond training lengths.
- To develop a principled framework for designing RPEs that support extrapolation using the mathematical properties of conditionally positive definite (CPD) kernels.
- To demonstrate that learnable CPD kernels can adapt to dataset-specific long-range dependencies, outperforming fixed-parameter methods like ALiBi.
- To provide a unified framework that generalizes existing methods such as ALiBi and enables systematic exploration of RPEs with strong extrapolation capacity.
Proposed method
- The framework kernelizes relative positional differences using conditionally positive definite (CPD) kernels, which generalize distance metrics and support extrapolation.
- A CPD kernel is transformed into a positive definite (PD) kernel by adding a constant offset, which is implicitly absorbed during Softmax normalization in self-attention.
- The method uses a learnable parameterization of the kernel function across attention heads, enabling adaptation to dataset-specific long-range dependencies.
- The framework is applied to causal language modeling, with attention scores computed as the sum of query-key dot products and kernelized relative positional biases.
- The kernel function is designed to decay slowly (e.g., logarithmic) to maintain attention on distant tokens during inference on longer sequences.
- Experiments use the GPT-NeoX codebase for fair comparison, training on short sequences (length 3) and evaluating on long sequences (up to 16384 tokens).
Experimental results
Research questions
- RQ1Can conditionally positive definite (CPD) kernels be used to design relative positional embeddings that support length extrapolation in Transformers?
- RQ2How does the choice of kernel function (e.g., logarithmic vs. power-law) affect the model’s ability to attend to long-range dependencies during inference?
- RQ3Can learnable parameters in the kernel function adapt to dataset-specific long-range dependencies better than fixed-parameter methods like ALiBi?
- RQ4To what extent does the kernelized RPE framework generalize existing methods such as ALiBi?
- RQ5How does the effective length of attention, defined by the kernel’s decay rate, correlate with model performance on long-context tasks?
Key findings
- The logarithmic variant of KERPLE achieves the best length extrapolation performance across three large language modeling datasets: OpenWebText2, GitHub, and ArXiv.
- KERPLE-log maintains low perplexity at sequence length 16384, outperforming both window attention (window@512) and ALiBi, which show higher perplexity.
- The model trained with KERPLE-log exhibits a slower decay in attention to distant tokens, indicating stronger long-range dependency modeling.
- The effective length of attention, defined as the distance at which the kernel bias drops below -2, is significantly longer for the logarithmic kernel compared to the power-law variant.
- The cumulative count of heads with effective lengths ≤ |m−n| shows that KERPLE-log maintains attention on distant tokens over a wider range of distances than other methods.
- The method generalizes ALiBi as a special case, with ALiBi corresponding to a linear CPD kernel with fixed parameters, while KERPLE allows learnable, dataset-adaptive parameters.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.