# Mandarin Chinese support for widgets and booklets

> The interactive widgets and the booklet generator now segment Mandarin Chinese into words as well as single characters. Thanks to Zhang Xilian for the nudge.

Recently Zhang Xilian, a master's student at The Education University of Hong
Kong, wrote to say he was planning to run LLMs Unplugged workshops in China, and
that the [Training](https://www.llmsunplugged.org/modules/training/) and [Generation](https://www.llmsunplugged.org/modules/generation/)
widgets didn't understand Mandarin Chinese. Neither did the booklet generator.
He was right: paste a line of Chinese into any of them and nothing happened.

The reason was buried in the tokeniser. To turn text into a model you first cut
it into tokens, and our tokeniser only recognised the letters `a` to `z`.
Everything else was treated as a gap between words and thrown away: digits,
stray symbols, and every Chinese character. Feed it a whole
poem and you got an empty model, with nothing to count and nothing to generate
from.

We had to choose whether to count individual characters or segment the Chinese
text into words. Unlike English, Chinese doesn't separate words with spaces.

The simplest answer is one token per character. 莲 follows 采, 叶 follows 莲.
Each character becomes a cell in the frequency grid, a cutout card, or a face
you can roll for.

Xilian pointed out what that misses. A Chinese word is often two or three
characters, like 深圳 (Shenzhen) or 金融 (finance). Cutting on every character
is a little like splitting English into its letters. So the tools now segment
into words by default, using [jieba](https://github.com/fxsjy/jieba), the
standard open-source Chinese tokeniser he recommended.[^ambiguity] Give
it 深圳最高的楼是平安金融中心 and it comes back
as 深圳 / 最高 / 的 / 楼 / 是 / 平安 / 金融中心.

[^ambiguity]:
    The boundaries are not always clean. 最高的 ("tallest") could be one word,
    or 最高 plus 的, and jieba has to pick one. That there is a choice at all is
    worth a few minutes in a classroom.

You can switch between words and characters in both tools. The widgets show a
words/characters toggle whenever there is Chinese on the page, and the
command-line tool takes `--cjk word` or `--cjk char`.

Here's a bigram model trained on _Jiangnan_, a two-thousand-year-old Han-dynasty
folk poem about picking lotus. Press play to watch it count the words, and use
the toggle to drop back to single characters:

<TrainingWidget
  client:visible
  initialText="江南可采莲，莲叶何田田。鱼戏莲叶间。鱼戏莲叶东，鱼戏莲叶西，鱼戏莲叶南，鱼戏莲叶北。"
/>

Chinese punctuation gets the same treatment. The full-width comma ， and full
stop 。 are kept as their own tokens, boxed in the model just like the English
`.` and `,`. A generated line breaks where a real sentence would.

The same segmentation flows through to print. Here's the
[_Jiangnan_ bigram booklet](https://pdf.llmsunplugged.org/booklets/jiangnan.pdf)
as a ready-to-print PDF, with every dice-lookup entry set in Noto Serif CJK. The entries are ordered by pinyin, the way a Chinese
dictionary sorts them. 电脑 (diannao) files before 手机 (shouji), so a word
stays findable once a booklet runs long. The [tools page](https://www.llmsunplugged.org/tools/) will generate
one from any text you paste in, Mandarin or otherwise. The bundled fonts cover
the simplified characters used across mainland China.

<Callout type="note" title="What works, and what's next">

The widgets, the booklet generator, the cutouts, and the in-browser PDF export
all handle Chinese now. If you are teaching in another language and something
doesn't work, tell us. The tokeniser is where most of these limits live, and
they are usually a small change once we know they are there.

</Callout>

Thanks again to Xilian: for the nudge, for the reading list of Chinese classroom
texts to test on, and for walking me through word segmentation and pinyin
ordering. If you run a workshop with any of this, I'd love to hear how it goes.

Source: <https://www.llmsunplugged.org/news/2026-07-03-chinese-language-support/>\
Licence: [CC-BY-SA-4.0](https://creativecommons.org/licenses/by-sa/4.0/)\
Cite as: Swift, B. (2026). _LLMs Unplugged: Understand how AI language models work by building one yourself._ https://doi.org/10.5281/zenodo.17403824
