Two Stones Hit One Bird: Bilevel Positional Encoding for Better Length Extrapolation
Zhenyu He, Guhao Feng, Shengjie Luo, Kai Yang, Liwei Wang, Jingjing Xu, Zhi Zhang, Hongxia Yang, Di He
TL;DR
This paper introduces Bilevel Positional Encoding (BiPE), which separately handles within-segment (intra-segment) and between-segment (inter-segment) positional information to improve length extrapolation in Transformer models. By applying absolute positional encoding inside segments and relative positional encoding between segments, BiPE achieves greater parameter efficiency and better extrapolation performance, as supported by theory framed around Bi-NFA and extensive experiments across arithmetic reasoning, long-context benchmarks, and normal-length data. BiPE variants, such as BiPE-RoPE and BiPE-ALiBi, demonstrate superior length extrapolation across multimodal tasks and maintain competitive performance on in-distribution tasks. The work suggests a promising direction for leveraging intrinsic data segmentation and opens avenues for hierarchical extensions to further improve extrapolation in longer contexts and other sequence types.
Abstract
In this work, we leverage the intrinsic segmentation of language sequences and design a new positional encoding method called Bilevel Positional Encoding (BiPE). For each position, our BiPE blends an intra-segment encoding and an inter-segment encoding. The intra-segment encoding identifies the locations within a segment and helps the model capture the semantic information therein via absolute positional encoding. The inter-segment encoding specifies the segment index, models the relationships between segments, and aims to improve extrapolation capabilities via relative positional encoding. Theoretical analysis shows this disentanglement of positional information makes learning more effective. The empirical results also show that our BiPE has superior length extrapolation capabilities across a wide range of tasks in diverse text modalities.
