ThaOCR structure β paragraphs, roles, list levels and reading order (ONNX)
Stage 5 of 5 of the ThaOCR pipeline. StructureNet (training/structure/model.py): a Transformer encoder (d=160, 4 layers, 4 heads,
about 0.6 M parameters) over the lines of a page (max 256 lines).
- Inputs per line: 23 geometric / text features (position, size, gaps, script mix, bold, bullet and so on) + 6 hashed character ids.
- Outputs per line: role (12 classes: text, title, section_header, list_item, caption, header, footer, page_number, footnote, table, form_field, other), paragraph-start flag, list level (0β3), bullet flag, and a pointer to the next line in reading order.
Models
| id | version | file | size | description |
|---|---|---|---|---|
struct_v1 (default) |
v1 | structure/struct_v1.onnx |
4.0 MB | Structure Transformer v1 (roles, paragraphs, levels, reading order) |
How it was trained
30 epochs, batch 16, training/structure/train.py; best checkpoint chosen by paragraph-start F1 + role accuracy + successor accuracy.
Dataset: docgen v3 synthetic pages with struct labels, 10,000 train / 500 val.
Result (val): role accuracy 0.988, level accuracy 0.993, bullet accuracy 1.00, successor accuracy 0.964, paragraph-start F1 0.971, Kendall tau of reading order 0.943.
Training data and licences
Synthetic only (docgen v3: English text from Project Gutenberg, Faker identities, procedural stamps/logos/figures; no real people),
so the labels are exact by construction. The page text builds on the Khmer news corpus (scraped by the owner for research use), so the
licence field is other: check that your use fits those terms. The owner's private exam photos were never used for training.
Part of ThaOCR
ThaOCR is a five-stage Khmer + English document OCR pipeline (layout, text-line detection, line recognition, font classification, page structure). Every model is plain ONNX (opset 17) and runs with onnxruntime on CPU. There is one repo per stage:
| stage | repo |
|---|---|
| layout | Thareah/ThaOCR-layout |
| textdet | Thareah/ThaOCR-textdet |
| rec | Thareah/ThaOCR-rec |
| font | Thareah/ThaOCR-font |
| structure | Thareah/ThaOCR-structure (this repo) |
The index repo Thareah/ThaOCR-models holds the full models.json manifest for all five stages.
models.structure.json in this repo lists only this stage. The file and vocab paths in both are relative to a folder into which
all stage repos are downloaded together, for example hf download Thareah/ThaOCR-structure --local-dir ThaOCR.
The pre/post-processing (letterbox + NMS, DB unclip, width bucketing + CTC, ...) is small numpy/OpenCV code in the
ThaOCR backend (backend/app/services/stages/).