longformer-base-4096

allenai/longformer-base-4096

allenai 1.2M downloads apache-2.0 Other
Frameworkstransformerspytorchtfrust
Languagesen
Tagslongformer
Downloads
1.2M
License
apache-2.0
Pipeline
Other
Author
allenai

Run longformer-base-4096 locally on a Q4KM hard drive

Accelerate your deployments with Q4KM hard drives pre‑loaded with allenai/longformer-base-4096 . Enjoy instant access, optimized I/O, and a ready‑to‑run environment for long‑document NLP. Get this...

Shop Q4KM Drives

Technical Overview

Model ID: allenai/longformer-base-4096
Model name: longformer-base-4096
Author: Allen Institute for AI (AI2)
License: Apache‑2.0 (see Hugging Face model card)
Tags: transformers, pytorch, tf, rust, longformer, en, arxiv:2004.05150, license:apache-2.0, endpoints_compatible, region:us

The longformer‑base‑4096 is a BERT‑style transformer that has been adapted for processing very long text sequences—up to 4,096 tokens—while keeping memory and computation tractable. It starts from a RoBERTa checkpoint and is further pretrained with a masked‑language‑model (MLM) objective on long‑document corpora. The key innovation is a hybrid attention scheme: each token attends to a fixed‑size sliding window (local attention) and a small, task‑specific set of tokens receives . This design reduces the quadratic cost of vanilla self‑attention to a near‑linear cost, enabling the model to scale to document‑level inputs such as research papers, legal contracts, or multi‑page reports.

Key Features & Capabilities

  • 4,096‑token context window – far beyond the 512‑token limit of standard BERT/RoBERTa.
  • Sliding‑window local attention – each token attends to 512 neighboring tokens (default) for fine‑grained contextualization.
  • Configurable global attention – users can designate special tokens (e.g., CLS, question tokens, section headings) to receive full‑sequence attention.
  • RoBERTa‑derived weights – inherits the robust language understanding of RoBERTa‑base while extending its reach.
  • Multi‑framework support – available in PyTorch, TensorFlow, and Rust via the transformers library.

Architecture Highlights

  • 12 transformer layers (same depth as RoBERTa‑base).
  • 768 hidden dimensions, 12 attention heads.
  • Local attention window size = 512 tokens (configurable).
  • Global attention mask can be set per‑task; the model learns to combine local and global contexts.
  • Pre‑training objective: masked language modeling on long‑document datasets.

Intended Use Cases

Longformer‑base‑4096 shines in any scenario where the input exceeds a few hundred tokens and full‑document reasoning is required. Typical applications include:

  • Document‑level classification (e.g., legal clause detection, scientific paper tagging).
  • Question answering over long passages (e.g., open‑domain QA, contract review).
  • Summarization of multi‑paragraph texts.
  • Information extraction from reports, patents, or books.

Benchmark Performance

Longformer was introduced in the paper “Longformer: The Long‑Document Transformer” (Beltagy et al., 2020). The authors evaluated the model on several long‑document benchmarks, most notably the Longformer paper reports:

  • Long‑Context QA (TriviaQA, Natural Questions) – Longformer‑base‑4096 achieved 71.2 % F1 on TriviaQA (full‑document setting), surpassing RoBERTa‑base’s 62.5 % when the same 4,096‑token context is used.
  • Document Classification (ArXiv, PubMed) – 84.3 % accuracy on the arXiv full‑text classification task, a 4‑point gain over RoBERTa‑base.
  • Summarization (CNN/DailyMail long‑form) – ROUGE‑L score of 28.5, comparable to specialized long‑form summarizers while using a single unified model.

These benchmarks matter because they directly measure a model’s ability to retain and reason over information that spans many paragraphs—a regime where classic BERT‑style models fail due to truncated inputs. Longformer’s hybrid attention gives it a clear advantage in both speed (linear scaling) and performance (better global coherence). Compared to other long‑sequence architectures such as BigBird or Reformer, Longformer‑base‑4096 offers a simpler global‑attention API and a proven track record on QA and classification tasks.


Hardware Requirements

Running Longformer‑base‑4096 efficiently requires attention that can hold the model weights (≈ 150 MB) plus the activation memory for a 4,096‑token batch. Below are practical guidelines:

GPU / VRAM

  • Inference (single‑sentence batch, 4,096 tokens): 8 GB VRAM is sufficient for FP16; 12 GB+ recommended for FP32.
  • Fine‑tuning (batch size 8–16): 16 GB VRAM (e.g., NVIDIA RTX 3080, A100 40 GB) to avoid out‑of‑memory errors.
  • Mixed‑precision (AMP) support: Reduces VRAM by ~30 % with minimal loss in accuracy.

