BP-Transformer: Modelling Long-Range Context via Binary Partitioning

Zihao Ye, Qipeng Guo, Quan Gan, Xipeng Qiu, Zheng ZhangarXiv 2019

Abstract

The Transformer model has revolutionized natural language processing, yet its quadratic self-attention complexity remains a significant barrier for long-sequence tasks. We propose the BP-Transformer (BPT), which employs a fine-to-coarse attention mechanism based on binary partitioning. By organizing input sequences into a multi-scale tree, BPT reduces the attention complexity to $O(k \cdot n \log(n/k))$, where $k$ controls attention density. Experiments across text classification, machine translation, and language modeling demonstrate that BPT balances computational efficiency with model capacity, outperforming traditional self-attention models on long-text benchmarks.

Introduction

Standard Transformer architectures utilize a global self-attention mechanism where every token attends to every other token. While powerful, this $O(n^2)$ complexity makes processing long documents—such as legal papers or books—prohibitively expensive in terms of memory and computation. Furthermore, global attention lacks the inductive bias that nearby words often share stronger dependencies than distant ones. To address these limitations, we introduce Binary Partitioning (BP) to create a hierarchical representation that allows for efficient long-range context modeling.

Methods: Binary Partitioning and Hierarchical Attention

The core of BPT is the transformation of a flat sequence into a hierarchical graph structure.

Node Construction and Graph Self-Attention

BPT recursively divides the input sequence into a binary tree. Leaf nodes represent individual tokens, while internal nodes represent "spans" that summarize groups of tokens. For a sequence of length $n$, the tree contains $2n-1$ nodes.

The model employs a Fine-to-Coarse Attention strategy. A token attends to its immediate neighbors at a fine-grained level (individual tokens). As the distance increases, the token attends to higher-level span nodes (coarse-grained summaries) rather than individual distant tokens. This multi-scale approach ensures that the model captures local nuances while maintaining a global context without the quadratic cost.

Comparison of attention patterns in Transformer, Transformer-XL, and BPT.

Structural Inductive Bias

To preserve structural information, BPT utilizes relative positional encodings generalized for tree structures. This allows the model to distinguish between different types of relationships, such as "ancestor," "left-child," or "right-child," providing a stronger inductive bias than the flat positional encodings used in standard Transformers.

Experimental Evaluation

We evaluated BPT on several benchmarks:

  • Text Classification: SST-5 (short) and IMDB (long).
  • Language Modeling: Character-level datasets Enwiki8 and Text8.
  • Machine Translation: IWSLT 2015 (Zh-En) and WMT14 (En-De).

Key Results

BPT demonstrates significant improvements in both performance and efficiency, particularly as sequence lengths grow.

Performance on Long-Range Tasks

On the IMDB dataset, which features long-form reviews, BPT achieved an accuracy of 92.12%, surpassing the vanilla Transformer (89.24%) and the Star-Transformer (90.50%). In language modeling on Enwiki8, BPT reached a Bits-Per-Character (BPC) of 1.02, matching or exceeding the performance of Transformer-XL with fewer parameters.

Efficiency and Scaling

The primary advantage of BPT is its scaling behavior. By moving from $O(n^2)$ to $O(n \log n)$ complexity, BPT maintains a manageable GPU memory footprint even for very long sequences.

BPT achieves a better trade-off between bits per character (BPC) and attention degree compared to Restricted Attention and Sparse Transformer.

As shown in the figure above, BPT consistently achieves lower BPC (better performance) at lower attention degrees compared to other sparse attention variants, effectively pushing the Pareto frontier of efficiency and accuracy.

Conclusion

BP-Transformer addresses the quadratic bottleneck of self-attention by leveraging a hierarchical binary partitioning scheme. By combining fine-grained local attention with coarse-grained global summaries, BPT provides an efficient and effective framework for processing long-range dependencies in natural language. Future work will explore more flexible partitioning strategies, such as incorporating syntactic dependency trees, to further enhance the model's structural awareness.

Summary updated

BibTeX
@misc{ye2019bp,
  author = {Zihao Ye and Qipeng Guo and Quan Gan and Xipeng Qiu and Zheng Zhang},
  title = {{BP-Transformer: Modelling Long-Range Context via Binary Partitioning}},
  year = {2019},
  eprint = {1911.04070},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1911.04070},
}
Figure