Papers › Longformer: The Long-Document Transformer

Longformer: The Long-Document Transformer

10 Apr 2020arXiv:2004.05150archive 2025-07-28

Iz Beltagy, Matthew E. Peters, Arman Cohan

Transformer-based models are unable to process long sequences due to their self-attention operation, which scales quadratically with the sequence length. To address this limitation, we introduce the Longformer with an attention mechanism that scales linearly with sequence length, making it easy to process documents of thousands of tokens or longer. Longformer's attention mechanism is a drop-in replacement for the standard self-attention and combines a local windowed attention with a task motivated global attention. Following prior work on long-sequence transformers, we evaluate Longformer on character-level language modeling and achieve state-of-the-art results on text8 and enwik8. In contrast to most prior work, we also pretrain Longformer and finetune it on a variety of downstream tasks. Our pretrained Longformer consistently outperforms RoBERTa on long document tasks and sets new state-of-the-art results on WikiHop and TriviaQA. We finally introduce the Longformer-Encoder-Decoder (LED), a Longformer variant for supporting long document generative sequence-to-sequence tasks, and demonstrate its effectiveness on the arXiv summarization dataset.

PaperPDFCodeCode Syntology ran

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2004.05150")

Code

Syntology Ran 15 of 35 code samples harvested from 7 repositories linked to this paper; 20 have no recorded run. Of those that ran: 1 ran · honoured contract; 1 ran · violated contract; 8 ran · our draft was wrong; 5 ran with no contract checked.

By repository: official repository: 11 samples from 1 repository, 9 ran; community (archive-listed): 24 samples from 6 repositories, 6 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

22 repositories listed; official and paper-mentioned ones first.

allenai/longformer officialmentioned in papermentioned on GitHubpytorch report
Phrase-in-Context/eval mentioned on GitHubpytorch report
a-rios/ats-models mentioned on GitHubpytorchApache-2.0 report
facebookresearch/xformers mentioned on GitHubpytorch report
han-shi/SparseBERT mentioned on GitHubpytorch report
huggingface/transformers mentioned on GitHubpytorch report
jaketae/pytorch-malware-detection mentioned on GitHubpytorchMIT report
kit-mrt/red-motion mentioned on GitHubpytorch report
kit-mrt/road-barlow-twins mentioned on GitHubpytorch report
lucashueda/long_sentence_transformer mentioned on GitHubpytorchLGPL-3.0 report
microsoft/dialoglm mentioned on GitHubpytorchMIT report
mim-solutions/bert_for_longer_texts mentioned on GitHubpytorch report
mim-solutions/roberta_for_longer_texts mentioned on GitHubpytorchNOASSERTION report
mistralai/mistral-src mentioned on GitHubpytorchApache-2.0 report
naver-ai/simseek mentioned on GitHubpytorchNOASSERTION report
schenliu/longformer-chinese mentioned on GitHubpytorch report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

35 samples harvested; 15 ran; 1 honoured the contract we drafted; 20 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

1ran · honoured contract
1ran · violated contract
8ran · our draft was wrong
5ran
20unverified

Licence: 5 of the 35 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from 7 repositories linked to this paper, official or community; each sample names its own and says which. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: 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. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