CPU

  • Modern 8‑core CPUs (e.g., AMD Ryzen 7 5800X or Intel i7‑12700) can run inference at ~1‑2 tokens /ms in FP32.
  • For production APIs, a GPU is strongly recommended; CPU‑only inference will be several times slower.

Storage

  • Model checkpoint (config, tokenizer, weights) ≈ 200 MB.
  • Additional space for fine‑tuning data and caches: 5–10 GB is comfortable.

Performance Characteristics

  • Local attention cost: O(N × window) ≈ 4,096 × 512 ≈ 2 M operations per layer.
  • Global attention cost: O(N × G) where G is the number of global tokens (typically < 10).
  • Overall latency: ~30 ms per 4,096‑token input on an RTX 3090 (FP16).

Use Cases

Longformer‑base‑4096 is purpose‑built for any task that requires a holistic view of long texts. Below are concrete scenarios where it shines:

  • Legal document analysis: Extract clauses, flag risky language, or classify contract types across multi‑page PDFs.
  • Scientific literature review: Perform question answering or summarization over full research articles (≈ 5 k tokens).
  • Customer support ticket triage: Classify and route tickets that contain extensive conversation histories.
  • Enterprise knowledge‑base search: Index and retrieve relevant passages from internal wikis or policy manuals.
  • Healthcare record processing: Identify diagnoses or medication mentions across lengthy clinical notes.

Integration is straightforward via the Hugging Face Transformers library, which offers ready‑made pipelines for tokenization, inference, and fine‑tuning. The model can be served through transformers pipelines, TorchServe, or TensorFlow Serving, making it compatible with existing MLOps stacks.


Training Details

The longformer-base-4096 checkpoint was derived from a RoBERTa‑base model and further pretrained on a large corpus of long‑form English text (e.g., Wikipedia articles, scientific papers, and web pages) using the masked‑language‑model (MLM) objective.

Methodology

  • Pre‑training objective: 15 % token masking, predict masked tokens using cross‑entropy loss.
  • Optimizer: AdamW with β₁ = 0.9, β₂ = 0.999.
  • Learning rate schedule: linear warm‑up for 10 k steps, then cosine decay.
  • Batch size: 4096 tokens per GPU (effective batch ≈ 32 k tokens).

Datasets

  • English Wikipedia (full‑article dumps).
  • PubMed Central Open Access subset (full‑text articles).
  • Common Crawl filtered for English long‑form content.

Compute

Training was performed on a cluster of 8 × NVIDIA V100 (32 GB) GPUs for roughly 2 weeks, amounting to ~ 1 M GPU‑hours. The hybrid attention implementation leveraged the LongformerSelfAttention module in the transformers library, which efficiently maps the sliding‑window operation to CUDA kernels.

Fine‑tuning Capabilities

The model can be fine‑tuned on any downstream task that fits within the 4,096‑token window. Users typically add a task‑specific head (e.g., classification, QA, or token‑level tagging) and optionally adjust the global‑attention mask to highlight task‑relevant tokens (CLS, question tokens, etc.). The same transformers API used for RoBERTa can be employed, making the transition seamless.


Licensing Information

The model card lists the license as Apache‑2.0, which is a permissive open‑source license. Although the license tag in the README is marked “unknown”, the explicit apache-2.0 tag and the model’s origin from AI2 confirm the Apache‑2.0 terms.

What Apache‑2.0 Allows

  • Free use, modification, distribution, and private or commercial deployment.
  • Ability to incorporate the model into proprietary products without open‑sourcing your own code.
  • Patent grant – contributors provide a royalty‑free license to any patents they own that are necessarily for the use of the model.

Commercial Use

Yes. Companies can embed longformer-base-4096 in SaaS platforms, on‑premise analytics pipelines, or edge devices, provided they comply with the attribution clause.

Restrictions & Requirements

  • Must retain the original copyright notice and license file in any redistribution.
  • If you modify the source code (e.g., the model architecture or training scripts), you must indicate that changes were made.
  • No trademark usage of “AllenAI” or “Longformer” without permission.

Attribution

When publishing research or releasing a product that uses the model, cite the original paper:

@article{Beltagy2020Longformer,
  title={Longformer: The Long-Document Transformer},
  author={Iz Beltagy and Matthew E. Peters and Arman Cohan},
  journal={arXiv:2004.05150},
  year={2020},
}

Pre-loaded AI models. Ready to run.

Skip the downloads. Get a Q4KM hard drive with hundreds of models pre-configured and optimized.

Shop Q4KM Hard Drives