Reading woodblock books from their scans
hanocr reads Chinese books printed from carved wooden blocks, straight from the scans, without neural networks. It finds the columns and cuts out each character, compares the motion of the character's lines with exemplars cut from the same book, and lets a small model of the language choose between close shapes. Its first book is a history printed at the Ming court in 1507; on pages it never learned from, it reads 87.4 % of the characters right.
- 87.4 %characters right on the test pages 70–88
- 84.8 %right on the 108 pages nobody had proofread, checked against their text established from the scan
- 17 015characters read on pages 89–196
- 82pages proofread by people: all it learns from
What hanocr is
Many old Chinese books on Wikisource are scans with a machine collation that nobody has checked yet. hanocr is an attempt to read such books the way a careful person would: by the shapes the carver actually cut in this book, not by a font or by a network trained on modern print.
It needs no neural network and no training data from outside the book. A few dozen pages that people have already proofread on Wikisource are its teacher: the proofread text is laid onto the boxes it cuts, so every box becomes an exemplar of its character in the carver's own hand. Then it reads the pages nobody has proofread, says how sure it is of every character, and learns again from the characters it is sure of.
Every step is plain, measurable code: how the columns are found, how two shapes are compared, how the confidence is calibrated. How hanocr reads a page explains each step in plain words, with drawings.
- find the frame and the columns
- cut the characters
- compare their lines with the book's exemplars
- let the language model choose
- calibrate the confidence
- learn from what it is sure of
The result now
On the test pages 70–88, which hanocr never learned from, it reads 87.4 % of the characters right. On the 108 pages nobody has proofread yet (89–196) it read 17 015 characters, 84.8 % of them right, measured against the text established from the scan for the English translation. Its confidence marks the doubtful ones, so a reader can trust the sure reads and check the rest: every page of the book, page by page marks them.
What made the difference
Each of these was measured on pages hanocr never learned from, and kept only because it helped.
- Exemplars from the book itself. A font alone read 15 % of the characters; the carver's own shapes, cut from the proofread pages, are the base of everything else.
- Elastic comparison. Each point of a character's ink may move a little toward the exemplar before the two are compared, as one carver's strokes vary from cut to cut.
- The columns the scan cuts off. On many pages the edge of the scan had lost a whole column; finding it, and placing the grid by the white between the columns, gave back most of the lost characters.
- Learning from its own sure reads. Characters read with high confidence on the unproofread pages become new exemplars.
- Characters built from their parts. A character the proofread pages never show is assembled from parts the carver cut in other characters.
From a font alone to the book's own exemplars, elastic matching, cleaner boxes, self-training and characters built from parts: 15 % to 87.4 %.
The book
hanocr's first book is the Essentials of the Comprehensive Mirror (歷代通鑒纂要), a history of China printed at the Ming palace in 1507: the book, its pages and their English translation.
Open source soon
The code of hanocr will be open source soon; until then this site shows what it does and how it does it. It is written in Rust, from scratch: no machine-learning framework, no network to download. The scans and the texts it learns from stay outside the code, as they belong to their sources.
Credits
- The scans: the National Library of China, digitised in its Chinese ancient books collection, via Wikimedia Commons and Wikisource; public domain.
- The proofread text: the contributors of the Chinese Wikisource, under CC BY-SA 4.0.
- Characters built from parts use the IDS data of cjkvi-ids (from CHISE), GPLv2, as data.
- Character variants and stroke counts: the Unicode Han Database (Unihan).
- Rare characters on this site are drawn in Shryfti, Elamur's open fonts.
This page in Markdown https://md.ocr.elamur.ai/free/en/