加载中…
加载中…
A 161.84M-parameter Longformer Encoder-Decoder (LED) fine-tuned on SCROLLS QASper for full-paper scientific Question Answering.
A Longformer Encoder-Decoder (
allenai/led-base-16384) Seq2Seq model fine-tuned on SCROLLS QASper across 16,384 tokens context, achieving 35.30% Held-Out Test SCROLLS F1 on 1,399 unique questions (surpassing the 24.2% LED-base baseline reported in the SCROLLS paper).
4-Beam Search) across all 1,399 test questions:bfloat16 single-shard checkpoint (model.safetensors, 308 MB), Dynamic Token-Budgeted Batching (24,576 tokens/batch), and Gradient Checkpointing capping peak VRAM at 10.25 GB / 39.49 GB on 1× NVIDIA A100.Run long-context scientific QA up to 16,384 tokens with 🤗 Transformers (assign global_attention_mask = 1 to <s> and all question tokens before \n\n, matching training):
import torch
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
repo = "GiangSon-5/led-base-16384-scrolls-qasper"
tokenizer = AutoTokenizer.from_pretrained(repo)
dtype = torch.bfloat16 if torch.cuda.is_available() and torch.cuda.is_bf16_supported() else torch.float32
model = AutoModelForSeq2SeqLM.from_pretrained(repo, dtype=dtype)
device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device).eval()
question = "What attention mechanism allows Longformer to process long documents linearly?"
paper_context = """
Transformer-based models suffer from quadratic O(N^2) self-attention complexity. To address this,
Longformer introduces a sliding window local attention pattern combined with global attention on
selected tokens, achieving linear O(N) scaling across 16,384 tokens.
"""
prompt = f"{question}\n\n{paper_context.strip()}"
sep_idx = prompt.find("\n\n")
enc = tokenizer(prompt, max_length=16384, truncation=True, return_offsets_mapping=True, return_tensors="pt")
offsets = enc.pop("offset_mapping")[0].tolist()
# Set global attention on <s> and question tokens
global_attention_mask = torch.zeros_like(enc["input_ids"])
global_attention_mask[0, 0] = 1
for idx, (off_s, off_e) in enumerate(offsets[1:], start=1):
if off_s < off_e and off_s < sep_idx:
global_attention_mask[0, idx] = 1
with torch.no_grad():
generated_ids = model.generate(
input_ids=enc["input_ids"].to(device),
attention_mask=enc["attention_mask"].to(device),
global_attention_mask=global_attention_mask.to(device),
max_new_tokens=128,
num_beams=4,
no_repeat_ngram_size=3,
length_penalty=1.0,
early_stopping=True,
)
print("Answer:", tokenizer.decode(generated_ids[0], skip_special_tokens=True).strip())
Empirical predictions from the standalone reloaded bfloat16 checkpoint across representative Held-Out Test questions (4-Beam Search):
Question (tau/scrolls Test) |
Model Prediction | Gold Reference | F1 |
|---|---|---|---|
| what chinese dialects are explored? | Ningxia, Hefei, Sichuan, Shanxi, Changsha, Hebei, Nanchang, Shanghai, Kekka and Fujian | Ningxia, Hefei, Sichuan, Shanxi, Changsha, Hebei, Nanchang, Shanghai, Kekka and Fujian | 100% |
| what preprocessing method is introduced? | we preprocess the data by removing URLs and pictures, also (2) by filtering tweets which have candidates' name | Tweets without candidate names are removed, URLs and pictures are removed from the tweets that remain | 53.3% |
| Does the training of ESuLMo take longer compared to ELMo? | Unanswerable | Unanswerable | 100% |
| Do they report the annotation agreement? | No | Yes | 0% |
Extracted verbatim from serialized config.json and tokenizer_config.json:
| Specification | Value | Architecture Details |
|---|---|---|
| Model Type | LEDForConditionalGeneration |
Seq2Seq Encoder-Decoder with linear sparse attention |
| Total Parameters | 161,844,480 (~161.84M) | Full-parameter fine-tuning (model.safetensors: 308.82 MB) |
| Layers (Encoder / Decoder) | 6 Blocks / 6 Blocks | 12 Transformer blocks total |
| Attention Heads | 12 Heads / layer | d_model = 768 (64 dimension / head) |
| Feed-Forward Dimension (FFN) | 3,072 | Intermediate representation (activation = gelu) |
| Max Encoder Context Length | 16,384 Tokens | Unclipped full-paper retention up to 16k tokens |
| Max Decoder Generation Length | 1,024 Tokens (128 eval) |
Covers multi-sentence scientific explanations |
Sliding Window Size (w) |
1,024 Tokens per layer | Local attention complexity $O(N \times w)$ |
| Global Attention Pattern | Question-Anchored (Mask = 1) |
Assigned to <s> and query tokens (mean ~11.5 tokens) |
| Vocabulary & Tokenizer | 50,265 Tokens | Byte-level BPE (RobertaTokenizer), weight_tying = True |
tau/scrolls (qasper), covering 2,567 train pairs (2,490 unique IDs), 984 validation, and 1,399 held-out test unique questions.Train ∩ Val ∩ Test = ∅) and exact prompt deduplication.return_offsets_mapping=True to accurately align the \n\n boundary with BPE tokens, anchoring bidirectional global attention to the question.pad_to_multiple_of = 1024) for optimal Ampere Tensor Core execution, with in-memory caching across shared paper contexts.| Hyperparameter | Value | Technical Nuance & Optimization |
|---|---|---|
| Compute Hardware | 1× NVIDIA A100-SXM4 (40GB) | Pure training runtime: 169.95 min (10,197.28s) • Pipeline: 194.33 min |
| Precision Stack | Native bfloat16 + TF32 |
allow_tf32 = True for Tensor Core acceleration |
| Memory Optimization | Gradient Checkpointing | use_cache = False during training; peak VRAM capped at 10.25 GB / 39.49 GB |
| Dynamic Micro-Batching | TokenBudgetTrainPlanner |
Token budget capped at 24,576 tokens/micro-batch (max_micro_batch = 6) |
| Gradient Accumulation | Sample-Weighted Accumulation | Dynamically normalizes gradients by micro-batch sample count to target effective batch size = 16 |
| Optimizer | adamw_torch_fused |
β₁ = 0.9, β₂ = 0.98, ε = 1e-6, grad clipping 1.0. Weight decay (0.01) filtered from bias and LayerNorm |
| Learning Rate Schedule | Linear Warmup + Decay | Peak LR 3e-5 with 10% warmup (176 / 1,764 updates) over 12 Epochs |
| Convergence Criterion | Task-Native Early Stopping | Checkpointed on true generative 2-beam Validation SCROLLS F1 (patience = 3) |
Evaluated using official SCROLLS multi-reference scoring (metric_max_over_ground_truths) with 4-Beam Search:
| Split | Questions | Beam Search | SCROLLS F1 | Exact Match (EM) |
|---|---|---|---|---|
| Zero-Shot Test Baseline | 1,399 | 1 Beam | 4.78% | 0.00% |
| Validation Split | 984 | 4 Beams | 29.91% | 15.14% |
| Held-Out Test Split (SOTA) | 1,399 | 4 Beams | 35.30% | 19.94% |
Official SCROLLS Paper (EMNLP 2022) LED-base reference baseline: 24.2% F1.
tau/scrolls (qasper). Performance on non-scientific, conversational, clinical, legal, or multilingual documents is not evaluated.allenai/led-base-16384).