Views
No views yet
| Dataset | Eval Loss | Perplexity |
|---|---|---|
| WikiText (Natural Language) | 1.3994 | 4.0526 |
| The Stack V2 (Code) | 0.4091 | 1.5054 |
| Combined (NL + Code) | 0.6728 | 1.9598 |
MLM Probability: 30% — Context Length: 2048 tokens
| Property | Value |
|---|---|
| Base Model | answerdotai/ModernBERT-base |
| Model Type | Masked Language Model (MLM) |
| Architecture | ModernBERT (Encoder-only Transformer) |
| Context Length | 2048 tokens |
| MLM Probability | 30% |
| Languages | English, C++, Go, Java, JavaScript, Python |
| License | MiT |
pip install transformers torch1from transformers import AutoTokenizer, AutoModelForMaskedLM
2
3tokenizer = AutoTokenizer.from_pretrained("kd13/ModernBERT-base-mlm-wiki-code")
4model = AutoModelForMaskedLM.from_pretrained("kd13/ModernBERT-base-mlm-wiki-code")
5model.config.reference_compile = False1from transformers import pipeline
2
3pipe = pipeline("fill-mask", model="kd13/ModernBERT-base-mlm-wiki-code")
4
5result = pipe("The capital of France is [MASK].")
6for r in result:
7 print(f"{r['token_str']:15s} → {r['score']:.4f}")1from transformers import pipeline
2
3pipe = pipeline("fill-mask", model="kd13/ModernBERT-base-mlm-wiki-code")
4
5result = pipe("def fibonacci(n): return n if n <= 1 else fibonacci(n-1) [MASK] fibonacci(n-2)")
6for r in result:
7 print(f"{r['token_str']:15s} → {r['score']:.4f}")1from transformers import AutoTokenizer, AutoModel
2import torch
3
4tokenizer = AutoTokenizer.from_pretrained("kd13/ModernBERT-base-mlm-wiki-code")
5model = AutoModel.from_pretrained("kd13/ModernBERT-base-mlm-wiki-code")
6
7text = "def quicksort(arr): return arr if len(arr) <= 1 else ..."
8inputs = tokenizer(text, return_tensors="pt", max_length=2048, truncation=True)
9
10with torch.no_grad():
11 outputs = model(**inputs)
12
13# CLS token embedding — shape: (1, 768)
14embedding = outputs.last_hidden_state[:, 0, :]
15print(embedding.shape)1@article{modernbert2024,
2 title = {Smarter, Better, Faster, Longer: A Modern Bidirectional Encoder for Fast, Memory Efficient, and Long Context Finetuning and Inference},
3 author = {Benjamin Warner and Antoine Chaffin and Benjamin Clavié and Orion Weller and Oskar Hallström and Said Taghadouini and Alexis Gallagher and Raja Biswas and Faisal Ladhak and Tom Aarsen and Nathan Cooper and Griffin Adams and Jeremy Howard and Iacopo Poli},
4 year = {2024},
5 url = {https://arxiv.org/abs/2412.13663}
6}