← All models

fill-mask · Chinese spelling correction · WASM · ~474 MB

Chinese spell check — 天气, not 天汽

Chinese typing errors are usually homophones: same sound, wrong character (天汽 instead of 天气). macbert4csc is a Chinese BERT fine-tuned to fix exactly these — it reads the whole sentence and predicts the most likely character at every position. This demo runs it on-device, marks every change, and shows how confident the model was.

At a glance

Modelshibing624/macbert4csc-base-chinese
Taskfill-mask (BERT MLM) — used here for Chinese spelling correction (CSC)
ArchitectureMacBERT (BERT) — masked-language head fine-tuned for CSC; 102M params, 21,128-token Chinese vocab
Params / dtype102M · fp32 (only fp32 ONNX export exists — 474 MB single file)
BackendWebAssembly (CPU) — no GPU required
Download~474 MB, cached after first load
LicenseApache-2.0
Web APIsWeb Workers, Cache Storage (via Transformers.js), WebAssembly

Run it

修正后的句子会显示在这里。

See inside — one pass, all positions

Unlike seq2seq models, this is a single forward pass: the sentence is tokenized, and the MLM head predicts the most likely character at every position at once, conditioned on the whole sentence. Each listed fix shows the model's confidence — the softmax probability of the corrected character. High confidence + a real error = a confident fix; low confidence can mean the model is unsure. Nothing is faked; a correct sentence usually comes back unchanged (try the last chip).

Why it matters

Chinese input methods make homophone typos inevitable, and spell-checking Chinese is a genuinely different problem from English (no spaces, no sound-alike dictionary lookup — the model has to understand context). On-device CSC means IMEs, editors, and chat apps can offer corrections with zero text leaving the device.

Use cases

Basics

Fix the sentence — homophone typos corrected with per-character confidence.

Practical

Document scan: paste a paragraph, get every correction in one pass.

Wild

Typo bench — see how the model handles deliberate, sneaky homophone traps.

How the API works

The model is a plain masked-LM; correction reads its per-position argmax:

import { AutoTokenizer, BertForMaskedLM } from "@huggingface/transformers";

const tokenizer = await AutoTokenizer.from_pretrained(MODEL, { subfolder: "onnx" });
const model = await BertForMaskedLM.from_pretrained(MODEL, { subfolder: "onnx", dtype: "fp32" });
const enc = await tokenizer("今天天汽很好");
const { logits } = await model({ input_ids: enc.input_ids, attention_mask: enc.attention_mask });
// for each position: argmax over the 21,128-token vocab = the corrected character
// diff against the input tokens → the changes shown on the page

One forward pass for the whole sentence; the argmax at every position is the model's real prediction. Runs in a Web Worker so the page stays responsive.

References