fill-mask · text · WASM · ~103 MB
chinese-roberta-wwm-ext is HFL's Chinese BERT trained with
Whole-Word Masking — when it hid one character of a word during pre-training, it hid
the whole word — plus RoBERTa-style training (no next-sentence objective) on
5.4 billion tokens. Its one job here is masked language modelling:
put a [MASK] in a Chinese sentence and it ranks which single Hànzì belongs there — no
word segmentation needed, because it tokenises one character at a time. Type a sentence with a mask
and see its guesses, the exact logits, and how it compares to vanilla bert-base-chinese on
the same slot. Everything runs on your device.
| Model | onnx-community/chinese-roberta-wwm-ext-ONNX (ONNX build of hfl/chinese-roberta-wwm-ext) |
|---|---|
| Task / pipeline | fill-mask — masked language modelling, loaded via AutoModelForMaskedLM for raw logits |
| Output | A probability over the whole 21,128-character vocabulary at each [MASK] |
| Architecture | BERT-base (12 layers, ~102M params; model_type: bert, BertForMaskedLM). Char-level WordPiece — every Hànzì is its own token |
| What makes it distinct | Whole-Word Masking (mask a word's characters together), RoBERTa-style training (dynamic masking, no NSP), and the "ext" extended 5.4B-token corpus — vs Google's Wikipedia-only bert-base-chinese. Same 21,128-token vocab + [MASK], so they compare apples-to-apples |
| Language | Chinese only; mask token is [MASK] (BERT/WordPiece style) |
| Quantization | q8 (model_quantized.onnx) — verified in-browser to give sensible, non-degenerate predictions (首[MASK]→都 0.99; the fp32/fp16/q4 builds also ship but q8 is the best size/quality/speed trade-off) |
| Backend | WebAssembly (runs anywhere; no WebGPU needed) |
| Download | ~103 MB (q8), cached after first load |
| License | Apache-2.0 |
| Web APIs | WebAssembly, Web Workers — all Baseline widely available |
Write a Chinese sentence containing [MASK] (or pick a sample).
The model predicts the missing character. You can use more than one mask.
chinese-roberta-wwm-ext and Google's bert-base-chinese share the identical
21,128-character vocabulary and [MASK] token — the only thing that differs is the
training: whole-word masking + RoBERTa-style + 5.4B tokens vs plain MLM+NSP on Wikipedia. Load the
vanilla model (an extra ~103 MB, on demand) and compare what each predicts for the same
Chinese [MASK]. The whole-word-masked model often prefers characters that complete a
coherent word, and you can see it in the logits.
The comparison uses whatever sentence is in the box above. Both runs are real, off-thread forward passes — nothing is cached or faked.
A language model doesn't output words — it outputs a logit (a raw, unbounded
score) for every one of its 21,128 characters 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 – below is the entropy of the top-k — low
means the model is sure, high means it's hedging.
top-k entropy: – bits · top-1 carries – of the shown mass
A character-level vocabulary means every Hànzì is one token — the model never has to guess word boundaries. Whole-word masking taught it, during training, to fill a character in the context of the word it belongs to.
Whole-word masking makes a Chinese BERT read characters in the context of the words they form, which sharpens exactly the tasks people ship on-device: input assistance, typo and OCR correction, and confusable-character checks. Because it scores every character in context, you can ask it what fits, how strongly, and compare candidates — all locally, with no prompt engineering and no API bill. And because it shares a vocabulary with vanilla bert-base-chinese, it's an unusually clean way to see what a training recipe buys you.
One Chinese mask, ranked character predictions with probabilities and the raw logits behind them.
A Chinese proofreader — flag the weak character in each slot and probe confusable characters (的/得/地).
Chengyu challenge — mask a character in a four-character idiom and see if whole-word masking nails it.
WWM vs vanilla — run the same mask through both Chinese BERTs and measure where the training recipe changes the answer.
The one-liner uses the fill-mask pipeline:
import { pipeline } from "@huggingface/transformers";
const unmask = await pipeline("fill-mask", "onnx-community/chinese-roberta-wwm-ext-ONNX");
const out = await unmask("北京是中国的首[MASK]。");
// → [{ token_str: "都", score: 0.99, sequence: "…" }, { token_str: "府", … }]
For the "see inside" surface we go one level lower — AutoModelForMaskedLM — so we can
read the exact logits tensor ([1, sequence, 21128]), 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. All of it runs in a Web Worker so the page never
janks. We load the q8 build (model_quantized.onnx, ~103 MB) after
verifying in-browser that it produces sensible predictions.