读古文字学论著里排印的行:一行图进去,文字出来。它是 OpenGlyph-OCR-0 的下一版,多了两样本事:
⿰亻木 就是“休”。这样的字它写成 <ids>⿰拍嵩</ids>,作者新造、哪个字表都没有的字也有了写法。有码位的字照 Unicode 写;没有码位、GlyphWiki 有收的字形写成 <gw:字形名>(同 OpenGlyph-OCR-0)。另可要它把每处的第二选项一并给出(见下文“输出”)。
read_page(见下文),不写换行。只试过这一页,多栏、表格、竖排的页面没有试过。测量用的论文行高约 100–150 像素,专项测试的行高约 96 像素。out = read_line(ocr, "line.png")
out["text"] # 一行文字:Unicode 字、<gw:字形名>、<ids>IDS</ids>
out["ids"] # 它写的每个 IDS,以及拼出的是什么:有码位的字 / 有记号的字形 / 新的字形
下面是专项测试里一行的真实输出(这一行整行读对):
𤪷也庾參與<gw:u2ff1-u65e5-u82f1><gw:ebag_s093-073><ids>⿰拍嵩</ids>了燒造磚瓦的工作
text 里三种写法的意思:
| 写法 | 意思 |
|---|---|
普通的字,如 𤪷 |
有码位的字,照 Unicode 写;生僻字可能是拼出 IDS 之后换回的 |
<gw:u2ff0-u79c0-u6208> |
GlyphWiki 有收、没有码位的字形,名字可到 https://glyphwiki.org/wiki/字形名 查 |
<ids>⿰…</ids> |
没有码位、GlyphWiki 也没有收(或它不认得)的字,由它拼出的 IDS |
第二选项。 read_line(ocr, "line.png", options=True) 另给 out["options"]:凡有另一种读法的地方,给出那一读法和它的来历——问过拼字的两条路的地方,给没有采用的那一读(拼出的 IDS,或原来那个字);没问过、但它对第一选择把握不大的地方(第一选择的分数比第二选择高不到 4,分数指模型输出的 logit),给它的第二选择。text 本身不因此而变。在 313 段论文片段上,生僻字按第一选择读对 93.0%,算上第二选项读对 94.8%;平均每段给出 0.54 个第二选项。论文片段里的一段(at_text 是这一处在 text 里的位置):
{
"text": "(陳)榑叄立事歲右<ids>⿳亠回米</ids>(廩)釜",
"options": [
{
"at_text": 3,
"stands_text": "榑",
"other_text": "搏",
"other_from": "the reader",
"lead": 0.562
},
{
"at_text": 4,
"stands_text": "叄",
"other_text": "<ids>⿳𠫯八三</ids>",
"other_from": "the speller",
"lead": 2.951
},
{
"at_text": 9,
"stands_text": "<ids>⿳亠回米</ids>",
"other_text": "稟",
"other_from": "the reader",
"lead": 1.256
},
{
"at_text": 27,
"stands_text": "釜",
"other_text": "釡",
"other_from": "the reader's second choice",
"lead": 1.625
}
]
}
hf download OpenGlyph/OpenGlyph-OCR-IDS --local-dir OpenGlyph-OCR-IDS
cd OpenGlyph-OCR-IDS
pip install -r requirements.txt
python -m openglyph_ocr_ids line.png # 每行图输出一行 JSON
python -m openglyph_ocr_ids line.png --options # 连同第二选项
python -m openglyph_ocr_ids page.png --page # 整页一次读(按 OpenGlyph-OCR-0 的读法,不写 IDS)
from openglyph_ocr_ids import load, read_line, atoms
ocr = load() # 本仓库所在的目录
out = read_line(ocr, "line.png")
print(out["text"])
print(atoms(out["text"])) # [('text', '其'), ('glyph', 'u2ff0-u79c0-u6208'), ('ids', '⿰…'), …]
page = read_page(ocr, "page.png") # 整页一次读;切成行用 read_line 读,效果更好
print(page["text"], page["complete"]) # complete 为 False 时,加大 max_tokens(默认 2048)
transformers 版。requirements.txt 装(mlx 0.32.3、mlx-vlm 0.3.12、transformers 5.18.0、tokenizers 0.23.2)。底模是 16 位浮点,换了版本算出来的数会有细微出入,下面的成绩就不一定原样重现。torch 和 torchvision 只用来预处理图像(装了它们,图像的预处理才与测量时逐像素相同)。以下都是 2026 年 11 月用这一套权重、MLX 版量的。“原版”指 Xiaomi-OCR-0 原样、用它自己的提示词去读同样的图。整行(整段)一字不差才算全对(空格不计,全角半角算同一个字);字错率 = 编辑距离 ÷ 答案的字数(一个字形记号算一个字)。写出的 IDS 若画的正是答案那个字,算读对;严格按写出的字符串算的数,凡有不同,都在表下注明。
四篇古文字学论文的电子版和一本书的四页扫描,都不在任何一套权重的训练材料里。“含难字的片段”是从那四篇论文里切出的、带难字的片段,每段 4–16 个字。
| 原版 Xiaomi-OCR-0 | OpenGlyph-OCR-0 | OpenGlyph-OCR-IDS | ||
|---|---|---|---|---|
| 论文整行(398 行,四篇论文的整行) | 整行全对 | 272(68.3%) | 332(83.4%) | 347(87.2%) |
| 字错率 | 3.71% | 0.90% | 0.70% | |
| 论文里含难字的片段(313 段,同四篇论文,每段 4–16 字) | 整段全对 | 225(71.9%) | 252(80.5%) | 276(88.2%) |
| 字错率 | 5.14% | 2.89% | 1.88% | |
| 一本书的扫描页(93 行,四页) | 整行全对 | 54(58.1%) | 69(74.2%) | 75(80.6%) |
| 字错率 | 2.20% | 1.12% | 0.83% |
注:论文里含难字的片段:严格按写出的字符串算,OpenGlyph-OCR-IDS 整段全对 275 段,字错率 1.94%。两者逐行相比,论文整行里只有 OpenGlyph-OCR-IDS 读对的 21 行,只有 OpenGlyph-OCR-0 读对的 6 行;论文里含难字的片段里只有 OpenGlyph-OCR-IDS 读对的 24 段,只有 OpenGlyph-OCR-0 读对的 0 段;一本书的扫描页里只有 OpenGlyph-OCR-IDS 读对的 7 行,只有 OpenGlyph-OCR-0 读对的 1 行。
图中六行的出处(截图只用来说明模型读得怎样,著作权归原作者和出版者):
测试用的四篇论文,除上面三篇外,还有一篇 2025 年的学位论文;我们不知道它是否已经公开,这里不列名,也不用它的截图。那本书的四页扫描,是《甲骨金文語文論稿》的第 1–4 頁。
| 原版 Xiaomi-OCR-0 | OpenGlyph-OCR-0 | OpenGlyph-OCR-IDS | ||
|---|---|---|---|---|
| 论文里含难字的片段(313 段) | 基本区的生僻字 | 298 / 354 | 318 / 354 | 339 / 354 |
| 扩展区的字 | 0 / 33 | 11 / 33 | 21 / 33 | |
| 一本书的扫描页(93 行) | 扩展区的字 | 0 / 13 | 3 / 13 | 12 / 13 |
| 论文整行(398 行) | 基本区的生僻字 | 326 / 402 | 355 / 402 | 370 / 402 |
| 扩展区的字 | 0 / 31 | 13 / 31 | 21 / 31 | |
| 专项测试(300 行) | 基本区的生僻字 | 121 / 300 | 73 / 300 | 256 / 300 |
| 扩展区的字 | 0 / 300 | 151 / 300 | 221 / 300 |
注:严格按写出的字符串算,OpenGlyph-OCR-IDS 在论文里含难字的片段的扩展区字为 19 / 33。
“基本区的生僻字”指基本区里分词器要拆成两三个记号的字;“扩展区的字”指扩展 A 至 J 区的字。专项测试是程序排印的 300 行:句子取自测试用的论文,每行嵌入一个基本区的生僻字、一个扩展区的字(各有一半取自这些论文,一半从全部生僻字里随机抽取)、两个 GlyphWiki 字形和一个只能写成 IDS 的字。
生僻字的提高,大多来自按部件再拼一遍:专项测试里,它读对的 256 个基本区生僻字里,232 个是拼成 IDS 读出来的(拼出的 IDS 画的正是这个字),扩展区的字也是如此(221 个里 186 个)。拼出的 IDS 若在 canon.json 里查得到有码位的字,输出时就换成那个字:论文片段里它写了 263 个 IDS,257 个这样换了回去。
| 专项测试里只能写成 IDS 的字 | 原版 | OpenGlyph-OCR-0 | OpenGlyph-OCR-IDS |
|---|---|---|---|
| 两个部件(左右或上下) | 0 / 195 | 0 / 195 | 109 / 195(55.9%) |
| 包围结构 | 0 / 29 | 0 / 29 | 8 / 29(27.6%) |
| 三个部件 | 0 / 22 | 0 / 22 | 7 / 22(31.8%) |
| 嵌套(部件本身又是拼成的) | 0 / 54 | 0 / 54 | 2 / 54(3.7%) |
| 有部件在训练里一次也没出现过 | 0 / 52 | 0 / 52 | 18 / 52(34.6%) |
| 合计 | 0 / 300 | 0 / 300 | 126 / 300(42.0%) |
写对的 126 个里,116 个与答案的 IDS 一字不差,10 个换了一种写法、画出来是同一个字(例如把上下两层再分上下,写成 ⿳)。
| OpenGlyph-OCR-0 | OpenGlyph-OCR-IDS | |
|---|---|---|
| 专项测试,600 个 GlyphWiki 字形 | 402 / 600 | 414 / 600 |
| 其中 ebag 系列 60 个 | 42 / 60 | 22 / 60 |
| 其中按 IDS 命名的 240 个 | 164 / 240 | 199 / 240 |
| 四页扫描,27 处 GlyphWiki 字形 | 16 / 27 | 14 / 27 |
在一台 24 GB 内存的 Apple 芯片 Mac 上(MLX):
| 每行用时(中位数) | 原版 | OpenGlyph-OCR-0 | OpenGlyph-OCR-IDS |
|---|---|---|---|
| 论文的整行 | 0.5 秒 | 1.1 秒 | 2.0 秒 |
| 论文里含难字的片段 | 0.2 秒 | 0.4 秒 | 1.4 秒 |
| 扫描书页的一行 | 0.5 秒 | 1.0 秒 | 2.4 秒 |
| 专项测试的一行(每行五个难字) | 0.4 秒 | 0.4 秒 | 16.9 秒 |
慢在拼字:每个要问的地方,要把字切成部件读几遍,还要再拼一遍。生僻字越多越慢。读一行时内存最多占到约 5 GB。
⿰⿱⿲⿳⿴⿵⿶⿷⿸⿹⿺⿻ 十二个结构符。reading.json)。门槛是在另一批调试用的行上选的,从没看过测试;换一类材料,最合适的门槛未必相同。读一行时,同一个模型里有四套权重:
<ids>、</ids> 和十二个结构符)和语言层 18–23 的 LoRA(秩 8),沿着读字的写出的行看,说哪里该写 IDS、可能是什么结构。两条路拼出同一个字,就采用;不同时,看拼字的有多大把握,按这处的类别(拼出的是有码位的字、有记号的字形,还是新的字形;读字的原来写的是生僻字、字形记号还是常用字)各有一道门槛;都不够,就留下读字的原来那个字。读字的自己写出生僻字或字形记号的地方,即使开口的没有说,也请拼字的拼一遍。
训练开口的那一套,用的是程序排印的拼字行,加上 OpenGlyph-OCR-0 训练时用过的几类行,以守住旧有的本事(其中 3,000 行是从 26 篇论文电子版裁出的真实行);拆字读部件的用同一批行,部件按排字程序的记录切开,另把行里一些有码位的字也切开来练习。拼字的只用程序排印的行:用部件拼出的字(含左右、上下、包围、三部件、嵌套)嵌在论文的句子里,GlyphWiki 上按 IDS 命名的字形,以及按部件拼写的生僻字,先后训练了七轮。测试用的四篇论文和那本书都不在任何一套的训练材料里;专项测试里那 300 个只能写成 IDS 的字,是在全部训练用的拼字之外另造的,也没有在训练行里出现过。本仓库不含任何训练或测试数据。
han2ids(mkpoli,MIT 许可,模型在 Hugging Face)是一个只读一个字的图、把它写成 IDS 的小模型:约 3,500 万个参数,ViT 编码器加四层解码器,在九万多个有码位的字的字图上训练,标签是 BabelStone 的 IDS。2026 年 11 月我们读过它的设计,也在我们的测试上试过它。借鉴的是这几点:
此外,我们拿它当过一回尺子:把我们测试里的拼字按框一个个切出来给它读(它只读单字,要先告诉它字在哪里),和我们的模型在整行里自己找字、自己拼相比。当时的一版拼字,部件都练过的 600 个字,han2ids 写对 238 个,我们 272 个;带有训练里从未出现的部件的 400 个字,han2ids 232 个,我们 132 个。在没见过的部件上差距很大,这也是本模型现在的毛病之一。
我们没有用它的代码、权重或数据,本仓库里没有 han2ids 的任何东西。两者设计上的根本不同在于:han2ids 读一个字,要给框;我们的模型读整行,自己决定哪里该写 IDS,其余照常写字。
| 文件 | 内容 |
|---|---|
base/ |
Xiaomi-OCR-0 的六个文件,一字节未改 |
openglyph-ocr-0.safetensors、tokens.json |
读字的:OpenGlyph-OCR-0 训练出来的全部数组和新增的 159,052 个记号(与 OpenGlyph-OCR-0 仓库里的同名文件相同) |
opener.safetensors |
开口的:14 个新记号的输出行与偏置,语言层 18–23 的 LoRA |
part-reader.safetensors |
拆字读部件的:语言层 18–23 的 LoRA |
speller.safetensors |
拼字的:语言层与视觉塔的 LoRA、结构符的输出行、部件的输出行 |
ids-tables.json |
14 个新记号,它们的输入行取自底模的哪些行,拼字的设定 |
canon.json |
由 IDS 查有码位的字或 GlyphWiki 字形的表(196,911 条) |
token-counts.json |
每个字要底模分词器的几个记号(据此分常用字与生僻字) |
reading.json |
开口与采用的门槛(测量时所用的) |
openglyph_ocr_ids/ |
读一行的代码(MLX) |
figures/ |
本页的图(其中真实论文的截图出处见上文) |
requirements.txt |
测量时所用的各库版本 |
另有 release.json,记着每个文件的 SHA-256 和来历。
本仓库按 Apache-2.0 发布。base/ 是 Xiaomi-OCR-0,其作者以 Apache-2.0 发布,它又建立在 Qwen3.5-0.8B-Base 之上;这里原样转发,未作改动。canon.json 由几种 IDS 资料推出:CJKVI IDS(出自 CHISE IDS,按 CHISE 的条款,即 GPLv2)、BabelStone 的 IDS 表(作者声明可自由使用)和 GlyphWiki 的字形资料;这个文件按其来源的条款使用。字形名和用来排字的字形数据来自 GlyphWiki。本模型不是小米或 Xiaomi-OCR-0 作者的产品,也未经他们认可。详见 NOTICE。
What it is. The next version of OpenGlyph-OCR-0, an OCR model for single lines of printed Chinese scholarly text dense with rare characters (Xiaomi-OCR-0, 0.8B, with LoRA, a retrained vision tail and 159,052 added output tokens). It adds two things. (1) A character that has neither a code point nor a GlyphWiki glyph is written as an Ideographic Description Sequence, <ids>⿰…</ids>. (2) Wherever the reader writes a rare character or a glyph token, the glyph is also spelt from its parts as an IDS; where that spelling is sure enough, the character it spells is written (an IDS that spells an encoded character becomes that character). On the 398 whole lines of four papers that gave no training line, lines read exactly right rise from 332 (OpenGlyph-OCR-0) to 347 and the character error rate falls from 0.90% to 0.70%; on 313 pieces of those papers' lines that hold hard characters (4 to 16 characters each), pieces read exactly right rise from 252 to 276 and the error rate falls from 2.89% to 1.88%.
Whole pages. A whole page can be read in one go (read_page, or --page on the command line), but line by line reads better. On the one page tried (a printed paper page, single column, 22 lines, 691 items), the page read whole had 8 items wrong (1.16%), the same page cut into its 22 lines 5 (0.72%). Read whole, the IDS routes are not used — they find a glyph by its place within one line — so a page read whole is read as OpenGlyph-OCR-0 reads it.
How it reads a line. Four sets of weights in one model: the reader (OpenGlyph-OCR-0, unchanged) writes the line; the opener (14 added tokens and rank-8 LoRA in language layers 18–23) says where an IDS is due; at such a place, and wherever the reader itself writes a rare character or a glyph token, the glyph is read two more ways — unfolded (located by the reader's attention, cut into parts by a program, the parts read by a rank-8 LoRA part reader) and spelt whole (the speller: rank-64 LoRA in language layers 18–23 and in all twelve vision blocks and the merger, its own structure-token rows and per-step part rows, about 34.8 million weights). An IDS both routes write alike stands; otherwise the speller's stands if it is sure enough by a gate set per kind of place; otherwise the reader's own character stands. The gates were chosen on tuning lines, never on a test. With options=True the reading also returns a second option at every place that has one (the reading not taken where the routes were asked; the reader's second choice where its lead is under 4 logits); the text is the same with and without.
Measured (November 2026, MLX form; "base" is Xiaomi-OCR-0 as released, with its own prompt; an IDS that draws exactly the answer's glyph counts as right — strict counts are given in the Chinese tables where they differ):
| base | OpenGlyph-OCR-0 | OpenGlyph-OCR-IDS | |
|---|---|---|---|
| 398 whole lines of four papers: lines exactly right | 272 | 332 | 347 |
| the same lines: character error rate | 3.71% | 0.90% | 0.70% |
| 313 pieces of lines with hard characters (4 to 16 characters) from the same papers: pieces exactly right | 225 | 252 | 276 |
| the same pieces: character error rate | 5.14% | 2.89% | 1.88% |
| 93 lines of four scanned book pages: lines exactly right | 54 | 69 | 75 |
| the same lines: character error rate | 2.20% | 1.12% | 0.83% |
| special test, 300 rare basic-block characters | 121 / 300 | 73 / 300 | 256 / 300 |
| special test, 300 extension characters | 0 / 300 | 151 / 300 | 221 / 300 |
| special test, 300 characters only an IDS can write | 0 / 300 | 0 / 300 | 126 / 300 |
Known defects. Nested composites are rarely right (2 of 54 on the special test), surrounds 8 of 29, three-part 7 of 22; composites with a part never seen in training 18 of 52. It sometimes spells a GlyphWiki glyph it has a token for as a wrong IDS (ebag-family glyphs 22 / 60 against OpenGlyph-OCR-0's 42 / 60; scanned-page glyphs 14 / 27 against 16 / 27), and leaves stray IDS where no composite is (57 on the special test; on the real sets 4 in the 398 whole lines of four papers, 3 in the 313 pieces of lines with hard characters, 3 in the 93 lines of four scanned book pages). It is several times slower than OpenGlyph-OCR-0. Only the MLX form exists (the reading runs four weight sets and cuts glyphs with a program; it was written and measured in MLX); OpenGlyph-OCR-0 alone has a transformers form.
Real lines and their sources. The card shows crops of real lines, each with its source: 何義軍《戰國陶文綜合研究》(Jilin University PhD thesis, 2023), 陈晶晶《清华简典型楚文字及相关问题研究》(Hebei University PhD thesis, 2025), 沈奇石《「隼」字異讀考論》(臺大中文學報 84, 2024, DOI 10.6281/NTUCL.202403_(84).0001), 鄔可晶《甲骨金文語文論稿》(Shanghai Guji, 2024). The fourth test paper, a 2025 thesis, is not named or shown: we do not know that it is public.
What we took from han2ids. han2ids (MIT) reads ONE glyph picture into an IDS. From it we took the idea that parts need outputs of their own (hence the speller's part rows), the comparison of trainable size that made us raise the speller's LoRA rank from 8 to 64, and its convention that nesting along one axis is one structure (as our "same picture counts as right"). We also used it as a yardstick: given each composite's box, it wrote 238 of 600 test composites with practised parts against 272 for an earlier version of our speller reading whole lines, and 232 of 400 with parts never seen in training against our 132. No code, weights or data of han2ids are in this model or repository.
Before release the package in this repository was checked against the code that was measured: every array and table of the model it builds is bit for bit the measured one (1,330 entries), and 190 test lines read with it come out exactly as they were measured, every note of every place included (32 more with the second options); the page of the whole-page trial, read whole with it, comes out letter for letter as in the trial.
Licence. Apache-2.0. base/ is Xiaomi-OCR-0, redistributed unchanged under its Apache-2.0 licence. canon.json is derived from CJKVI IDS (from CHISE IDS, under CHISE's terms, GPLv2), BabelStone's IDS table (free for any use) and GlyphWiki data, and is used under the terms of those sources. Not a product of Xiaomi or of the authors of Xiaomi-OCR-0, and not endorsed by them.
base/model.safetensors 1.7 GBopenglyph-ocr-0.safetensors 821 MBspeller.safetensors 140 MBopener.safetensors 5 MBpart-reader.safetensors 5 MB