fill-mask · text · WASM · ~103 MB
Google's BERT, pre-trained on Chinese Wikipedia. Its one job here is
masked language modelling: hide a character behind [MASK] and it
ranks which Hànzì belongs there. Chinese BERT is character-level — every character
is its own token, so it needs no word-segmentation step. Type a sentence with a mask and see its
guesses, plus the exact logits it computed. Everything runs on your device.
| Model | Xenova/bert-base-chinese (ONNX build of google-bert/bert-base-chinese) |
|---|---|
| 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), character-level WordPiece — one token per Hànzì |
| Language | Chinese (Simplified & Traditional) — mask token is [MASK] |
| Quantization | q8 (8-bit) ONNX |
| Backend | WebAssembly (runs anywhere; no WebGPU needed) |
| Download | ~103 MB, cached after first load |
| License | Apache-2.0 |
| Web APIs | WebAssembly, Web Workers — all Baseline widely available |
Write a Chinese sentence containing [MASK] (use a sample if you're not
sure). Chinese BERT predicts the missing character. You can use more than one mask.
First, how the text is tokenised: Chinese BERT splits your sentence into one chip
per character — no word segmentation, no sub-word merging. The ▢ chip is the position
being predicted.
And the prediction itself: the model outputs a logit (a raw, unbounded score) for
every one of its 21,128 vocabulary 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 BERT is sure which character fits, high means it's hedging.
top-k entropy: – bits · top-1 carries – of the shown mass
Chinese has no spaces between words, so most NLP starts with the hard problem of segmentation. A character-level masked model sidesteps that entirely: it reasons one Hànzì at a time, in context. Because it scores every character in context, you can ask it what fits, how strongly, and compare alternatives — all locally, with no prompt engineering and no API bill.
One Chinese mask, ranked character predictions with probabilities and the raw logits.
A Chinese input assistant — predict the next character one at a time and build a sentence.
Chengyu challenge — mask a character in a four-character idiom and see if BERT knows it.
Fill the Chinese mask, then translate the completed sentence to English with a second model.
The one-liner uses the fill-mask pipeline:
import { pipeline } from "@huggingface/transformers";
const unmask = await pipeline("fill-mask", "Xenova/bert-base-chinese");
const out = await unmask("北京是中国的[MASK]都。");
// → [{ token_str: "首", score: 0.82, sequence: "…" }, { token_str: "古", … }] → 首都 = "capital"
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 and the character-by-character tokenisation, not just the pipeline's rounded scores. All of
it runs in a Web Worker so the page never janks.