โ† All models

fill-mask ยท text ยท WASM ยท ~155 MB

ModernBERT โ€” BERT, rebuilt for 2024

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.

At a glance

Modelanswerdotai/ModernBERT-base (official ONNX build)
Task / pipelinefill-mask โ€” masked language modelling, loaded via AutoModelForMaskedLM for raw logits
OutputA probability over the 50,368-token vocabulary at each [MASK]
ArchitectureModernBERT-base โ€” 22 layers, ~149M params, RoPE + GeGLU + alternating global/local attention
Context length8,192 tokens (BERT-base: 512)
TokenizerByte-level BPE (OLMo-style), 50,368 vocab, [MASK] token
Quantizationq8 (8-bit) ONNX
BackendWebAssembly (runs anywhere; no WebGPU needed)
Download~155 MB, cached after first load
LicenseApache-2.0
Web APIsWebAssembly, Web Workers โ€” all Baseline widely available

Run it

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.

context 0 / 8192 tokens

See inside โ€” logits, and what changed vs classic BERT

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.

ModernBERT vs the original BERT

Both are masked-language-model encoders โ€” the difference is everything under the hood.
 BERT-base (2018)ModernBERT-base (2024)
position encodinglearned absolute (capped at 512)rotary (RoPE) โ€” extrapolates
attentionfull attention, every layeralternating global / 128-token local
context length512 tokens8,192 tokens
feed-forwardGeLUGeGLU (gated)
normalizationpost-LayerNormpre-LayerNorm, bias-free
tokenizerWordPiece, 30,522 vocabbyte-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.

Why it matters

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.

Use cases

Basics

One mask, ranked predictions with probabilities and the raw logits behind them.

Practical

Long-context masked prediction and factual/code knowledge probing over ready-made templates.

Wild

Bias probe โ€” run the same sentence with one word swapped and compare what ModernBERT expects.

Multi-model

Fill the mask, then rank the candidates by meaning with MiniLM embeddings.

How the API works

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.

References