_chunk allenai/longformer/longformer/longformer.py official repository ran · our draft was wrong fingerprinted Apache-2.0 (permissive) · b3689e24866300ad · report
_get_invalid_locations_mask allenai/longformer/longformer/longformer.py official repository ran · our draft was wrong Apache-2.0 (permissive) · 215ac6dd58d2d468 · report
_get_invalid_locations_mask_fixed_dilation allenai/longformer/longformer/longformer.py official repository ran · honoured contract fingerprinted Apache-2.0 (permissive) · 1a6f3f01a17a0b4c · report
_skew allenai/longformer/longformer/longformer.py official repository ran · our draft was wrong Apache-2.0 (permissive) · 54c6929644249d31 · report
_skew2 allenai/longformer/longformer/longformer.py official repository ran · our draft was wrong fingerprinted Apache-2.0 (permissive) · 755bf82d9fe23d4b · report
sliding_chunks_matmul_pv allenai/longformer/longformer/longformer.py official repository ran · our draft was wrong Apache-2.0 (permissive) · 4261f70837b75c76 · report
sliding_chunks_matmul_qk allenai/longformer/longformer/longformer.py official repository ran · our draft was wrong fingerprinted Apache-2.0 (permissive) · 1b7525edcd068b10 · report
sliding_chunks_no_overlap_matmul_pv allenai/longformer/longformer/longformer.py official repository ran · our draft was wrong Apache-2.0 (permissive) · 1273524f034ce151 · report
sliding_chunks_no_overlap_matmul_qk allenai/longformer/longformer/longformer.py official repository ran · our draft was wrong fingerprinted Apache-2.0 (permissive) · 3d4e46172b26669c · report
LongformerSelfAttention allenai/longformer/longformer/longformer.py official repository unverified Apache-2.0 (permissive) · c1eb691dab111921 · report
mask_invalid_locations allenai/longformer/longformer/longformer.py official repository unverified Apache-2.0 (permissive) · bec22b3675334717 · report
FeedForward AIResearchHub/transformergallery/transformer/longformer.py community (archive-listed) ran · metamorphic tier: deterministic MIT (permissive) · 2893a3bddf619d82 · report
LongformerClassificationHead amazon-science/efficient-longdoc-classification/src/models.py community (archive-listed) ran · metamorphic tier: invariant Apache-2.0 (permissive) · e71d9c8a8cff7aa3 · report
PositionalEncoding AIResearchHub/transformergallery/transformer/longformer.py community (archive-listed) ran · metamorphic tier: deterministic fingerprinted MIT (permissive) · 6c89fcd0771cd674 · report
TokenEmbedding AIResearchHub/transformergallery/transformer/longformer.py community (archive-listed) ran · metamorphic tier: deterministic MIT (permissive) · 0840d53a3e87bbd0 · report
TransformerEmbedding AIResearchHub/transformergallery/transformer/longformer.py community (archive-listed) ran · metamorphic tier: deterministic MIT (permissive) · 4d2255c33fd872a1 · report
local_1d_pattern facebookresearch/xformers/xformers/components/attention/attention_patterns.py community (archive-listed) ran · violated contract fingerprinted licence not identified · pointer only · ca468da77bd87495 · report
Longformer AIResearchHub/transformergallery/transformer/longformer.py community (archive-listed) unverified MIT (permissive) · e23d4d61b776fd56 · report
LongformerClass amazon-science/efficient-longdoc-classification/src/models.py community (archive-listed) unverified Apache-2.0 (permissive) · 083425b2586f0566 · report
LongformerLayer AIResearchHub/transformergallery/transformer/longformer.py community (archive-listed) unverified MIT (permissive) · 56f78e8f5e291c8d · report
LongformerSelfAttention schenliu/longformer-chinese/longformer/longformer.py community (archive-listed) unverified no licence file found · pointer only · 3b707d0823eee4d2 · report
_generate_nd_grid facebookresearch/xformers/xformers/components/attention/attention_patterns.py community (archive-listed) unverified licence not identified · pointer only · cc7b7bd19f2134ba · report
average_tensors a-rios/ats-models/ats_models/average.py community (archive-listed) unverified Apache-2.0 (permissive) · 62964c608dfd3d2c · report
collate_fn jaketae/pytorch-malware-detection/src/deep_malware_detection/dataset.py community (archive-listed) unverified MIT (permissive) · be39561477eedbab · report
construct_href jaketae/pytorch-malware-detection/src/bin/malshare.py community (archive-listed) unverified MIT (permissive) · 1d6037ddb5464048 · report
count_params jaketae/pytorch-malware-detection/src/deep_malware_detection/utils.py community (archive-listed) unverified MIT (permissive) · 4f4f44d30b573fa8 · report
create_long_model a-rios/ats-models/ats_models/convert_bart2long.py community (archive-listed) unverified Apache-2.0 (permissive) · 8a1120aa9e015927 · report
get_accuracy jaketae/pytorch-malware-detection/src/deep_malware_detection/utils.py community (archive-listed) unverified MIT (permissive) · e910798b9dfc1967 · report
label_smoothed_nll_loss a-rios/ats-models/ats_models/metrics.py community (archive-listed) unverified Apache-2.0 (permissive) · 9c78ceb4210479cf · report
local_nd_distance facebookresearch/xformers/xformers/components/attention/attention_patterns.py community (archive-listed) unverified licence not identified · pointer only · 69ca0d84582f00bd · report
local_nd_pattern facebookresearch/xformers/xformers/components/attention/attention_patterns.py community (archive-listed) unverified licence not identified · pointer only · 2a87d1deca0f2b1a · report
pad_sequence jaketae/pytorch-malware-detection/src/deep_malware_detection/dataset.py community (archive-listed) unverified MIT (permissive) · 337700a5796189df · report
predict jaketae/pytorch-malware-detection/src/deep_malware_detection/utils.py community (archive-listed) unverified MIT (permissive) · e566c3f105753aa6 · report
remove_special_tokens a-rios/ats-models/ats_models/finetune_mbart.py community (archive-listed) unverified Apache-2.0 (permissive) · bce6838014c76d1e · report
train_val_test_split jaketae/pytorch-malware-detection/src/deep_malware_detection/dataset.py community (archive-listed) unverified MIT (permissive) · e71dea05795c03bf · report

Tasks

DecoderLanguage ModelingLanguage ModellingQuestion AnsweringTriviaQA

Results from the paper archive 2025-07-28

TaskDatasetModelMetricValueRank at snapshotLeaderboardReport
Language Modelling Hutter Prize Longformer Large Bit per Character (BPC) 0.99 #5 of 18 Archive leaderboard report
Language Modelling Hutter Prize Longformer Large Number of params 102M #5 of 18 Archive leaderboard report
Language Modelling Hutter Prize Longformer Small Bit per Character (BPC) 1.00 #6 of 18 Archive leaderboard report
Language Modelling Hutter Prize Longformer Small Number of params 41M #6 of 18 Archive leaderboard report
Language Modelling enwik8 Longformer (30 layers, h=512) Bit per Character (BPC) 0.99 #13 of 42 Archive leaderboard report
Language Modelling enwik8 Longformer (30 layers, h=512) Number of params 102M #13 of 42 Archive leaderboard report
Language Modelling enwik8 Longformer (12 layers, h=512) Bit per Character (BPC) 1.00 #18 of 42 Archive leaderboard report
Language Modelling enwik8 Longformer (12 layers, h=512) Number of params 41M #18 of 42 Archive leaderboard report
Question Answering WikiHop Longformer-large Test 81.9 #2 of 9 Archive leaderboard report

Ranks are positions in the archive's leaderboards as they stood at the 2025-07-28 snapshot. Results published since then are not among these rows, so a rank here is not a current standing.

Methods

Introduced by this paper: Longformer

AdamWAttentionAttention DropoutDense ConnectionsDropoutLayer NormalizationLinear LayerLinear Warmup With Linear DecayLongformerMulti-Head AttentionResidual ConnectionSoftmaxWeight DecayWordPiece

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections