|
Download README.md from treoa/turkic-ocr-code: direct link, hf CLI and curl.
- Browser
- Download file 18.5 kB
-
https://huggingface.co/treoa/turkic-ocr-code/resolve/main/README.md
- Command line
-
hf download hf://treoa/turkic-ocr-code/README.md
-
curl -L -o README.md https://huggingface.co/treoa/turkic-ocr-code/resolve/main/README.md
18.5 kB
| # Licence: Apache-2.0 for the package, except the line detector's training and inference path and the page | |
| # pipeline, which are AGPL-3.0 (LICENSE.AGPL-3.0; the files are listed in NOTICE); see also README part 2. | |
| license: apache-2.0 | |
| language: | |
| - kk | |
| - ky | |
| - uz | |
| - tr | |
| - az | |
| - tt | |
| - ba | |
| - tk | |
| - sah | |
| pipeline_tag: image-to-text | |
| tags: | |
| - ocr | |
| - handwriting | |
| - handwritten-text-recognition | |
| - text-line-detection | |
| - synthetic-data | |
| - document-images | |
| - turkic-languages | |
| - cyrillic | |
| - latin-script | |
| TURKIC OCR: CODE OF THE GENERATOR, TRAINING AND EVALUATION | |
| (release candidate rc1_code) | |
| This package holds the code behind the project report | |
| Suleimenov, A., Bolatov, Z., Baglanova, A., Kadirbekova, A., Nguyen, A. T. (2026). A Handwriting Recognition Model | |
| for Turkic Languages in Latin and Cyrillic Script. Project report, Nazarbayev University. | |
| @techreport{suleimenov2026turkic, | |
| author = {Suleimenov, Anuar and Bolatov, Zhalgasbek and Baglanova, Aidana and Kadirbekova, Anel and Nguyen, Anh Tu}, | |
| title = {A Handwriting Recognition Model for Turkic Languages in Latin and Cyrillic Script}, | |
| institution = {Nazarbayev University}, | |
| type = {Project report}, | |
| year = {2026} | |
| } | |
| It contains the page and line generator (pagesynth 0.3.0) with its text filters, the builders of the real-data | |
| manifests and of the training mix, the training code of the vision-language readers and of the CTC line recognizers, | |
| the training and inference code of the line detector, the scorer with its bootstrap intervals and selection rules, the | |
| test-pass and page-scoring scripts, the inference scripts of the release packages, and the code of the planned RQ2 | |
| augmentation study. "The paper" below means the report cited above; section numbers refer to it (S1 to S11 are the | |
| sections of its supplementary material). Comments in the code name the project's work stages in capitals (for example | |
| GEN for the generator, DATA for the real-data manifests, PRINT, FREEZE, LINEDET, REF, VLMA, VLMB, EVALCODE) and use the | |
| round name R5 for the run that produced the paper's results. | |
| 1. WHAT IS NOT IN THIS PACKAGE | |
| - No data. None of the real datasets is included, and neither are the project's generated data, manifests, splits or | |
| predictions. Where to obtain the real datasets is listed in part 6. The generated data are released separately under | |
| CC BY-SA 4.0. | |
| - No reader weights. The fine-tuned weights of the three readers (PaddleOCR-VL-1.6, the final model; Qwen3-VL-2B; and | |
| the PP-OCRv6-medium line recognizer with its character language model) are not released. They were trained on KOHTD | |
| and HKR, whose terms limit use to the applicant's group and to academic research, and their authors have not given | |
| permission to share models trained on them. The code here lets others train their own readers from the released | |
| generated data and the real datasets obtained from their sources. | |
| - The line detector's weights are released separately, with this code path, under AGPL-3.0. | |
| - No font files. The generator needs the 73 fonts listed in src/pagesynth/assets/fonts_manifest.tsv (file name, | |
| content fingerprint, licence class, and whether the font is held out of training). Place them in src/pagesynth/assets/fonts/ or | |
| point the environment variable PAGESYNTH_FONTS to their folder. Eight of them are personal-use fonts (licence class | |
| personal_use_only); they may not be redistributed, and the released generated data contain no item drawn with them. | |
| - Not included: the vendored PaddleOCR source used only by the PP-OCRv3 reference re-run (see NOTICE), earlier | |
| generator versions (0.1 and 0.2.0; the text filters of 0.2.0 are identical to those of 0.3.0), staging and test copies of | |
| scripts, one-off probes, the corrector pilot (never trained), the unfinished full-schedule PP-OCRv3 re-run, and the | |
| download and extraction scripts of KOHTD, which need access credentials from its authors. | |
| - config_r5eval/sota_checklist.json is not included. scripts/r5_select_verdict.sbatch passes it to | |
| scripts/r5eval/verdict.py; remove that argument (verdict.py runs without it) or supply your own checklist. | |
| 2. LICENCES | |
| Apache-2.0 (LICENSE) for everything except: the line detector's training and inference path and the page pipeline, | |
| which are AGPL-3.0 (LICENSE.AGPL-3.0; the files are listed in NOTICE); the vendored HTR-Flor copy in | |
| src/ref/ (repository state of 23 June 2021; MIT, its own LICENSE); and the Natural Earth map files in | |
| src/pagesynth/assets/naturalearth/ (public domain). Copyright and third-party notices are in NOTICE. | |
| 3. SETTING UP | |
| 3.1 Paths. The code ran on a Slurm cluster with one code folder and one data folder. Every absolute path in the | |
| package now starts with a placeholder: | |
| /path/to/TURKIC_OCR_CODE the folder that holds this package (src/, scripts/, ... and the virtual environments) | |
| /path/to/TURKIC_OCR_DATA the data folder, with data/raw, data/processed, outputs, checkpoints, logs, hf_cache, tmp | |
| Replace both with your own folders before running anything, for example: | |
| grep -rlF /path/to/TURKIC_OCR_CODE . | xargs sed -i 's#/path/to/TURKIC_OCR_CODE#/home/me/turkic_ocr#g' | |
| grep -rlF /path/to/TURKIC_OCR_DATA . | xargs sed -i 's#/path/to/TURKIC_OCR_DATA#/data/turkic_ocr#g' | |
| Neither placeholder is a prefix of the other, so the order does not matter. The Slurm headers name | |
| the partitions (H100, ZEN4) and quality-of-service names of the original cluster; adapt them to yours. Many scripts | |
| and comments refer to the project's working records (paths that begin with records/, or files under the data folder | |
| such as manifests and score files); these records are not part of this package. | |
| 3.2 Python environments. The scripts call the interpreter of a project environment, for example | |
| /path/to/TURKIC_OCR_CODE/.venv_gen/bin/python. The folder environments/ holds the exact package list of each | |
| environment, made with 'uv pip freeze'. To rebuild one: | |
| uv venv --python 3.12 /path/to/TURKIC_OCR_CODE/.venv_gen | |
| uv pip install --python /path/to/TURKIC_OCR_CODE/.venv_gen/bin/python -r environments/venv_gen.requirements | |
| PyTorch builds with a +cu suffix in the lists come from the PyTorch package index (add | |
| --extra-index-url https://download.pytorch.org/whl/<cuda tag>, the tag matching the suffix). | |
| environment (file) Python main use | |
| .venv (venv.requirements) 3.12 real-data manifests (scripts/r5), KOHTD split and leak checks, zero-shot screen | |
| .venv_gen (venv_gen.requirements) 3.12 generator, training-mix freeze, release data build | |
| .venv_kraken 3.12 CTC line recognizers, letter model, detector, scorer jobs, test pass 2, RQ2 | |
| .venv_vlm 3.12 vision-language training and evaluation (scripts/r5_vlma), single page model, | |
| loop guard, page check, showcase | |
| .venv_vlm_<model> (9 files) 3.12 * one per extra candidate in scripts/r5_vlmb (* unlimited_ocr_2: 3.10) | |
| .venv_print 3.12 real printed lines (scripts/r5_print) | |
| .venv_ref_tf 3.11 HTR-Flor reference re-run (R1) | |
| .venv_ref_paddle, .venv_ref_paddle_cpu 3.11 PP-OCRv3 reference re-run (R2) | |
| .venv_dl see file download tools (Kazakh web benchmark) | |
| The exact Python version of each environment is in its file's first line. Each shell and sbatch file names the | |
| environment its step used. The release packages in release/ carry their own requirements.txt. | |
| 4. FOLDERS AND WHERE THEY APPEAR IN THE PAPER | |
| src/pagesynth/ Page and line generator 0.3.0: text cleaning and filters (text.py, langtext.py, | |
| textbuild.py, vocab.py), fonts and the glyph gate, the simulated writer, layouts, paper, | |
| marks, maps, capture, cropping; produce_r5.py and scripts/ run the text build, the text | |
| split by source document and the production. Paper: Section 2.2, S2. | |
| src/linedet/ CTC line recognizers (PP-OCRv6 medium and small, CRNN, HTR-VT-style model), training | |
| driver, prediction, the character 6-gram letter model with beam search and its gate, and | |
| (det_*.py, AGPL-3.0) the YOLO11s line detector: data preparation, training, evaluation. | |
| Paper: Sections 3.4 and 3.5, S6, S9, S10. | |
| src/r5eval/, scripts/r5eval/ Scorer: text normalisation, CER and WER, look-alike repair, form-level bootstrap, | |
| config_r5eval/, tests_r5eval/ Holm correction, selection of leaders and of the final model, decision rules, report | |
| cards; with its configuration and tests. Paper: Section 4, S7. | |
| scripts/r5_score.sbatch and Scoring, selection, verdict, learning-curve and self-test jobs of the scorer. | |
| the other scripts/r5_*.sbatch Paper: Section 4, S7. | |
| scripts/r5_gate/ Gate files that kept the test sets sealed until the single test pass. Paper: Section 4, S7. | |
| scripts/r5/ Real-data manifests (KOHTD, HKR, Cyrillic Handwriting Dataset, School Notebooks, RUKOPYS, | |
| LocalDoc), de-duplication against held-out images, the registry of training, validation | |
| and test sets, validation subsets and the unseen-word slice. Paper: Section 2.1, S1, S4, S7. | |
| scripts/k1_labels_all.py, KOHTD split by exam form (a salted deterministic function of the form number). Paper: Section 2.1, S4. | |
| scripts/k1_build_split.py | |
| scripts/kohtd_leak_* Checks that no KOHTD training crop without a form number is a copy of a validation or | |
| test crop. Paper: S4. | |
| scripts/r5_print/ Real printed lines: candidate PDFs from FinePDFs, text-layer check, line cutting, pixel | |
| checks, split by document. Paper: Section 2.1, S3. | |
| scripts/r5_freeze/ Freeze of the training mix (shares, de-duplication against held-out sets, sample | |
| sequences). Paper: Section 2.3, S2. | |
| scripts/j2/ Zero-shot screen of released document models on KOHTD validation words. Paper: Section 3.2. | |
| scripts/r5_vlma/ Fine-tuning and evaluation of the vision-language readers (shared recipe, short and long | |
| runs, slot runners), preference post-training (DPO, GRPO), and the sealed test pass. | |
| Paper: Sections 3.2, 3.3 and 4, S5, S6, S7. | |
| scripts/r5_vlmb/ Adapters, environments and runner for the extra vision-language candidates. Paper: S5, S6. | |
| scripts/r5_linedet/ Jobs of the line recognizers, the detector and the letter model. Paper: Sections 3.4, 3.5, S6. | |
| scripts/r5_ref/, src/ref/ Reference re-runs: HTR-Flor (R1, vendored copy in src/ref/) and PP-OCRv3 (R2, PaddleOCR | |
| not included). Paper: Section 5, S10. | |
| scripts/r5_testpass2/ Second test pass and its amendments: real handwriting and print tests, page tests | |
| (TurkishOCR-Bench, Kazakh web benchmark), label-free re-reading of the line recognizer, | |
| per-language tables, error analysis. Paper: Section 5, S7, S8, S9. | |
| scripts/tp2_proposal_metrics.py Measures for the research questions. Paper: Section 6.1, S8. | |
| scripts/r5_erran/ Error analysis of validation outputs (label errors, ambiguous handwriting). Paper: S7. | |
| scripts/b1_page_check/ Page check: the final model on whole pages, alone and after the detector. Paper: S9. | |
| scripts/r5_onemodel/ Single page model: page records, training, page scoring. Paper: S6, S9. | |
| scripts/r5_loopguard/ Loop guard for the single page model. Paper: S9, S10. | |
| scripts/r5_showcase/ Showcase pages: the generator stages of chosen validation pages (material for Figure 2) | |
| and pages read by the pipeline. Paper: Section 2.2, S11. | |
| scripts/r5_release/ Checks of the first release candidate, including the batching diagnostic of the line | |
| recognizer. Paper: S7 (the batching leak). | |
| scripts/release2/ Release build: data package, Parquet shards, regeneration check of every released page, | |
| Sakha-text check, cards and file verification; rel2_d5_* (AGPL-3.0) retrain and check the | |
| released detector without the personal-use-font pages. Paper: S11. | |
| release/ Inference scripts and requirements of the release packages: the three readers (whose | |
| weights are not released), the line detector and the page pipeline (AGPL-3.0). Paper: S11. | |
| src/rq2/, scripts/r5_rq2/, RQ2 augmentation study (line height 32 or 64 px crossed with a typical or a diacritic-safe | |
| src/lettersynth/ augmentation policy) and its pixel probe; src/lettersynth holds only the letter-sheet | |
| reader that the probe uses. This code was written after the paper's results; the paper | |
| states that the study was not run, and no RQ2 result is part of it. | |
| environments/ Package lists of the Python environments (part 3.2). | |
| 5. KNOWN ISSUES | |
| - Content pins. Some files pin the exact content of other files as it was on the cluster, and a few check it at start. | |
| Making the paths configurable changed some pinned files, so those pins no longer match (the list of affected pins | |
| is in part 7). Update the pinned values after configuring the paths, or skip the check. | |
| - release/turkic-ocr-ppocrv6-medium/infer.py is the inference script of the withheld PP-OCRv6 package. Its docstring | |
| was written before the corrections the paper reports in S7 (the batching leak) and was not updated; the paper's | |
| figures supersede the ones it quotes. | |
| - The generator reproduces the content of a page from its seed but not every byte (paper, S11). | |
| - The scripts were written for one cluster and one run of the project: many take their inputs from fixed paths and | |
| write records of that run. They document what was done; running them elsewhere needs the data, the paths and the | |
| job headers set up as described in part 3. | |
| 6. REAL DATASETS: NOT INCLUDED, WHERE TO OBTAIN THEM | |
| KOHTD (Kazakh handwriting) https://github.com/abdoelsayed2016/KOHTD (the authors' application form) | |
| HKR (Kazakh and Russian) https://github.com/abdoelsayed2016/HKR_Dataset (the authors' application form) | |
| School Notebooks RU https://huggingface.co/datasets/ai-forever/school_notebooks_RU | |
| Cyrillic Handwriting Dataset https://www.kaggle.com/datasets/constantinwerner/cyrillic-handwriting-dataset | |
| Azerbaijani Handwritten OCR | |
| Benchmark (LocalDoc) https://huggingface.co/datasets/LocalDoc/azerbaijani-htr-benchmark | |
| TurkishOCR-Bench https://huggingface.co/datasets/moganai/TurkishOCR-Bench | |
| RUKOPYS (Ukrainian) https://huggingface.co/datasets/UkrainianCatholicUniversity/rukopys | |
| FinePDFs (real printed lines) https://huggingface.co/datasets/HuggingFaceFW/finepdfs | |
| FineWeb-2 (generator text) https://huggingface.co/datasets/HuggingFaceFW/fineweb-2 | |
| Wikipedia (generator text) https://huggingface.co/datasets/wikimedia/wikipedia (snapshot 20231101) | |
| PP-OCRv6 medium base weights https://doi.org/10.5281/zenodo.21788410 | |
| Each dataset keeps its own licence and terms. Three further sources are read by the code but are not in the paper's | |
| reference list; their identifiers are taken from the code: | |
| Kazakh web benchmark Hugging Face dataset Omar-2002/kz_benchmark_data (scripts/r5_testpass2/tp2_kzb_fetch.py) | |
| Sakha newspaper corpus Hugging Face dataset ailabykt/sakha-corpus-mono (generator text for Sakha) | |
| Kazakh handwritten letter sheets https://github.com/Nuray-Sheriyeva/Kazakh_Handwritten_Letter_Dataset (dataset_split_v2; | |
| read by the RQ2 pixel probe) | |
| 7. EDITS MADE FOR THE PACKAGE, AND CONTENT PINS | |
| The package was made from the project's files by these edits only: absolute paths were replaced by the placeholders of | |
| part 3.1; comments and descriptive strings were reworded; the folder scripts/r5_gate was renamed; two output fields | |
| were renamed (endpoints_confirmed in the verdict written by scripts/r5eval/verdict.py, added_beyond_plan in the set | |
| registry written by scripts/r5/r5_registry.py); one verdict text of scripts/r5_freeze/dedupe_verdict.py now reads | |
| "NEEDS MANUAL REVIEW"; and scripts/r5_testpass2/tp2_make_plan.py no longer records the fingerprint of a planning note. | |
| Two pins that the code checks at run time were updated to the shipped files, so they match: | |
| src/r5eval/cards.py (label-rule pin) the content of config_r5eval/r5_descriptive_labels.txt (reworded first line), | |
| checked by scripts/r5eval/report_cards.py. | |
| src/r5eval/frozen.py (frozen-file pin) the content of src/r5eval/frozen/postproc_vlma.py (one reworded docstring line; | |
| scripts/r5_vlma/postproc.py and scripts/r5_vlmb/postproc.py are identical | |
| copies), checked whenever the scorer is imported. | |
| Four pins refer to a file that these edits changed and were left as they were: | |
| src/rq2/geom.py pins src/linedet/common.py (paths). Checked at start: the RQ2 wrappers stop | |
| with "REFUSED". After configuring the paths, put the new fingerprint of | |
| src/linedet/common.py into PINNED in src/rq2/geom.py. The same table pins | |
| four kraken files of the installed kraken package and three data files. | |
| scripts/r5_vlma/make_vlmb_testpass.py pins scripts/r5_vlmb/vlmb_eval_vlm.py (a reworded comment); it is the one-time | |
| builder of scripts/r5_vlmb/vlmb_eval_vlm_testpass.py, which also quotes that | |
| fingerprint in a comment. | |
| scripts/r5_vlma/testpass_config.json quotes the fingerprint of scripts/r5_linedet/test_pass_commands.sh (paths) in a note. | |
| All other pins inside the package still match. | |