ModernBERT-base-32K
A long-context extension of ModernBERT-base fine-tuned for 32K token context length using YaRN (Yet another RoPE extensioN) scaling.
Model Description
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:
- YaRN RoPE Scaling: Factor of 4.0x to extend positional embeddings
- Retrieval-Aware Masking: Custom MLM objective that encourages long-range token dependencies
- Elastic Weight Consolidation (EWC): Regularization to prevent catastrophic forgetting
- Conservative Learning Rate: 1e-5 with constant warmup schedule
Model Details
Training
Dataset
- Source: Leooyii/Slimpajama_downsample_32k_1B (subset)
- Samples: ~1B tokens of long-form text (β₯32K tokens per document)
- Preprocessing: Concatenated documents with proper sequence boundaries
Hyperparameters
Training Infrastructure
- Hardware: AMD MI300X GPU (192GB HBM3)
- Framework: PyTorch + Transformers
- Training Time: ~4 hours
Evaluation Results
Comparison with Base Model (at 32K context)
Distance-Based Retrieval Accuracy
Perplexity by Context Length
Usage
Basic Usage
Long Context Usage
Feature Extraction
Limitations
-
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.
Intended Use
- Long-document understanding: Processing documents that exceed typical BERT context limits
- Information retrieval: Embedding long documents for semantic search
- Long-form text classification: Sentiment analysis, topic classification on long texts
- Coreference resolution: Resolving references across long documents
- Feature extraction: Getting embeddings for downstream tasks
Training Methodology
This model uses several techniques to preserve long-range capabilities during fine-tuning:
1. YaRN RoPE Scaling
Extends positional embeddings from 8K to 32K using Yet another RoPE extensioN with:
- Scaling factor: 4.0
- Original base frequency: 10000
- Attention scaling for numerical stability
2. Retrieval-Aware Masking
Custom MLM objective that creates explicit long-range dependencies:
- Standard MLM masking (30%)
- Additional masking of tokens that appear in distant context (10% probability)
- Minimum distance threshold: 512 tokens
3. Elastic Weight Consolidation
Prevents catastrophic forgetting by:
- Computing Fisher information matrix on base model
- Penalizing changes to important weights during fine-tuning
- Lambda: 1000.0
Citation
If you use this model, please cite:
Also cite the original ModernBERT paper:
License
Apache 2.0 (same as base model)
Acknowledgments
- Answer.AI for the original ModernBERT model
- Leooyii for the SlimPajama dataset
- AMD for the MI300X GPU