fill-mask ยท text ยท WASM ยท ~155 MB
Same familiar job as the original BERT โ hide a word behind [MASK] and rank what
belongs there โ but a genuinely new encoder underneath: rotary position
embeddings, GeGLU feed-forwards, and alternating global/local attention that
lets it read an 8,192-token context (16ร BERT's 512). Type a sentence with a
mask and see its guesses, plus the exact logits. Everything runs on your device.
| Model | answerdotai/ModernBERT-base (official ONNX build) |
|---|---|
| Task / pipeline | fill-mask โ masked language modelling, loaded via AutoModelForMaskedLM for raw logits |
| Output | A probability over the 50,368-token vocabulary at each [MASK] |
| Architecture | ModernBERT-base โ 22 layers, ~149M params, RoPE + GeGLU + alternating global/local attention |
| Context length | 8,192 tokens (BERT-base: 512) |
| Tokenizer | Byte-level BPE (OLMo-style), 50,368 vocab, [MASK] token |
| Quantization | q8 (8-bit) ONNX |
| Backend | WebAssembly (runs anywhere; no WebGPU needed) |
| Download | ~155 MB, cached after first load |
| License | Apache-2.0 |
| Web APIs | WebAssembly, Web Workers โ all Baseline widely available |
Write a sentence containing [MASK] (use the button if you're not sure).
ModernBERT predicts the missing word. You can use more than one mask โ and, unlike BERT, your
text can be very long.
Like any masked language model, ModernBERT doesn't output words โ it outputs a
logit (a raw, unbounded score) for every one of its 50,368 vocabulary tokens at
the masked position. We softmax those into probabilities. The bars above show the
probability; the logit beside each is the actual number the network produced. The
top-k entropy below is โ โ low means ModernBERT is sure, high means it's
hedging.
top-k entropy: โ bits ยท top-1 carries โ of the shown mass
| BERT-base (2018) | ModernBERT-base (2024) | |
|---|---|---|
| position encoding | learned absolute (capped at 512) | rotary (RoPE) โ extrapolates |
| attention | full attention, every layer | alternating global / 128-token local |
| context length | 512 tokens | 8,192 tokens |
| feed-forward | GeLU | GeGLU (gated) |
| normalization | post-LayerNorm | pre-LayerNorm, bias-free |
| tokenizer | WordPiece, 30,522 vocab | byte-level BPE, 50,368 vocab |
| training data | ~3.3B tokens (books + wiki) | ~2T tokens, incl. code |
The alternating attention is the trick that unlocks long context cheaply: most layers only look 128 tokens either side (local), and every third layer looks at everything (global). You get long-range reach without the quadratic cost of full attention on 8,192 tokens.
Encoders never went away โ they're the quiet workhorses behind search, retrieval, classification and extraction, where you need to understand text fast, not generate it. ModernBERT is a drop-in upgrade to that whole layer: same masked-LM interface, but faster, longer-context, and trained on far more (and more modern, code-aware) data. Because it scores every word in context, you can ask it what fits, how strongly, and compare alternatives โ all locally, with no prompt engineering and no API bill.
return a ___ b" surfaces what a code-aware encoder learned.One mask, ranked predictions with probabilities and the raw logits behind them.
Long-context masked prediction and factual/code knowledge probing over ready-made templates.
Bias probe โ run the same sentence with one word swapped and compare what ModernBERT expects.
Fill the mask, then rank the candidates by meaning with MiniLM embeddings.
The one-liner uses the fill-mask pipeline:
import { pipeline } from "@huggingface/transformers";
const unmask = await pipeline("fill-mask", "answerdotai/ModernBERT-base");
const out = await unmask("The capital of France is [MASK].");
// โ [{ token_str: "Paris", score: 0.34, sequence: "โฆ" }, { token_str: "Lyon", โฆ }]
For the "see inside" surface we go one level lower โ AutoModelForMaskedLM โ so we can
read the exact logits tensor ([1, sequence, 50368]), slice the row at the
[MASK] position, and softmax it ourselves. That's the only way to show the real logit
values, not just the pipeline's rounded scores. ModernBERT uses a byte-level BPE tokenizer, so a
word-initial token carries a leading space โ we trim it for display. All of it runs in a Web
Worker so the page never janks, even on a long document.