{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/bp-transformer-modelling-long-range-context","title":"BP-Transformer: Modelling Long-Range Context via Binary Partitioning","arxiv_id":"1911.04070","date":"2019-11-11","proceeding":null,"authors":["Zihao Ye","Qipeng Guo","Quan Gan","Xipeng Qiu","Zheng Zhang"],"abstract":"The Transformer model is widely successful on many natural language processing tasks. However, the quadratic complexity of self-attention limit its application on long text. In this paper, adopting a fine-to-coarse attention mechanism on multi-scale spans via binary partitioning (BP), we propose BP-Transformer (BPT for short). BPT yields $O(k\\cdot n\\log (n/k))$ connections where $k$ is a hyperparameter to control the density of attention. BPT has a good balance between computation complexity and model capacity. A series of experiments on text classification, machine translation and language modeling shows BPT has a superior performance for long text than previous self-attention models. Our code, hyperparameters and CUDA kernels for sparse attention are available in PyTorch.","url_abs":"https://arxiv.org/abs/1911.04070v1","url_pdf":"https://arxiv.org/pdf/1911.04070v1.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"bp-transformer-modelling-long-range-context","repo_url":"https://github.com/yzh119/BPT","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}},{"paper_slug":"bp-transformer-modelling-long-range-context","repo_url":"https://github.com/dmlc/dgl/tree/master/examples/pytorch/transformer","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":0,"framework":"pytorch","reach":null}],"tasks":[{"task_slug":"language-modeling","task_name":"Language Modeling"},{"task_slug":"language-modelling","task_name":"Language Modelling"},{"task_slug":"machine-translation","task_name":"Machine Translation"},{"task_slug":"sentiment-analysis","task_name":"Sentiment Analysis"},{"task_slug":"text-classification","task_name":"Text Classification"},{"task_slug":"translation","task_name":"Translation"},{"task_slug":"text-classification-1","task_name":"text-classification"}],"methods":[{"method_slug":"absolute-position-encodings","method_name":"Absolute Position Encodings"},{"method_slug":"adam","method_name":"Adam"},{"method_slug":"attention","method_name":"Attention"},{"method_slug":"bp-transformer","method_name":"BP-Transformer"},{"method_slug":"bpe","method_name":"BPE"},{"method_slug":"dense-connections","method_name":"Dense Connections"},{"method_slug":"dropout","method_name":"Dropout"},{"method_slug":"graph-self-attention","method_name":"Graph Self-Attention"},{"method_slug":"label-smoothing","method_name":"Label Smoothing"},{"method_slug":"layer-normalization","method_name":"Layer Normalization"},{"method_slug":"linear-layer","method_name":"Linear Layer"},{"method_slug":"multi-head-attention","method_name":"Multi-Head Attention"},{"method_slug":"position-wise-feed-forward-layer","method_name":"Position-Wise Feed-Forward Layer"},{"method_slug":"relu","method_name":"ReLU"},{"method_slug":"residual-connection","method_name":"Residual Connection"},{"method_slug":"softmax","method_name":"Softmax"},{"method_slug":"transformer","method_name":"Transformer"}],"datasets_introduced":[],"methods_introduced":[{"slug":"bp-transformer","name":"BP-Transformer","full_name":"BP-Transformer"}],"results":[{"leaderboard":"/sota/language-modelling-on-text8","task":"Language Modelling","dataset":"Text8","model":"BP-Transformer - 12 Layers","rank_in_archive_order":10,"of":24,"metrics":{"Bit per Character (BPC)":"1.11"},"uses_additional_data":false},{"leaderboard":"/sota/language-modelling-on-enwiki8","task":"Language Modelling","dataset":"enwik8","model":"BP-Transformer (12 layers)","rank_in_archive_order":21,"of":42,"metrics":{"Bit per Character (BPC)":"1.02","Number of params":"38M"},"uses_additional_data":false},{"leaderboard":"/sota/machine-translation-on-iwslt2015-chinese","task":"Machine Translation","dataset":"IWSLT2015 Chinese-English","model":"BP-Transformer","rank_in_archive_order":1,"of":1,"metrics":{"BLEU":"19.84"},"uses_additional_data":false},{"leaderboard":"/sota/sentiment-analysis-on-imdb","task":"Sentiment Analysis","dataset":"IMDb","model":"BP-Transformer + GloVe","rank_in_archive_order":33,"of":49,"metrics":{"Accuracy":"92.12"},"uses_additional_data":false},{"leaderboard":"/sota/sentiment-analysis-on-sst-5-fine-grained","task":"Sentiment Analysis","dataset":"SST-5 Fine-grained classification","model":"BP-Transformer + GloVe","rank_in_archive_order":15,"of":31,"metrics":{"Accuracy":"52.71"},"uses_additional_data":false}],"syntology":{"syntology_url":null,"atlas_url":"https://app.syntology.ai/?focus=1911.04070","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"1911.04070"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/dmlc/dgl/tree/master/examples/pytorch/transformer","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/yzh119/BPT","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"unverified":7},"by_repo_kind":{"official":{"samples":7,"ran":0,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"1887f5eadaadc3aa","entry":"average_model","repo":"yzh119/BPT","repo_kind":"official","path":"utils.py","file_url":"https://github.com/yzh119/BPT/blob/HEAD/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"1887f5eadaadc3aa"}},{"code_sha256_prefix":"18d1d5a8e178b8d3","entry":"masked_mm","repo":"yzh119/BPT","repo_kind":"official","path":"modules/op.py","file_url":"https://github.com/yzh119/BPT/blob/HEAD/modules/op.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"18d1d5a8e178b8d3"}},{"code_sha256_prefix":"6f00f4844df2c25b","entry":"move_to_device","repo":"yzh119/BPT","repo_kind":"official","path":"modules/beam.py","file_url":"https://github.com/yzh119/BPT/blob/HEAD/modules/beam.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"6f00f4844df2c25b"}},{"code_sha256_prefix":"281d17936edd3b56","entry":"sparse_softmax","repo":"yzh119/BPT","repo_kind":"official","path":"modules/op.py","file_url":"https://github.com/yzh119/BPT/blob/HEAD/modules/op.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"281d17936edd3b56"}},{"code_sha256_prefix":"257a29f25914a6ac","entry":"tensor_to_sequence","repo":"yzh119/BPT","repo_kind":"official","path":"utils.py","file_url":"https://github.com/yzh119/BPT/blob/HEAD/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"257a29f25914a6ac"}},{"code_sha256_prefix":"355eda071b2a6ed3","entry":"to_contiguous","repo":"yzh119/BPT","repo_kind":"official","path":"modules/op.py","file_url":"https://github.com/yzh119/BPT/blob/HEAD/modules/op.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"355eda071b2a6ed3"}},{"code_sha256_prefix":"82c86b7826716ef2","entry":"unpack_params","repo":"yzh119/BPT","repo_kind":"official","path":"utils.py","file_url":"https://github.com/yzh119/BPT/blob/HEAD/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"82c86b7826716ef2"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}