Downloads · 30 days
1.5K
78% of all-time downloads
vllm-sr/modernbert-base-32k
modernbert-base-32k is a fill-mask model from vllm-sr. Use it when you need the model to fill a missing word. It is set up for transformers. The card lists the license as apache-2.0.
A long-context extension of ModernBERT-base fine-tuned for 32K token context length using YaRN (Yet another RoPE extensioN) scaling.
Downloads · 30 days
1.5K
78% of all-time downloads
All-time downloads
1.9K
Public
Parameters
150M
299 MB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors299 MB · 99%
How the weights are stored.
BF16150M · 100%
From the Hugging Face model README
A long-context extension of ModernBERT-base fine-tuned for 32K token context length using YaRN (Yet another RoPE extensioN) scaling.
This model extends the original ModernBERT-base from 8,192 tokens to 32,768 tokens context length while preserving the base model's capabilities. It was fine-tuned using specialized techniques to maintain long-range retrieval performance:
| Property | Value |
|---|---|
| Parameters | 149M |
| Context Length | 32,768 tokens |
| Hidden Size | 768 |
| Attention Heads | 12 |
| Layers | 22 |
| Vocabulary | 50,368 |
| Architecture | ModernBERT (RoPE + Sliding Window + Global Attention) |
learning_rate: 1e-5
lr_scheduler: constant_with_warmup
warmup_ratio: 0.1
epochs: 1
batch_size: 6
gradient_accumulation: 1
precision: bf16
max_length: 32768
# RoPE Scaling
rope_scaling_type: yarn
rope_scaling_factor: 4.0
# Retrieval Masking
mlm_probability: 0.30
retrieval_probability: 0.10
min_distance_for_retrieval: 512
# EWC Regularization
ewc_lambda: 1000.0
ewc_samples: 200
| Metric | This Model | Base ModernBERT |
|---|---|---|
| Basic MLM Accuracy | 100% | 100% |
| Perplexity @ 32K | 1.00 | 1.00 |
| Passkey Retrieval @ 512 | 60% | 50% |
| Passkey Retrieval @ 1K | 50% | 50% |
| Long-Range Coreference | 100% | 100% |
| Position Accuracy (early) | 90% | 85% |
| Position Accuracy (late) | 71% | 64% |
| Repeated Info Consistency | 100% | 100% |
| Distance | Accuracy |
|---|---|
| 64 tokens | 80% |
| 128 tokens | 60% |
| 256 tokens | 73% |
| 512 tokens | 27% |
| 1024 tokens | 40% |
| 2048 tokens | 47% |
| 4096 tokens | 53% |
| 8192 tokens | 20% |
| Context | Perplexity |
|---|---|
| 512 | 1.84 |
| 1024 | 1.29 |
| 2048 | 1.11 |
| 4096 | 1.02 |
| 8192 | 1.00 |
| 16384 | 1.00 |
| 24576 | 1.00 |
| 32768 | 1.00 |
from transformers import AutoModelForMaskedLM, AutoTokenizer
model = AutoModelForMaskedLM.from_pretrained("vllm-sr/modernbert-base-32k")
tokenizer = AutoTokenizer.from_pretrained("vllm-sr/modernbert-base-32k")
text = "The capital of France is [MASK]."
inputs = tokenizer(text, return_tensors="pt")
outputs = model(**inputs)
# Get predictions
mask_idx = (inputs.input_ids == tokenizer.mask_token_id).nonzero(as_tuple=True)[1]
logits = outputs.logits[0, mask_idx, :]
top_tokens = logits.topk(5).indices[0]
print([tokenizer.decode(t) for t in top_tokens])
# ['Paris', 'Lyon', 'Nancy', ...]
# For sequences longer than 8192 tokens, YaRN scaling is automatically applied
long_text = "..." * 10000 # Very long document
inputs = tokenizer(
long_text,
return_tensors="pt",
max_length=32768,
truncation=True
)
outputs = model(**inputs)
from transformers import AutoModel
model = AutoModel.from_pretrained("vllm-sr/modernbert-base-32k")
inputs = tokenizer(text, return_tensors="pt")
outputs = model(**inputs)
embeddings = outputs.last_hidden_state # [batch, seq_len, 768]
# Mean pooling for sentence embedding
attention_mask = inputs["attention_mask"]
masked_embeddings = embeddings * attention_mask.unsqueeze(-1)
sentence_embedding = masked_embeddings.sum(1) / attention_mask.sum(1, keepdim=True)
Passkey Retrieval at Long Distances: Like the base model, this model struggles with needle-in-haystack retrieval beyond ~1K tokens. This is a fundamental limitation of MLM architectures, not the fine-tuning.
Context Utilization: At very long contexts (16K+), the model may not always benefit from additional context for MLM predictions. This is expected behavior for encoder-only models.
Memory Requirements: Processing 32K tokens requires significant GPU memory (~16GB+ for inference).
Domain: Trained primarily on web text; may not generalize well to specialized domains without additional fine-tuning.
This model uses several techniques to preserve long-range capabilities during fine-tuning:
Extends positional embeddings from 8K to 32K using Yet another RoPE extensioN with:
Custom MLM objective that creates explicit long-range dependencies:
Prevents catastrophic forgetting by:
If you use this model, please cite:
@misc{modernbert-32k,
title={ModernBERT-base-32K: Long-Context Extension of ModernBERT},
author={LLM Semantic Router},
year={2026},
url={https://huggingface.co/vllm-sr/modernbert-base-32k}
}
Also cite the original ModernBERT paper:
@article{modernbert2024,
title={Smarter, Better, Faster, Longer: A Modern Bidirectional Encoder for Fast, Memory Efficient, and Long Context Finetuning and Inference},
author={Warner, Benjamin and Chaffin, Antoine and Geiger, Benjamin and Werra, Leandro von and Tunstall, Lewis and Bartolo, Max and Thrush, Tristan},
journal={arXiv preprint},
year={2024}
}
Apache 2.0 (same as base model)