treoa commited on
Commit
46fb086
·
verified ·
1 Parent(s): 50e673e

Add setup, tests and results; update repository text

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +1 -0
  2. .gitignore +36 -0
  3. Makefile +22 -0
  4. NOTICE +5 -5
  5. README +0 -224
  6. README.md +194 -226
  7. pyproject.toml +16 -0
  8. release/page-pipeline/infer.py +6 -6
  9. release/page-pipeline/requirements.txt +4 -4
  10. release/turkic-line-detector-yolo11s/infer.py +2 -2
  11. release/turkic-line-detector-yolo11s/requirements.txt +2 -2
  12. release/turkic-ocr-paddleocr-vl-1.6/infer.py +2 -2
  13. release/turkic-ocr-paddleocr-vl-1.6/requirements.txt +2 -2
  14. release/turkic-ocr-ppocrv6-medium/infer.py +5 -5
  15. release/turkic-ocr-ppocrv6-medium/requirements.txt +2 -2
  16. release/turkic-ocr-qwen3-vl-2b/infer.py +2 -2
  17. release/turkic-ocr-qwen3-vl-2b/requirements.txt +2 -2
  18. requirements.txt +18 -0
  19. results/figures/fig1_overview.png +3 -0
  20. results/figures/fig2_results.png +0 -0
  21. results/figures/fig3_forgetting.png +0 -0
  22. results/metrics.csv +23 -0
  23. scripts/r5/r5_build_real.py +1 -1
  24. scripts/r5_onemodel/onemodel_gate.sbatch +1 -1
  25. scripts/r5_testpass2/tp2_a1lf_kohtd.sbatch +1 -1
  26. scripts/r5_testpass2/tp2_amend2.py +1 -1
  27. scripts/r5_testpass2/tp2_amend4.py +1 -1
  28. scripts/r5_testpass2/tp2_az_latin.py +1 -1
  29. scripts/r5_testpass2/tp2_kzb_card.sbatch +1 -1
  30. scripts/r5_testpass2/tp2_kzb_fetch.py +1 -1
  31. scripts/r5_testpass2/tp2_kzb_fetch.sbatch +1 -1
  32. scripts/r5_vlma/testpass_runner.py +1 -1
  33. scripts/r5_vlmb/vlmb_runner.py +1 -1
  34. scripts/release2/decisions.json +5 -5
  35. scripts/release2/rel2_build_data.py +2 -2
  36. scripts/release2/rel2_d5_data.sbatch +1 -1
  37. scripts/release2/rel2_d5_detector_retrain.sbatch +1 -1
  38. scripts/release2/rel2_d5_prep.py +1 -1
  39. scripts/release2/rel2_d5_prep.sbatch +1 -1
  40. scripts/release2/rel2_decisions_install.sbatch +1 -1
  41. scripts/release2/rel2_parquet.py +1 -1
  42. src/pagesynth/pagesynth/fonts.py +3 -3
  43. src/pagesynth/pagesynth/langtext.py +1 -1
  44. src/pagesynth/pagesynth/scenes.py +1 -1
  45. src/pagesynth/pagesynth/vocab.py +1 -1
  46. src/rq2/aug.py +3 -3
  47. tests/data/sample_eval/evalsets.json +7 -0
  48. tests/data/sample_eval/manifests/sample_lines.tsv +11 -0
  49. tests/data/sample_eval/preds/demo/final/sample_lines.tsv +11 -0
  50. tests/test_edit_distance.py +57 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ results/figures/fig1_overview.png filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ .venv*/
6
+ .pytest_cache/
7
+ .ruff_cache/
8
+
9
+ # data, fonts, weights and run outputs at the top level (never committed)
10
+ /data/
11
+ /outputs/
12
+ /out/
13
+ /models/
14
+ /checkpoints/
15
+ /logs/
16
+ /hf_cache/
17
+ /tmp/
18
+ src/pagesynth/assets/fonts/
19
+ *.pt
20
+ *.pth
21
+ *.ckpt
22
+ *.safetensors
23
+ *.onnx
24
+ *.arpa
25
+ *.klm
26
+ *.parquet
27
+ *.zip
28
+ *.7z
29
+ *.tar
30
+ *.tgz
31
+ *.tar.gz
32
+
33
+ # editors and systems
34
+ .DS_Store
35
+ .idea/
36
+ .vscode/
Makefile ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ PYTHON ?= python3.12
2
+ VENV ?= .venv
3
+ PY = $(VENV)/bin/python
4
+ SAMPLE_OUT ?= outputs/sample_eval
5
+
6
+ .PHONY: setup test lint sample-eval
7
+
8
+ setup:
9
+ $(PYTHON) -m venv $(VENV)
10
+ $(PY) -m pip install -r requirements.txt
11
+
12
+ test:
13
+ $(PY) -m pytest
14
+
15
+ lint:
16
+ $(PY) -m ruff check tests
17
+
18
+ sample-eval:
19
+ $(PY) scripts/r5eval/score.py --preds tests/data/sample_eval/preds --registry tests/data/sample_eval/evalsets.json \
20
+ --out $(SAMPLE_OUT) --B 1000 --settle 0 --force
21
+ @grep -o '"plain":{"groups":{"all":{"n_items":[0-9]*,"n_clusters":[0-9]*,"metrics":{"cer":{[^}]*}' \
22
+ $(SAMPLE_OUT)/demo/final/sample_lines.json
NOTICE CHANGED
@@ -1,9 +1,9 @@
1
- Turkic OCR: code of the generator, training and evaluation (release candidate rc1_code)
2
 
3
- Copyright 2026 Anuar Suleimenov, Zhalgasbek Bolatov, Aidana Baglanova, Ainur Zhumabay, Anel Kadirbekova
4
 
5
- Cite as: Suleimenov, A., Bolatov, Z., Baglanova, A., Zhumabay, A., Kadirbekova, A. (2026). A Handwriting Recognition
6
- Model for Turkic Languages in Latin and Cyrillic Script. Project report, Nazarbayev University.
7
 
8
 
9
  LICENCES
@@ -49,7 +49,7 @@ THIRD-PARTY SOFTWARE NOT INCLUDED
49
 
50
  The code imports third-party packages (PyTorch, Hugging Face Transformers, kraken, Ultralytics, KenLM, PaddleOCR and others)
51
  that are installed separately under their own licences; the environments/ folder lists the versions used.
52
- The PP-OCRv3 reference re-run (scripts/r5_ref, arm R2) expects PaddleOCR release v2.10.0
53
  (7 March 2025) of https://github.com/PaddlePaddle/PaddleOCR (Apache-2.0) in the folder under src/ref/ that
54
  scripts/r5_ref/ref_common.py sets (PPOCR_ROOT); it is not included.
55
 
 
1
+ Turkic OCR: code of the generator, training and evaluation
2
 
3
+ Copyright 2026 the authors of the project report
4
 
5
+ Cite as: A Handwriting Recognition Model for Turkic Languages in Latin and Cyrillic Script. Project report, Nazarbayev
6
+ University, 2026.
7
 
8
 
9
  LICENCES
 
49
 
50
  The code imports third-party packages (PyTorch, Hugging Face Transformers, kraken, Ultralytics, KenLM, PaddleOCR and others)
51
  that are installed separately under their own licences; the environments/ folder lists the versions used.
52
+ The PP-OCRv3 reference re-run (scripts/r5_ref) expects PaddleOCR release v2.10.0
53
  (7 March 2025) of https://github.com/PaddlePaddle/PaddleOCR (Apache-2.0) in the folder under src/ref/ that
54
  scripts/r5_ref/ref_common.py sets (PPOCR_ROOT); it is not included.
55
 
README DELETED
@@ -1,224 +0,0 @@
1
- TURKIC OCR: CODE OF THE GENERATOR, TRAINING AND EVALUATION
2
- (release candidate rc1_code)
3
-
4
- This package holds the code behind the project report
5
-
6
- Suleimenov, A., Bolatov, Z., Baglanova, A., Zhumabay, A., Kadirbekova, A. (2026). A Handwriting Recognition Model
7
- for Turkic Languages in Latin and Cyrillic Script. Project report, Nazarbayev University.
8
-
9
- @techreport{suleimenov2026turkic,
10
- author = {Suleimenov, Anuar and Bolatov, Zhalgasbek and Baglanova, Aidana and Zhumabay, Ainur and Kadirbekova, Anel},
11
- title = {A Handwriting Recognition Model for Turkic Languages in Latin and Cyrillic Script},
12
- institution = {Nazarbayev University},
13
- type = {Project report},
14
- year = {2026}
15
- }
16
-
17
- It contains the page and line generator (pagesynth 0.3.0) with its text filters, the builders of the real-data
18
- manifests and of the training mix, the training code of the vision-language readers and of the CTC line recognizers,
19
- the training and inference code of the line detector, the scorer with its bootstrap intervals and selection rules, the
20
- test-pass and page-scoring scripts, the inference scripts of the release packages, and the code of the planned RQ2
21
- augmentation study. "The paper" below means the report cited above; section numbers refer to it (S1 to S11 are the
22
- sections of its supplementary material). Comments in the code name the project's work stages in capitals (for example
23
- GEN for the generator, DATA for the real-data manifests, PRINT, FREEZE, LINEDET, REF, VLMA, VLMB, EVALCODE) and use the
24
- round name R5 for the run that produced the paper's results.
25
-
26
-
27
- 1. WHAT IS NOT IN THIS PACKAGE
28
-
29
- - No data. None of the real datasets is included, and neither are the project's generated data, manifests, splits or
30
- predictions. Where to obtain the real datasets is listed in part 6. The generated data are released separately under
31
- CC BY-SA 4.0.
32
- - No reader weights. The fine-tuned weights of the three readers (PaddleOCR-VL-1.6, the final model; Qwen3-VL-2B; and
33
- the PP-OCRv6-medium line recognizer with its character language model) are not released. They were trained on KOHTD
34
- and HKR, whose terms limit use to the applicant's group and to academic research, and their authors have not given
35
- permission to share models trained on them. The code here lets others train their own readers from the released
36
- generated data and the real datasets obtained from their sources.
37
- - The line detector's weights are released separately, with this code path, under AGPL-3.0.
38
- - No font files. The generator needs the 73 fonts listed in src/pagesynth/assets/fonts_manifest.tsv (file name,
39
- licence class, and whether the font is held out of training). Place them in src/pagesynth/assets/fonts/ or
40
- point the environment variable PAGESYNTH_FONTS to their folder. Eight of them are personal-use fonts (licence class
41
- personal_use_only); they may not be redistributed, and the released generated data contain no item drawn with them.
42
- - Not included: the vendored PaddleOCR source used only by the PP-OCRv3 reference re-run (see NOTICE), earlier
43
- 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
44
- scripts, one-off probes, the corrector pilot (never trained), the unfinished full-schedule PP-OCRv3 re-run, and the
45
- download and extraction scripts of KOHTD, which need access credentials from its authors.
46
- - config_r5eval/sota_checklist.json is not included. scripts/r5_select_verdict.sbatch passes it to
47
- scripts/r5eval/verdict.py; remove that argument (verdict.py runs without it) or supply your own checklist.
48
-
49
-
50
- 2. LICENCES
51
-
52
- Apache-2.0 (LICENSE) for everything except: the line detector's training and inference path and the page pipeline,
53
- which are AGPL-3.0 (LICENSE.AGPL-3.0; the files are listed in NOTICE); the vendored HTR-Flor copy in
54
- src/ref/ (repository state of 23 June 2021; MIT, its own LICENSE); and the Natural Earth map files in
55
- src/pagesynth/assets/naturalearth/ (public domain). Copyright and third-party notices are in NOTICE.
56
-
57
-
58
- 3. SETTING UP
59
-
60
- 3.1 Paths. The code ran on a Slurm cluster with one code folder and one data folder. Every absolute path in the
61
- package now starts with a placeholder:
62
-
63
- /path/to/TURKIC_OCR_CODE the folder that holds this package (src/, scripts/, ... and the virtual environments)
64
- /path/to/TURKIC_OCR_DATA the data folder, with data/raw, data/processed, outputs, checkpoints, logs, hf_cache, tmp
65
-
66
- Replace both with your own folders before running anything, for example:
67
-
68
- grep -rlF /path/to/TURKIC_OCR_CODE . | xargs sed -i 's#/path/to/TURKIC_OCR_CODE#/home/me/turkic_ocr#g'
69
- grep -rlF /path/to/TURKIC_OCR_DATA . | xargs sed -i 's#/path/to/TURKIC_OCR_DATA#/data/turkic_ocr#g'
70
-
71
- Neither placeholder is a prefix of the other, so the order does not matter. The Slurm headers name
72
- the partitions (H100, ZEN4) and quality-of-service names of the original cluster; adapt them to yours. Many scripts
73
- and comments refer to the project's working records (paths that begin with records/, or files under the data folder
74
- such as manifests and score files); these records are not part of this package.
75
-
76
- 3.2 Python environments. The scripts call the interpreter of a project environment, for example
77
- /path/to/TURKIC_OCR_CODE/.venv_gen/bin/python. The folder environments/ holds the exact package list of each
78
- environment, made with 'uv pip freeze'. To rebuild one:
79
-
80
- uv venv --python 3.12 /path/to/TURKIC_OCR_CODE/.venv_gen
81
- uv pip install --python /path/to/TURKIC_OCR_CODE/.venv_gen/bin/python -r environments/venv_gen.requirements
82
-
83
- PyTorch builds with a +cu suffix in the lists come from the PyTorch package index (add
84
- --extra-index-url https://download.pytorch.org/whl/<cuda tag>, the tag matching the suffix).
85
-
86
- environment (file) Python main use
87
- .venv (venv.requirements) 3.12 real-data manifests (scripts/r5), KOHTD split and leak checks, zero-shot screen
88
- .venv_gen (venv_gen.requirements) 3.12 generator, training-mix freeze, release data build
89
- .venv_kraken 3.12 CTC line recognizers, letter model, detector, scorer jobs, test pass 2, RQ2
90
- .venv_vlm 3.12 vision-language training and evaluation (scripts/r5_vlma), single page model,
91
- loop guard, page check, showcase
92
- .venv_vlm_<model> (9 files) 3.12 * one per extra candidate in scripts/r5_vlmb (* unlimited_ocr_2: 3.10)
93
- .venv_print 3.12 real printed lines (scripts/r5_print)
94
- .venv_ref_tf 3.11 HTR-Flor reference re-run (R1)
95
- .venv_ref_paddle, .venv_ref_paddle_cpu 3.11 PP-OCRv3 reference re-run (R2)
96
- .venv_dl see file download tools (Kazakh web benchmark)
97
-
98
- The exact Python version of each environment is in its file's first line. Each shell and sbatch file names the
99
- environment its step used. The release packages in release/ carry their own requirements.txt.
100
-
101
-
102
- 4. FOLDERS AND WHERE THEY APPEAR IN THE PAPER
103
-
104
- src/pagesynth/ Page and line generator 0.3.0: text cleaning and filters (text.py, langtext.py,
105
- textbuild.py, vocab.py), fonts and the glyph gate, the simulated writer, layouts, paper,
106
- marks, maps, capture, cropping; produce_r5.py and scripts/ run the text build, the text
107
- split by source document and the production. Paper: Section 2.2, S2.
108
- src/linedet/ CTC line recognizers (PP-OCRv6 medium and small, CRNN, HTR-VT-style model), training
109
- driver, prediction, the character 6-gram letter model with beam search and its gate, and
110
- (det_*.py, AGPL-3.0) the YOLO11s line detector: data preparation, training, evaluation.
111
- Paper: Sections 3.4 and 3.5, S6, S9, S10.
112
- src/r5eval/, scripts/r5eval/ Scorer: text normalisation, CER and WER, look-alike repair, form-level bootstrap,
113
- config_r5eval/, tests_r5eval/ Holm correction, selection of leaders and of the final model, decision rules, report
114
- cards; with its configuration and tests. Paper: Section 4, S7.
115
- scripts/r5_score.sbatch and Scoring, selection, verdict, learning-curve and self-test jobs of the scorer.
116
- the other scripts/r5_*.sbatch Paper: Section 4, S7.
117
- scripts/r5_gate/ Gate files that kept the test sets sealed until the single test pass. Paper: Section 4, S7.
118
- scripts/r5/ Real-data manifests (KOHTD, HKR, Cyrillic Handwriting Dataset, School Notebooks, RUKOPYS,
119
- LocalDoc), de-duplication against held-out images, the registry of training, validation
120
- and test sets, validation subsets and the unseen-word slice. Paper: Section 2.1, S1, S4, S7.
121
- scripts/k1_labels_all.py, KOHTD split by exam form (a salted deterministic function of the form number). Paper: Section 2.1, S4.
122
- scripts/k1_build_split.py
123
- scripts/kohtd_leak_* Checks that no KOHTD training crop without a form number is a copy of a validation or
124
- test crop. Paper: S4.
125
- scripts/r5_print/ Real printed lines: candidate PDFs from FinePDFs, text-layer check, line cutting, pixel
126
- checks, split by document. Paper: Section 2.1, S3.
127
- scripts/r5_freeze/ Freeze of the training mix (shares, de-duplication against held-out sets, sample
128
- sequences). Paper: Section 2.3, S2.
129
- scripts/j2/ Zero-shot screen of released document models on KOHTD validation words. Paper: Section 3.2.
130
- scripts/r5_vlma/ Fine-tuning and evaluation of the vision-language readers (shared recipe, short and long
131
- runs, slot runners), preference post-training (DPO, GRPO), and the sealed test pass.
132
- Paper: Sections 3.2, 3.3 and 4, S5, S6, S7.
133
- scripts/r5_vlmb/ Adapters, environments and runner for the extra vision-language candidates. Paper: S5, S6.
134
- scripts/r5_linedet/ Jobs of the line recognizers, the detector and the letter model. Paper: Sections 3.4, 3.5, S6.
135
- scripts/r5_ref/, src/ref/ Reference re-runs: HTR-Flor (R1, vendored copy in src/ref/) and PP-OCRv3 (R2, PaddleOCR
136
- not included). Paper: Section 5, S10.
137
- scripts/r5_testpass2/ Second test pass and its amendments: real handwriting and print tests, page tests
138
- (TurkishOCR-Bench, Kazakh web benchmark), label-free re-reading of the line recognizer,
139
- per-language tables, error analysis. Paper: Section 5, S7, S8, S9.
140
- scripts/tp2_proposal_metrics.py Measures for the research questions. Paper: Section 6.1, S8.
141
- scripts/r5_erran/ Error analysis of validation outputs (label errors, ambiguous handwriting). Paper: S7.
142
- scripts/b1_page_check/ Page check: the final model on whole pages, alone and after the detector. Paper: S9.
143
- scripts/r5_onemodel/ Single page model: page records, training, page scoring. Paper: S6, S9.
144
- scripts/r5_loopguard/ Loop guard for the single page model. Paper: S9, S10.
145
- scripts/r5_showcase/ Showcase pages: the generator stages of chosen validation pages (material for Figure 2)
146
- and pages read by the pipeline. Paper: Section 2.2, S11.
147
- scripts/r5_release/ Checks of the first release candidate, including the batching diagnostic of the line
148
- recognizer. Paper: S7 (the batching leak).
149
- scripts/release2/ Release build: data package, Parquet shards, regeneration check of every released page,
150
- Sakha-text check, cards and file verification; rel2_d5_* (AGPL-3.0) retrain and check the
151
- released detector without the personal-use-font pages. Paper: S11.
152
- release/ Inference scripts and requirements of the release packages: the three readers (whose
153
- weights are not released), the line detector and the page pipeline (AGPL-3.0). Paper: S11.
154
- src/rq2/, scripts/r5_rq2/, RQ2 augmentation study (line height 32 or 64 px crossed with a typical or a diacritic-safe
155
- src/lettersynth/ augmentation policy) and its pixel probe; src/lettersynth holds only the letter-sheet
156
- reader that the probe uses. This code was written after the paper's results; the paper
157
- states that the study was not run, and no RQ2 result is part of it.
158
- environments/ Package lists of the Python environments (part 3.2).
159
-
160
-
161
- 5. KNOWN ISSUES
162
-
163
- - Content pins. Some files pin the exact content of other files as it was on the cluster, and a few check it at start.
164
- Making the paths configurable changed some pinned files, so those pins no longer match (the list of affected pins
165
- is in part 7). Update the pinned values after configuring the paths, or skip the check.
166
- - release/turkic-ocr-ppocrv6-medium/infer.py is the inference script of the withheld PP-OCRv6 package. Its docstring
167
- was written before the corrections the paper reports in S7 (the batching leak) and was not updated; the paper's
168
- figures supersede the ones it quotes.
169
- - The generator reproduces the content of a page from its seed but not every byte (paper, S11).
170
- - The scripts were written for one cluster and one run of the project: many take their inputs from fixed paths and
171
- write records of that run. They document what was done; running them elsewhere needs the data, the paths and the
172
- job headers set up as described in part 3.
173
-
174
-
175
- 6. REAL DATASETS: NOT INCLUDED, WHERE TO OBTAIN THEM
176
-
177
- KOHTD (Kazakh handwriting) https://github.com/abdoelsayed2016/KOHTD (the authors' application form)
178
- HKR (Kazakh and Russian) https://github.com/abdoelsayed2016/HKR_Dataset (the authors' application form)
179
- School Notebooks RU https://huggingface.co/datasets/ai-forever/school_notebooks_RU
180
- Cyrillic Handwriting Dataset https://www.kaggle.com/datasets/constantinwerner/cyrillic-handwriting-dataset
181
- Azerbaijani Handwritten OCR
182
- Benchmark (LocalDoc) https://huggingface.co/datasets/LocalDoc/azerbaijani-htr-benchmark
183
- TurkishOCR-Bench https://huggingface.co/datasets/moganai/TurkishOCR-Bench
184
- RUKOPYS (Ukrainian) https://huggingface.co/datasets/UkrainianCatholicUniversity/rukopys
185
- FinePDFs (real printed lines) https://huggingface.co/datasets/HuggingFaceFW/finepdfs
186
- FineWeb-2 (generator text) https://huggingface.co/datasets/HuggingFaceFW/fineweb-2
187
- Wikipedia (generator text) https://huggingface.co/datasets/wikimedia/wikipedia (snapshot 20231101)
188
- PP-OCRv6 medium base weights https://doi.org/10.5281/zenodo.21788410
189
-
190
- Each dataset keeps its own licence and terms. Three further sources are read by the code but are not in the paper's
191
- reference list; their identifiers are taken from the code:
192
- Kazakh web benchmark Hugging Face dataset Omar-2002/kz_benchmark_data (scripts/r5_testpass2/tp2_kzb_fetch.py)
193
- Sakha newspaper corpus Hugging Face dataset ailabykt/sakha-corpus-mono (generator text for Sakha)
194
- Kazakh handwritten letter sheets https://github.com/Nuray-Sheriyeva/Kazakh_Handwritten_Letter_Dataset (dataset_split_v2;
195
- read by the RQ2 pixel probe)
196
-
197
-
198
- 7. EDITS MADE FOR THE PACKAGE, AND CONTENT PINS
199
-
200
- The package was made from the project's files by these edits only: absolute paths were replaced by the placeholders of
201
- part 3.1; comments and descriptive strings were reworded; the folder scripts/r5_gate was renamed; two output fields
202
- were renamed (endpoints_confirmed in the verdict written by scripts/r5eval/verdict.py, added_beyond_plan in the set
203
- registry written by scripts/r5/r5_registry.py); one verdict text of scripts/r5_freeze/dedupe_verdict.py now reads
204
- "NEEDS MANUAL REVIEW"; and scripts/r5_testpass2/tp2_make_plan.py no longer records the fingerprint of a planning note.
205
-
206
- Two pins that the code checks at run time were updated to the shipped files, so they match:
207
- src/r5eval/cards.py (label-rule pin) the content of config_r5eval/r5_descriptive_labels.txt (reworded first line),
208
- checked by scripts/r5eval/report_cards.py.
209
- src/r5eval/frozen.py (frozen-file pin) the content of src/r5eval/frozen/postproc_vlma.py (one reworded docstring line;
210
- scripts/r5_vlma/postproc.py and scripts/r5_vlmb/postproc.py are identical
211
- copies), checked whenever the scorer is imported.
212
-
213
- Four pins refer to a file that these edits changed and were left as they were:
214
-
215
- src/rq2/geom.py pins src/linedet/common.py (paths). Checked at start: the RQ2 wrappers stop
216
- with "REFUSED". After configuring the paths, put the new fingerprint of
217
- src/linedet/common.py into PINNED in src/rq2/geom.py. The same table pins
218
- four kraken files of the installed kraken package and three data files.
219
- scripts/r5_vlma/make_vlmb_testpass.py pins scripts/r5_vlmb/vlmb_eval_vlm.py (a reworded comment); it is the one-time
220
- builder of scripts/r5_vlmb/vlmb_eval_vlm_testpass.py, which also quotes that
221
- fingerprint in a comment.
222
- scripts/r5_vlma/testpass_config.json quotes the fingerprint of scripts/r5_linedet/test_pass_commands.sh (paths) in a note.
223
-
224
- All other pins inside the package still match.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
- # Licence: Apache-2.0 for the package, except the line detector's training and inference path and the page
3
- # pipeline, which are AGPL-3.0 (LICENSE.AGPL-3.0; the files are listed in NOTICE); see also README part 2.
4
  license: apache-2.0
5
  language:
6
  - kk
@@ -25,227 +25,195 @@ tags:
25
  - latin-script
26
  ---
27
 
28
- TURKIC OCR: CODE OF THE GENERATOR, TRAINING AND EVALUATION
29
- (release candidate rc1_code)
30
-
31
- This package holds the code behind the project report
32
-
33
- Suleimenov, A., Bolatov, Z., Baglanova, A., Zhumabay, A., Kadirbekova, A. (2026). A Handwriting Recognition Model
34
- for Turkic Languages in Latin and Cyrillic Script. Project report, Nazarbayev University.
35
-
36
- @techreport{suleimenov2026turkic,
37
- author = {Suleimenov, Anuar and Bolatov, Zhalgasbek and Baglanova, Aidana and Zhumabay, Ainur and Kadirbekova, Anel},
38
- title = {A Handwriting Recognition Model for Turkic Languages in Latin and Cyrillic Script},
39
- institution = {Nazarbayev University},
40
- type = {Project report},
41
- year = {2026}
42
- }
43
-
44
- It contains the page and line generator (pagesynth 0.3.0) with its text filters, the builders of the real-data
45
- manifests and of the training mix, the training code of the vision-language readers and of the CTC line recognizers,
46
- the training and inference code of the line detector, the scorer with its bootstrap intervals and selection rules, the
47
- test-pass and page-scoring scripts, the inference scripts of the release packages, and the code of the planned RQ2
48
- augmentation study. "The paper" below means the report cited above; section numbers refer to it (S1 to S11 are the
49
- sections of its supplementary material). Comments in the code name the project's work stages in capitals (for example
50
- GEN for the generator, DATA for the real-data manifests, PRINT, FREEZE, LINEDET, REF, VLMA, VLMB, EVALCODE) and use the
51
- round name R5 for the run that produced the paper's results.
52
-
53
-
54
- 1. WHAT IS NOT IN THIS PACKAGE
55
-
56
- - No data. None of the real datasets is included, and neither are the project's generated data, manifests, splits or
57
- predictions. Where to obtain the real datasets is listed in part 6. The generated data are released separately under
58
- CC BY-SA 4.0.
59
- - No reader weights. The fine-tuned weights of the three readers (PaddleOCR-VL-1.6, the final model; Qwen3-VL-2B; and
60
- the PP-OCRv6-medium line recognizer with its character language model) are not released. They were trained on KOHTD
61
- and HKR, whose terms limit use to the applicant's group and to academic research, and their authors have not given
62
- permission to share models trained on them. The code here lets others train their own readers from the released
63
- generated data and the real datasets obtained from their sources.
64
- - The line detector's weights are released separately, with this code path, under AGPL-3.0.
65
- - No font files. The generator needs the 73 fonts listed in src/pagesynth/assets/fonts_manifest.tsv (file name,
66
- licence class, and whether the font is held out of training). Place them in src/pagesynth/assets/fonts/ or
67
- point the environment variable PAGESYNTH_FONTS to their folder. Eight of them are personal-use fonts (licence class
68
- personal_use_only); they may not be redistributed, and the released generated data contain no item drawn with them.
69
- - Not included: the vendored PaddleOCR source used only by the PP-OCRv3 reference re-run (see NOTICE), earlier
70
- 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
71
- scripts, one-off probes, the corrector pilot (never trained), the unfinished full-schedule PP-OCRv3 re-run, and the
72
- download and extraction scripts of KOHTD, which need access credentials from its authors.
73
- - config_r5eval/sota_checklist.json is not included. scripts/r5_select_verdict.sbatch passes it to
74
- scripts/r5eval/verdict.py; remove that argument (verdict.py runs without it) or supply your own checklist.
75
-
76
-
77
- 2. LICENCES
78
-
79
- Apache-2.0 (LICENSE) for everything except: the line detector's training and inference path and the page pipeline,
80
- which are AGPL-3.0 (LICENSE.AGPL-3.0; the files are listed in NOTICE); the vendored HTR-Flor copy in
81
- src/ref/ (repository state of 23 June 2021; MIT, its own LICENSE); and the Natural Earth map files in
82
- src/pagesynth/assets/naturalearth/ (public domain). Copyright and third-party notices are in NOTICE.
83
-
84
-
85
- 3. SETTING UP
86
-
87
- 3.1 Paths. The code ran on a Slurm cluster with one code folder and one data folder. Every absolute path in the
88
- package now starts with a placeholder:
89
-
90
- /path/to/TURKIC_OCR_CODE the folder that holds this package (src/, scripts/, ... and the virtual environments)
91
- /path/to/TURKIC_OCR_DATA the data folder, with data/raw, data/processed, outputs, checkpoints, logs, hf_cache, tmp
92
-
93
- Replace both with your own folders before running anything, for example:
94
-
95
- grep -rlF /path/to/TURKIC_OCR_CODE . | xargs sed -i 's#/path/to/TURKIC_OCR_CODE#/home/me/turkic_ocr#g'
96
- grep -rlF /path/to/TURKIC_OCR_DATA . | xargs sed -i 's#/path/to/TURKIC_OCR_DATA#/data/turkic_ocr#g'
97
-
98
- Neither placeholder is a prefix of the other, so the order does not matter. The Slurm headers name
99
- the partitions (H100, ZEN4) and quality-of-service names of the original cluster; adapt them to yours. Many scripts
100
- and comments refer to the project's working records (paths that begin with records/, or files under the data folder
101
- such as manifests and score files); these records are not part of this package.
102
-
103
- 3.2 Python environments. The scripts call the interpreter of a project environment, for example
104
- /path/to/TURKIC_OCR_CODE/.venv_gen/bin/python. The folder environments/ holds the exact package list of each
105
- environment, made with 'uv pip freeze'. To rebuild one:
106
-
107
- uv venv --python 3.12 /path/to/TURKIC_OCR_CODE/.venv_gen
108
- uv pip install --python /path/to/TURKIC_OCR_CODE/.venv_gen/bin/python -r environments/venv_gen.requirements
109
-
110
- PyTorch builds with a +cu suffix in the lists come from the PyTorch package index (add
111
- --extra-index-url https://download.pytorch.org/whl/<cuda tag>, the tag matching the suffix).
112
-
113
- environment (file) Python main use
114
- .venv (venv.requirements) 3.12 real-data manifests (scripts/r5), KOHTD split and leak checks, zero-shot screen
115
- .venv_gen (venv_gen.requirements) 3.12 generator, training-mix freeze, release data build
116
- .venv_kraken 3.12 CTC line recognizers, letter model, detector, scorer jobs, test pass 2, RQ2
117
- .venv_vlm 3.12 vision-language training and evaluation (scripts/r5_vlma), single page model,
118
- loop guard, page check, showcase
119
- .venv_vlm_<model> (9 files) 3.12 * one per extra candidate in scripts/r5_vlmb (* unlimited_ocr_2: 3.10)
120
- .venv_print 3.12 real printed lines (scripts/r5_print)
121
- .venv_ref_tf 3.11 HTR-Flor reference re-run (R1)
122
- .venv_ref_paddle, .venv_ref_paddle_cpu 3.11 PP-OCRv3 reference re-run (R2)
123
- .venv_dl see file download tools (Kazakh web benchmark)
124
-
125
- The exact Python version of each environment is in its file's first line. Each shell and sbatch file names the
126
- environment its step used. The release packages in release/ carry their own requirements.txt.
127
-
128
-
129
- 4. FOLDERS AND WHERE THEY APPEAR IN THE PAPER
130
-
131
- src/pagesynth/ Page and line generator 0.3.0: text cleaning and filters (text.py, langtext.py,
132
- textbuild.py, vocab.py), fonts and the glyph gate, the simulated writer, layouts, paper,
133
- marks, maps, capture, cropping; produce_r5.py and scripts/ run the text build, the text
134
- split by source document and the production. Paper: Section 2.2, S2.
135
- src/linedet/ CTC line recognizers (PP-OCRv6 medium and small, CRNN, HTR-VT-style model), training
136
- driver, prediction, the character 6-gram letter model with beam search and its gate, and
137
- (det_*.py, AGPL-3.0) the YOLO11s line detector: data preparation, training, evaluation.
138
- Paper: Sections 3.4 and 3.5, S6, S9, S10.
139
- src/r5eval/, scripts/r5eval/ Scorer: text normalisation, CER and WER, look-alike repair, form-level bootstrap,
140
- config_r5eval/, tests_r5eval/ Holm correction, selection of leaders and of the final model, decision rules, report
141
- cards; with its configuration and tests. Paper: Section 4, S7.
142
- scripts/r5_score.sbatch and Scoring, selection, verdict, learning-curve and self-test jobs of the scorer.
143
- the other scripts/r5_*.sbatch Paper: Section 4, S7.
144
- scripts/r5_gate/ Gate files that kept the test sets sealed until the single test pass. Paper: Section 4, S7.
145
- scripts/r5/ Real-data manifests (KOHTD, HKR, Cyrillic Handwriting Dataset, School Notebooks, RUKOPYS,
146
- LocalDoc), de-duplication against held-out images, the registry of training, validation
147
- and test sets, validation subsets and the unseen-word slice. Paper: Section 2.1, S1, S4, S7.
148
- scripts/k1_labels_all.py, KOHTD split by exam form (a salted deterministic function of the form number). Paper: Section 2.1, S4.
149
- scripts/k1_build_split.py
150
- scripts/kohtd_leak_* Checks that no KOHTD training crop without a form number is a copy of a validation or
151
- test crop. Paper: S4.
152
- scripts/r5_print/ Real printed lines: candidate PDFs from FinePDFs, text-layer check, line cutting, pixel
153
- checks, split by document. Paper: Section 2.1, S3.
154
- scripts/r5_freeze/ Freeze of the training mix (shares, de-duplication against held-out sets, sample
155
- sequences). Paper: Section 2.3, S2.
156
- scripts/j2/ Zero-shot screen of released document models on KOHTD validation words. Paper: Section 3.2.
157
- scripts/r5_vlma/ Fine-tuning and evaluation of the vision-language readers (shared recipe, short and long
158
- runs, slot runners), preference post-training (DPO, GRPO), and the sealed test pass.
159
- Paper: Sections 3.2, 3.3 and 4, S5, S6, S7.
160
- scripts/r5_vlmb/ Adapters, environments and runner for the extra vision-language candidates. Paper: S5, S6.
161
- scripts/r5_linedet/ Jobs of the line recognizers, the detector and the letter model. Paper: Sections 3.4, 3.5, S6.
162
- scripts/r5_ref/, src/ref/ Reference re-runs: HTR-Flor (R1, vendored copy in src/ref/) and PP-OCRv3 (R2, PaddleOCR
163
- not included). Paper: Section 5, S10.
164
- scripts/r5_testpass2/ Second test pass and its amendments: real handwriting and print tests, page tests
165
- (TurkishOCR-Bench, Kazakh web benchmark), label-free re-reading of the line recognizer,
166
- per-language tables, error analysis. Paper: Section 5, S7, S8, S9.
167
- scripts/tp2_proposal_metrics.py Measures for the research questions. Paper: Section 6.1, S8.
168
- scripts/r5_erran/ Error analysis of validation outputs (label errors, ambiguous handwriting). Paper: S7.
169
- scripts/b1_page_check/ Page check: the final model on whole pages, alone and after the detector. Paper: S9.
170
- scripts/r5_onemodel/ Single page model: page records, training, page scoring. Paper: S6, S9.
171
- scripts/r5_loopguard/ Loop guard for the single page model. Paper: S9, S10.
172
- scripts/r5_showcase/ Showcase pages: the generator stages of chosen validation pages (material for Figure 2)
173
- and pages read by the pipeline. Paper: Section 2.2, S11.
174
- scripts/r5_release/ Checks of the first release candidate, including the batching diagnostic of the line
175
- recognizer. Paper: S7 (the batching leak).
176
- scripts/release2/ Release build: data package, Parquet shards, regeneration check of every released page,
177
- Sakha-text check, cards and file verification; rel2_d5_* (AGPL-3.0) retrain and check the
178
- released detector without the personal-use-font pages. Paper: S11.
179
- release/ Inference scripts and requirements of the release packages: the three readers (whose
180
- weights are not released), the line detector and the page pipeline (AGPL-3.0). Paper: S11.
181
- src/rq2/, scripts/r5_rq2/, RQ2 augmentation study (line height 32 or 64 px crossed with a typical or a diacritic-safe
182
- src/lettersynth/ augmentation policy) and its pixel probe; src/lettersynth holds only the letter-sheet
183
- reader that the probe uses. This code was written after the paper's results; the paper
184
- states that the study was not run, and no RQ2 result is part of it.
185
- environments/ Package lists of the Python environments (part 3.2).
186
-
187
-
188
- 5. KNOWN ISSUES
189
-
190
- - Content pins. Some files pin the exact content of other files as it was on the cluster, and a few check it at start.
191
- Making the paths configurable changed some pinned files, so those pins no longer match (the list of affected pins
192
- is in part 7). Update the pinned values after configuring the paths, or skip the check.
193
- - release/turkic-ocr-ppocrv6-medium/infer.py is the inference script of the withheld PP-OCRv6 package. Its docstring
194
- was written before the corrections the paper reports in S7 (the batching leak) and was not updated; the paper's
195
- figures supersede the ones it quotes.
196
- - The generator reproduces the content of a page from its seed but not every byte (paper, S11).
197
- - The scripts were written for one cluster and one run of the project: many take their inputs from fixed paths and
198
- write records of that run. They document what was done; running them elsewhere needs the data, the paths and the
199
- job headers set up as described in part 3.
200
-
201
-
202
- 6. REAL DATASETS: NOT INCLUDED, WHERE TO OBTAIN THEM
203
-
204
- KOHTD (Kazakh handwriting) https://github.com/abdoelsayed2016/KOHTD (the authors' application form)
205
- HKR (Kazakh and Russian) https://github.com/abdoelsayed2016/HKR_Dataset (the authors' application form)
206
- School Notebooks RU https://huggingface.co/datasets/ai-forever/school_notebooks_RU
207
- Cyrillic Handwriting Dataset https://www.kaggle.com/datasets/constantinwerner/cyrillic-handwriting-dataset
208
- Azerbaijani Handwritten OCR
209
- Benchmark (LocalDoc) https://huggingface.co/datasets/LocalDoc/azerbaijani-htr-benchmark
210
- TurkishOCR-Bench https://huggingface.co/datasets/moganai/TurkishOCR-Bench
211
- RUKOPYS (Ukrainian) https://huggingface.co/datasets/UkrainianCatholicUniversity/rukopys
212
- FinePDFs (real printed lines) https://huggingface.co/datasets/HuggingFaceFW/finepdfs
213
- FineWeb-2 (generator text) https://huggingface.co/datasets/HuggingFaceFW/fineweb-2
214
- Wikipedia (generator text) https://huggingface.co/datasets/wikimedia/wikipedia (snapshot 20231101)
215
- PP-OCRv6 medium base weights https://doi.org/10.5281/zenodo.21788410
216
-
217
- Each dataset keeps its own licence and terms. Three further sources are read by the code but are not in the paper's
218
- reference list; their identifiers are taken from the code:
219
- Kazakh web benchmark Hugging Face dataset Omar-2002/kz_benchmark_data (scripts/r5_testpass2/tp2_kzb_fetch.py)
220
- Sakha newspaper corpus Hugging Face dataset ailabykt/sakha-corpus-mono (generator text for Sakha)
221
- Kazakh handwritten letter sheets https://github.com/Nuray-Sheriyeva/Kazakh_Handwritten_Letter_Dataset (dataset_split_v2;
222
- read by the RQ2 pixel probe)
223
-
224
-
225
- 7. EDITS MADE FOR THE PACKAGE, AND CONTENT PINS
226
-
227
- The package was made from the project's files by these edits only: absolute paths were replaced by the placeholders of
228
- part 3.1; comments and descriptive strings were reworded; the folder scripts/r5_gate was renamed; two output fields
229
- were renamed (endpoints_confirmed in the verdict written by scripts/r5eval/verdict.py, added_beyond_plan in the set
230
- registry written by scripts/r5/r5_registry.py); one verdict text of scripts/r5_freeze/dedupe_verdict.py now reads
231
- "NEEDS MANUAL REVIEW"; and scripts/r5_testpass2/tp2_make_plan.py no longer records the fingerprint of a planning note.
232
-
233
- Two pins that the code checks at run time were updated to the shipped files, so they match:
234
- src/r5eval/cards.py (label-rule pin) the content of config_r5eval/r5_descriptive_labels.txt (reworded first line),
235
- checked by scripts/r5eval/report_cards.py.
236
- src/r5eval/frozen.py (frozen-file pin) the content of src/r5eval/frozen/postproc_vlma.py (one reworded docstring line;
237
- scripts/r5_vlma/postproc.py and scripts/r5_vlmb/postproc.py are identical
238
- copies), checked whenever the scorer is imported.
239
-
240
- Four pins refer to a file that these edits changed and were left as they were:
241
-
242
- src/rq2/geom.py pins src/linedet/common.py (paths). Checked at start: the RQ2 wrappers stop
243
- with "REFUSED". After configuring the paths, put the new fingerprint of
244
- src/linedet/common.py into PINNED in src/rq2/geom.py. The same table pins
245
- four kraken files of the installed kraken package and three data files.
246
- scripts/r5_vlma/make_vlmb_testpass.py pins scripts/r5_vlmb/vlmb_eval_vlm.py (a reworded comment); it is the one-time
247
- builder of scripts/r5_vlmb/vlmb_eval_vlm_testpass.py, which also quotes that
248
- fingerprint in a comment.
249
- scripts/r5_vlma/testpass_config.json quotes the fingerprint of scripts/r5_linedet/test_pass_commands.sh (paths) in a note.
250
-
251
- All other pins inside the package still match.
 
1
  ---
2
+ # Apache-2.0 for the package, except the line detector's training and inference path and the page pipeline,
3
+ # which are AGPL-3.0 (LICENSE.AGPL-3.0; the files are listed in NOTICE).
4
  license: apache-2.0
5
  language:
6
  - kk
 
25
  - latin-script
26
  ---
27
 
28
+ # Turkic OCR: generator, training and evaluation code
29
+
30
+ This is the code behind one text reader for typed and handwritten text in nine Turkic languages: Kazakh, Kyrgyz,
31
+ Tatar, Bashkir and Sakha in Cyrillic, Turkish, Azerbaijani and Turkmen in Latin, and Uzbek in both scripts. A YOLO11s
32
+ detector finds the text lines on a page, and a fine-tuned PaddleOCR-VL-1.6 reads each line. Of the nine languages only
33
+ Kazakh has real handwriting to train on, so a page generator, pagesynth 0.3.0, writes real sentences onto simulated
34
+ school pages with exact line labels. The work is described in
35
+
36
+ > A Handwriting Recognition Model for Turkic Languages in Latin and Cyrillic Script. Project report, Nazarbayev
37
+ > University, 2026.
38
+
39
+ ```bibtex
40
+ @techreport{turkicocr2026,
41
+ author = {{Project authors}},
42
+ title = {A Handwriting Recognition Model for Turkic Languages in Latin and Cyrillic Script},
43
+ institution = {Nazarbayev University},
44
+ type = {Project report},
45
+ year = {2026}
46
+ }
47
+ ```
48
+
49
+ Related repositories: the generated data `treoa/turkic-ocr-generated-data` (CC BY-SA 4.0), the detector weights
50
+ `treoa/turkic-line-detector-yolo11s` and the page pipeline `treoa/turkic-ocr-page-pipeline` (both AGPL-3.0).
51
+
52
+ ## Layout
53
+
54
+ | Folder | Contents |
55
+ |---|---|
56
+ | `src/pagesynth/` | page and line generator 0.3.0: text filters, fonts, simulated writer, layouts, paper, marks, maps, capture, cropping |
57
+ | `src/linedet/` | CTC line recognizers (PP-OCRv6-medium and others), the 6-gram character language model, the YOLO11s detector (`det_*.py`) |
58
+ | `src/r5eval/` | scorer: normalisation, CER and WER, look-alike repair, bootstrap intervals, model selection, report cards |
59
+ | `src/rq2/`, `src/lettersynth/` | augmentation study (line height 32 or 64 px crossed with two augmentation policies) |
60
+ | `src/ref/` | vendored HTR-Flor, used for the reference re-run |
61
+ | `scripts/` | job scripts: real-data manifests and splits, training mix, training, test passes, page scoring, release build |
62
+ | `config_r5eval/` | configuration of the scorer and the model selection (there is no separate `configs/` folder) |
63
+ | `release/` | inference scripts and requirements of the detector, the page pipeline and the three readers |
64
+ | `tests/` | unit tests of the scorer utilities and a small scoring sample (`tests/data/sample_eval/`) |
65
+ | `tests_r5eval/` | the scorer's original test suite (`python tests_r5eval/run_all.py SCRATCH_DIR`) |
66
+ | `results/` | `metrics.csv` (headline numbers of the 6-page paper) and the three paper figures |
67
+ | `environments/` | exact package lists of every Python environment used in the project |
68
+
69
+ ## Setup
70
+
71
+ Python 3.12. On Linux or macOS:
72
+
73
+ ```bash
74
+ python3.12 -m venv .venv
75
+ .venv/bin/python -m pip install -r requirements.txt
76
+ ```
77
+
78
+ `make setup` does the same (`make setup PYTHON=/path/to/python3.12` picks another interpreter). `requirements.txt` covers the tests, the scorer, the
79
+ generator and line detection on the CPU. Training used other environments; their exact package lists are in
80
+ `environments/` (for example `environments/venv_vlm.requirements` for the vision-language readers). PyTorch builds with
81
+ a `+cu` suffix there come from `https://download.pytorch.org/whl/<cuda tag>`.
82
+
83
+ The job scripts were written for one Slurm cluster. Absolute paths in them start with two placeholders, which you
84
+ replace with your own folders before running a job:
85
+
86
+ ```bash
87
+ grep -rlF /path/to/TURKIC_OCR_CODE . | xargs sed -i 's#/path/to/TURKIC_OCR_CODE#/home/me/turkic_ocr#g'
88
+ grep -rlF /path/to/TURKIC_OCR_DATA . | xargs sed -i 's#/path/to/TURKIC_OCR_DATA#/data/turkic_ocr#g'
89
+ ```
90
+
91
+ The Slurm headers name the partitions of the original cluster. Many scripts read manifests and write records of the
92
+ original run; those files are not part of this package.
93
+
94
+ ## Data
95
+
96
+ No dataset is stored here. The generated data are on the Hugging Face Hub, in four configurations (`hand`, `typed`,
97
+ `clutter`, `pages`), each with train, validation and test splits:
98
+
99
+ ```bash
100
+ hf download treoa/turkic-ocr-generated-data --repo-type dataset --local-dir data/generated
101
+ ```
102
+
103
+ ```python
104
+ from datasets import load_dataset # pip install datasets
105
+ hand_val = load_dataset("treoa/turkic-ocr-generated-data", "hand", split="validation")
106
+ ```
107
+
108
+ The real datasets keep their own licences and must be obtained from their sources:
109
+
110
+ | Set | Where |
111
+ |---|---|
112
+ | KOHTD (Kazakh handwriting) | https://github.com/abdoelsayed2016/KOHTD (application form of its authors) |
113
+ | HKR (Kazakh and Russian handwriting) | https://github.com/abdoelsayed2016/HKR_Dataset (application form of its authors) |
114
+ | School Notebooks RU | https://huggingface.co/datasets/ai-forever/school_notebooks_RU |
115
+ | Cyrillic Handwriting Dataset | https://www.kaggle.com/datasets/constantinwerner/cyrillic-handwriting-dataset |
116
+ | Azerbaijani Handwritten OCR Benchmark | https://huggingface.co/datasets/LocalDoc/azerbaijani-htr-benchmark |
117
+ | TurkishOCR-Bench | https://huggingface.co/datasets/moganai/TurkishOCR-Bench |
118
+ | RUKOPYS | https://huggingface.co/datasets/UkrainianCatholicUniversity/rukopys |
119
+ | FinePDFs (real printed lines) | https://huggingface.co/datasets/HuggingFaceFW/finepdfs |
120
+ | FineWeb-2, Wikipedia (generator text) | https://huggingface.co/datasets/HuggingFaceFW/fineweb-2, https://huggingface.co/datasets/wikimedia/wikipedia |
121
+ | PP-OCRv6-medium base weights | https://doi.org/10.5281/zenodo.21788410 |
122
+
123
+ The code also reads the Kazakh web benchmark `Omar-2002/kz_benchmark_data`, the Sakha newspaper corpus
124
+ `ailabykt/sakha-corpus-mono` (generator text for Sakha) and the Kazakh handwritten letter sheets of
125
+ https://github.com/Nuray-Sheriyeva/Kazakh_Handwritten_Letter_Dataset (used by the augmentation study's pixel probe).
126
+
127
+ ## Running
128
+
129
+ Tests (`make test`): the files in `tests/` check edit distance, text normalisation, look-alike repair and one full
130
+ scoring run.
131
+
132
+ ```bash
133
+ make test # pytest, 22 tests, under a minute on a laptop
134
+ make lint # ruff on tests/
135
+ ```
136
+
137
+ Scoring a prediction file (`make sample-eval`). The scorer reads a set registry, a manifest per set, and prediction
138
+ files laid out as `<preds>/<model>/<checkpoint>/<set>.tsv` with the columns `id`, `ref`, `hyp`. The bundled sample has
139
+ ten made-up lines in eight languages with ten character errors:
140
+
141
+ ```bash
142
+ python scripts/r5eval/score.py --preds tests/data/sample_eval/preds --registry tests/data/sample_eval/evalsets.json \
143
+ --out outputs/sample_eval --B 1000 --settle 0
144
+ ```
145
+
146
+ The score file `outputs/sample_eval/demo/final/sample_lines.json` holds the CER under
147
+ `profiles.plain.groups.all.metrics.cer`: 10 / 229 = 0.0437, with a 95% bootstrap interval over pages.
148
+
149
+ Line detection on a page image, with the released weights (needs `torch` and `ultralytics` from `requirements.txt`):
150
+
151
+ ```bash
152
+ hf download treoa/turkic-line-detector-yolo11s best.pt --local-dir models/detector
153
+ python release/turkic-line-detector-yolo11s/infer.py --images page.jpg --weights models/detector/best.pt \
154
+ --out boxes.tsv --device cpu
155
+ ```
156
+
157
+ The output TSV has one row per image: `id`, `n_lines`, `boxes` (JSON list of `[x0, y0, x1, y1]` in pixels) and `scores`.
158
+ To read the lines as well, use the page pipeline repository; it needs reader weights, which are not released.
159
+
160
+ Generating pages. The generator needs the 73 fonts listed in `src/pagesynth/assets/fonts_manifest.tsv` (font, licence
161
+ class, held out or not). The font files are not shipped: put them in `src/pagesynth/assets/fonts/` or point
162
+ `PAGESYNTH_FONTS` at their folder. It also needs a sentence bank per language, built from Wikipedia and FineWeb-2 by
163
+ `src/pagesynth/scripts/build_text.py` and `build_label_vocab.py`. Then, for ten Kazakh notebook pages:
164
+
165
+ ```bash
166
+ python src/pagesynth/generate_pages.py --type notebook --lang kk --n 10 --seed 1 --strength mixed \
167
+ --out out/pages --text-dir TEXT --no-personal-fonts
168
+ ```
169
+
170
+ `--no-personal-fonts` leaves out the eight fonts whose licence allows personal use only. The released generated data
171
+ contain no item drawn with them.
172
+
173
+ Training. The training entry points are `scripts/r5_vlma/train_vlm.py` (full fine-tuning of the vision-language
174
+ readers), `scripts/r5_vlmb/vlmb_train.py` (readers that need their maker's code), `src/linedet/train_arm.py` (CTC line
175
+ recognizers), `src/linedet/det_yolo.py` (detector) and `scripts/r5_rq2/rq2_train.py` (augmentation study). The full
176
+ runs need H100 GPUs on a Slurm cluster and the licensed real data, KOHTD and HKR above all. The reader weights trained in
177
+ the project are not released: the terms of KOHTD and HKR limit their use to the applicant's group and to academic
178
+ research. The detector was trained on School Notebooks photos and generated pages, and its weights are released.
179
+
180
+ ## Seeds
181
+
182
+ Fixed defaults in the code: `--seed 20261121` for the bootstrap of the scorer (`scripts/r5eval/score.py`), for the
183
+ sample stream of the line recognizers (`src/linedet/train_arm.py`) and for `scripts/r5_vlmb/vlmb_train.py`;
184
+ `--data-order-seed 20261121` is recorded by `scripts/r5_vlma/train_vlm.py`, whose data order comes from a fixed
185
+ sequence file; the generator draws each page from `--seed` (default 1) and the page index. The generator reproduces the
186
+ content of a page from its seed, but not every byte of the image.
187
+
188
+ ## Results
189
+
190
+ `results/metrics.csv` lists the headline numbers of the 6-page paper, with 95% intervals where the paper gives them;
191
+ `results/figures/` holds its three figures. On the sealed KOHTD test of 18,615 Kazakh handwritten words the
192
+ fine-tuned PaddleOCR-VL-1.6 reads at 4.01% CER (3.71 to 4.32%), and on 8,265 real printed lines at 0.244%. On 50
193
+ handwritten Turkish test pages its page CER is 49.8%. The long version of the report also gives the augmentation
194
+ study, run on validation data only.
195
+
196
+ ## Not included
197
+
198
+ - Data of any kind: real datasets, generated data, manifests, splits, predictions.
199
+ - Weights of the fine-tuned readers (PaddleOCR-VL-1.6, Qwen3-VL-2B, PP-OCRv6-medium and its character language model).
200
+ - Font files.
201
+ - The scripts of the continued training on real Latin-script handwriting, of the IAM scoring and of the later,
202
+ more realistic generator version.
203
+ - The PaddleOCR source used by the PP-OCRv3 reference re-run (see NOTICE) and the KOHTD download scripts.
204
+ - `config_r5eval/sota_checklist.json`: `scripts/r5_select_verdict.sbatch` passes it to `scripts/r5eval/verdict.py`;
205
+ drop that argument, since `verdict.py` runs without it.
206
+
207
+ ## Known issues
208
+
209
+ - Some scripts check at start that other files are unchanged byte for byte. Replacing the path placeholders changes
210
+ those files, so the checks fail: `src/rq2/geom.py` then stops with "REFUSED" until you update its `PINNED` table.
211
+ - The docstring of `release/turkic-ocr-ppocrv6-medium/infer.py` quotes figures from before the batching correction;
212
+ the paper's figures replace them.
213
+
214
+ ## Licences
215
+
216
+ Apache-2.0 (`LICENSE`) for everything except: the detector's training and inference path and the page pipeline,
217
+ AGPL-3.0 (`LICENSE.AGPL-3.0`, files listed in `NOTICE`), because Ultralytics YOLO is AGPL-3.0; the vendored HTR-Flor
218
+ copy in `src/ref/` (MIT, its own `LICENSE`); and the Natural Earth map files in `src/pagesynth/assets/naturalearth/`
219
+ (public domain). Third-party notices are in `NOTICE`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pyproject.toml ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "turkic-ocr-code"
3
+ version = "1.0.0"
4
+ description = "Generator, training and evaluation code for one text reader in nine Turkic languages"
5
+ requires-python = ">=3.12"
6
+
7
+ [tool.pytest.ini_options]
8
+ pythonpath = ["src"]
9
+ testpaths = ["tests"]
10
+
11
+ [tool.ruff]
12
+ line-length = 120
13
+ target-version = "py312"
14
+
15
+ [tool.ruff.lint]
16
+ select = ["E", "F", "W", "I"]
release/page-pipeline/infer.py CHANGED
@@ -1,12 +1,12 @@
1
  #!/usr/bin/env python
2
- """Read whole pages: find the text lines, cut a crop for every line, read every crop (Turkic OCR, release candidate 1).
3
 
4
  Stage 1 runs the detector package (turkic-line-detector-yolo11s) on the page image as a subprocess, because it needs ultralytics, which
5
  the reader's environment does not contain: pass --detector-python with a Python that has ultralytics (the default is this Python).
6
- Stage 2 cuts one crop per box and reads every crop with the reader package (turkic-ocr-paddleocr-vl-1.6, final model of this release,
7
- greedy, bfloat16, at most 192 new tokens per line, batches of 16 crops in reading order), in this process.
8
 
9
- Crop and reading-order logic are those of our evaluation (CODE/src/linedet/det_eval.py and the page check detb1_page_check.py):
10
  - reading order: boxes sorted by (centre_y // band, centre_x) in the detection image, band = 15 px in a page whose longer side is
11
  1280 px (the band grows in proportion for a larger or smaller page);
12
  - crop: the box widened by 1 % of its width plus 2 px on each side and heightened by 10 % of its height plus 1 px above and below,
@@ -19,8 +19,8 @@ Outputs: --out, a TSV with one row per page: id, n_lines, text (the lines in rea
19
  --lines-out, a TSV with one row per crop: id, line, x0, y0, x1, y1, score, text (boxes in detection-image pixels).
20
 
21
  usage:
22
- python infer.py --images page.jpg --out pages.tsv --lines-out lines.tsv
23
- python infer.py --manifest pages.tsv --out pages.tsv --lines-out lines.tsv --detector-python /path/to/venv-with-ultralytics/bin/python
24
  """
25
  import os
26
 
 
1
  #!/usr/bin/env python
2
+ """Read whole pages: find the text lines, cut a crop for every line, read every crop (Turkic OCR).
3
 
4
  Stage 1 runs the detector package (turkic-line-detector-yolo11s) on the page image as a subprocess, because it needs ultralytics, which
5
  the reader's environment does not contain: pass --detector-python with a Python that has ultralytics (the default is this Python).
6
+ Stage 2 cuts one crop per box and reads every crop, in this process, with the reader package given by --reader-dir (bfloat16, batches of
7
+ 16 crops in reading order). No reader is included: the project's fine-tuned PaddleOCR-VL-1.6 is not distributed (see model_card.json).
8
 
9
+ Crop and reading-order logic are those of our evaluation (src/linedet/det_eval.py and scripts/b1_page_check/detb1_page_check.py in treoa/turkic-ocr-code):
10
  - reading order: boxes sorted by (centre_y // band, centre_x) in the detection image, band = 15 px in a page whose longer side is
11
  1280 px (the band grows in proportion for a larger or smaller page);
12
  - crop: the box widened by 1 % of its width plus 2 px on each side and heightened by 10 % of its height plus 1 px above and below,
 
19
  --lines-out, a TSV with one row per crop: id, line, x0, y0, x1, y1, score, text (boxes in detection-image pixels).
20
 
21
  usage:
22
+ python infer.py --images page.jpg --reader-dir /path/to/reader --out pages.tsv --lines-out lines.tsv
23
+ python infer.py --manifest pages.tsv --reader-dir /path/to/reader --out pages.tsv --lines-out lines.tsv --detector-python /path/to/venv-with-ultralytics/bin/python
24
  """
25
  import os
26
 
release/page-pipeline/requirements.txt CHANGED
@@ -1,7 +1,7 @@
1
- # The page pipeline runs in the READER's environment (infer.py here and the reader's code): exact package versions of CODE/.venv_vlm,
2
- # Python 3.12.13. The detector needs ultralytics, which this environment does not have: install the requirements.txt of
3
- # turkic-line-detector-yolo11s in a second environment and pass its Python as --detector-python (one environment holding both also works).
4
- # Frozen with `uv pip freeze` on 2026-11-25 (cluster job 55104, file DATA/tmp/rc1_check/freeze_vlm.txt).
5
  # torch and torchvision are the CUDA 12.8 builds ("+cu128"); the index line below lets pip find them. On a machine without a GPU the same
6
  # versions run on the CPU (bfloat16 matrix products are used on CPU as well), or install torch==2.11.0 and torchvision==0.26.0 from PyPI.
7
  --extra-index-url https://download.pytorch.org/whl/cu128
 
1
+ # The page pipeline runs in the reader's environment (infer.py here and the reader's code): exact package versions of
2
+ # that environment, Python 3.12.13, frozen with `uv pip freeze` on 2026-11-25. The detector needs ultralytics, which
3
+ # this environment does not have: install the requirements.txt of turkic-line-detector-yolo11s in a second environment
4
+ # and pass its Python as --detector-python (one environment holding both also works).
5
  # torch and torchvision are the CUDA 12.8 builds ("+cu128"); the index line below lets pip find them. On a machine without a GPU the same
6
  # versions run on the CPU (bfloat16 matrix products are used on CPU as well), or install torch==2.11.0 and torchvision==0.26.0 from PyPI.
7
  --extra-index-url https://download.pytorch.org/whl/cu128
release/turkic-line-detector-yolo11s/infer.py CHANGED
@@ -1,12 +1,12 @@
1
  #!/usr/bin/env python
2
- """Find text lines on page images with the YOLO11s line detector of Turkic OCR (release candidate 1, stage-2 weights best.pt).
3
 
4
  Input: one image, a folder of images, or a TSV manifest (columns id, image). Output: a TSV with one row per page image and the columns
5
  id, n_lines, boxes, scores
6
  where boxes is a JSON list of [x0, y0, x1, y1] in pixels of the input image (rounded to 0.1) and scores a JSON list of the detection
7
  confidences (rounded to 0.0001), in the detector's own order. A detector finds boxes, not text, so this TSV replaces the (id, text) table
8
  of the readers; the reader of the page-pipeline package turns the boxes into text.
9
- The settings are those of our detection evaluation (CODE/src/linedet/det_eval.py): the image file is passed to ultralytics, image size
10
  1280, confidence threshold 0.25, NMS IoU 0.6, at most 300 boxes, one class "text_line".
11
 
12
  usage:
 
1
  #!/usr/bin/env python
2
+ """Find text lines on page images with the YOLO11s line detector of Turkic OCR (weights best.pt).
3
 
4
  Input: one image, a folder of images, or a TSV manifest (columns id, image). Output: a TSV with one row per page image and the columns
5
  id, n_lines, boxes, scores
6
  where boxes is a JSON list of [x0, y0, x1, y1] in pixels of the input image (rounded to 0.1) and scores a JSON list of the detection
7
  confidences (rounded to 0.0001), in the detector's own order. A detector finds boxes, not text, so this TSV replaces the (id, text) table
8
  of the readers; the reader of the page-pipeline package turns the boxes into text.
9
+ The settings are those of our detection evaluation (src/linedet/det_eval.py in treoa/turkic-ocr-code): the image file is passed to ultralytics, image size
10
  1280, confidence threshold 0.25, NMS IoU 0.6, at most 300 boxes, one class "text_line".
11
 
12
  usage:
release/turkic-line-detector-yolo11s/requirements.txt CHANGED
@@ -1,5 +1,5 @@
1
- # Exact package versions of the environment this detector was trained and evaluated in: CODE/.venv_kraken, Python 3.12.13.
2
- # Frozen with `uv pip freeze` on 2026-11-25 (cluster job 55104, file DATA/tmp/rc1_check/freeze_kraken.txt).
3
  # What infer.py imports directly: ultralytics (8.4.216; AGPL-3.0), torch, and through ultralytics numpy, opencv-python, pillow, scipy, pyyaml.
4
  # torch and torchvision are the CUDA 12.8 builds ("+cu128"); the index line below lets pip find them. On a machine without a GPU the same
5
  # versions run on the CPU.
 
1
+ # Exact package versions of the environment this detector was trained and evaluated in (Python 3.12.13),
2
+ # frozen with `uv pip freeze` on 2026-11-25.
3
  # What infer.py imports directly: ultralytics (8.4.216; AGPL-3.0), torch, and through ultralytics numpy, opencv-python, pillow, scipy, pyyaml.
4
  # torch and torchvision are the CUDA 12.8 builds ("+cu128"); the index line below lets pip find them. On a machine without a GPU the same
5
  # versions run on the CPU.
release/turkic-ocr-paddleocr-vl-1.6/infer.py CHANGED
@@ -1,8 +1,8 @@
1
  #!/usr/bin/env python
2
- """Read word or line crops with the vision-language model in ./model (Turkic OCR, release candidate 1).
3
 
4
  Input: one image, a folder of images, or a TSV manifest (columns id, image). Output: a TSV with the columns id and text.
5
- The decoding is the one of our evaluation (CODE/scripts/r5_vlma/vlm_common.py and eval_vlm.py), copied here so the package stands alone:
6
  - the single instruction "Transcribe the text in this image exactly." with one image, the model's own chat template,
7
  generation prompt on, chat-template variables and answer-end token read from model/r5_export.json;
8
  - greedy decoding, one beam, no repetition penalty, left padding, stop on the generation-config end ids, the tokenizer end id and
 
1
  #!/usr/bin/env python
2
+ """Read word or line crops with the vision-language model in ./model (Turkic OCR).
3
 
4
  Input: one image, a folder of images, or a TSV manifest (columns id, image). Output: a TSV with the columns id and text.
5
+ The decoding is the one of our evaluation (scripts/r5_vlma/vlm_common.py and eval_vlm.py), copied here so the package stands alone:
6
  - the single instruction "Transcribe the text in this image exactly." with one image, the model's own chat template,
7
  generation prompt on, chat-template variables and answer-end token read from model/r5_export.json;
8
  - greedy decoding, one beam, no repetition penalty, left padding, stop on the generation-config end ids, the tokenizer end id and
release/turkic-ocr-paddleocr-vl-1.6/requirements.txt CHANGED
@@ -1,5 +1,5 @@
1
- # Exact package versions of the environment this model was evaluated in: CODE/.venv_vlm, Python 3.12.13.
2
- # Frozen with `uv pip freeze` on 2026-11-25 (cluster job 55104, file DATA/tmp/rc1_check/freeze_vlm.txt).
3
  # torch and torchvision are the CUDA 12.8 builds ("+cu128"); the index line below lets pip find them. On a machine without a GPU the same
4
  # versions run on the CPU (bfloat16 matrix products are used on CPU as well), or install torch==2.11.0 and torchvision==0.26.0 from PyPI.
5
  --extra-index-url https://download.pytorch.org/whl/cu128
 
1
+ # Exact package versions of the environment this model was evaluated in (Python 3.12.13),
2
+ # frozen with `uv pip freeze` on 2026-11-25.
3
  # torch and torchvision are the CUDA 12.8 builds ("+cu128"); the index line below lets pip find them. On a machine without a GPU the same
4
  # versions run on the CPU (bfloat16 matrix products are used on CPU as well), or install torch==2.11.0 and torchvision==0.26.0 from PyPI.
5
  --extra-index-url https://download.pytorch.org/whl/cu128
release/turkic-ocr-ppocrv6-medium/infer.py CHANGED
@@ -1,8 +1,8 @@
1
  #!/usr/bin/env python
2
- """Read word or line crops with the small recognizer A1 (kraken PP-OCRv6 medium, our checkpoint long2x) - Turkic OCR, release candidate 1.
3
 
4
  Input: one image, a folder of images, or a TSV manifest (columns id, image). Output: a TSV with the columns id and text.
5
- The code path is the one of our evaluation (CODE/src/linedet/data.py, models.py, predict.py, lm_decode.py, lm_gate.py), copied here so
6
  the package stands alone:
7
  - image: RGB, scaled to 96 px height with Lanczos (width keeps the aspect ratio), 16 px white padding left and right, scaled to
8
  [0, 1], inverted (ink bright); a batch is padded with zeros on the right to its widest image;
@@ -10,8 +10,8 @@ the package stands alone:
10
  squeeze-and-excite layers of kraken's backbone average over the whole padded width (kraken/lib/ppocr/backbone.py, SELayer), while only
11
  the attention of the neck masks the padded columns (network.py, _lengths_and_mask). The evaluation read batches of 32 sorted by
12
  LABEL length, so every batch carried white margin on its narrower crops, and the network was trained that way; without labels that
13
- cannot be repeated. Measured on the 3,678 KOHTD validation crops V1 (greedy, CPU float32, character error rate; jobs 55155 and
14
- 55176): evaluation batches 6.2% (the recorded GPU file: 6.2%); batches sorted by width 14.1%; every crop alone 14.2%; batches in
15
  manifest order 7.9%; in a seeded shuffle 7.3%; sorted by width plus 64, 128, 256, 512, 1024 extra zero columns: 10.4%, 8.1%, 6.55%,
16
  6.50%, 7.5%. This script therefore sorts by width and appends --batch-pad (default 256) zero columns to every batch: a label-free
17
  approximation chosen on V1 (word crops; the value for line crops is untested), not the evaluation's own condition. To reproduce the
@@ -50,7 +50,7 @@ from safetensors.torch import load_file # noqa: E402
50
  HERE = os.path.dirname(os.path.abspath(__file__))
51
  IMG_EXT = (".png", ".jpg", ".jpeg", ".bmp", ".tif", ".tiff", ".webp")
52
  PAD = 16
53
- BATCH_PAD_DEFAULT = 256 # extra zero columns per batch, chosen on V1 from {0, 64, 128, 256, 512, 1024} (job 55176)
54
  TOPK = 6
55
  BEAM = 16
56
  ALPHA, BETA = 0.40, 1.00
 
1
  #!/usr/bin/env python
2
+ """Read word or line crops with the small recognizer A1 (kraken PP-OCRv6 medium, our checkpoint long2x) of Turkic OCR.
3
 
4
  Input: one image, a folder of images, or a TSV manifest (columns id, image). Output: a TSV with the columns id and text.
5
+ The code path is the one of our evaluation (src/linedet/data.py, models.py, predict.py, lm_decode.py, lm_gate.py), copied here so
6
  the package stands alone:
7
  - image: RGB, scaled to 96 px height with Lanczos (width keeps the aspect ratio), 16 px white padding left and right, scaled to
8
  [0, 1], inverted (ink bright); a batch is padded with zeros on the right to its widest image;
 
10
  squeeze-and-excite layers of kraken's backbone average over the whole padded width (kraken/lib/ppocr/backbone.py, SELayer), while only
11
  the attention of the neck masks the padded columns (network.py, _lengths_and_mask). The evaluation read batches of 32 sorted by
12
  LABEL length, so every batch carried white margin on its narrower crops, and the network was trained that way; without labels that
13
+ cannot be repeated. Measured on the 3,678 KOHTD validation crops V1 (greedy, CPU float32, character error rate):
14
+ evaluation batches 6.2% (the recorded GPU file: 6.2%); batches sorted by width 14.1%; every crop alone 14.2%; batches in
15
  manifest order 7.9%; in a seeded shuffle 7.3%; sorted by width plus 64, 128, 256, 512, 1024 extra zero columns: 10.4%, 8.1%, 6.55%,
16
  6.50%, 7.5%. This script therefore sorts by width and appends --batch-pad (default 256) zero columns to every batch: a label-free
17
  approximation chosen on V1 (word crops; the value for line crops is untested), not the evaluation's own condition. To reproduce the
 
50
  HERE = os.path.dirname(os.path.abspath(__file__))
51
  IMG_EXT = (".png", ".jpg", ".jpeg", ".bmp", ".tif", ".tiff", ".webp")
52
  PAD = 16
53
+ BATCH_PAD_DEFAULT = 256 # extra zero columns per batch, chosen on V1 from {0, 64, 128, 256, 512, 1024}
54
  TOPK = 6
55
  BEAM = 16
56
  ALPHA, BETA = 0.40, 1.00
release/turkic-ocr-ppocrv6-medium/requirements.txt CHANGED
@@ -1,5 +1,5 @@
1
- # Exact package versions of the environment this model was trained and evaluated in: CODE/.venv_kraken, Python 3.12.13.
2
- # Frozen with `uv pip freeze` on 2026-11-25 (cluster job 55104, file DATA/tmp/rc1_check/freeze_kraken.txt).
3
  # What infer.py imports directly: kraken (PPOCRv6Model, PytorchCodec), torch, numpy, pillow, safetensors, and kenlm for --decode lm and lm_gated.
4
  # kenlm==0.3.0 is built from source on installation (needs a C++ compiler). torch and torchvision are the CUDA 12.8 builds ("+cu128"); the
5
  # index line below lets pip find them. On a machine without a GPU the same versions run on the CPU (float32 there).
 
1
+ # Exact package versions of the environment this model was trained and evaluated in (Python 3.12.13),
2
+ # frozen with `uv pip freeze` on 2026-11-25.
3
  # What infer.py imports directly: kraken (PPOCRv6Model, PytorchCodec), torch, numpy, pillow, safetensors, and kenlm for --decode lm and lm_gated.
4
  # kenlm==0.3.0 is built from source on installation (needs a C++ compiler). torch and torchvision are the CUDA 12.8 builds ("+cu128"); the
5
  # index line below lets pip find them. On a machine without a GPU the same versions run on the CPU (float32 there).
release/turkic-ocr-qwen3-vl-2b/infer.py CHANGED
@@ -1,8 +1,8 @@
1
  #!/usr/bin/env python
2
- """Read word or line crops with the vision-language model in ./model (Turkic OCR, release candidate 1).
3
 
4
  Input: one image, a folder of images, or a TSV manifest (columns id, image). Output: a TSV with the columns id and text.
5
- The decoding is the one of our evaluation (CODE/scripts/r5_vlma/vlm_common.py and eval_vlm.py), copied here so the package stands alone:
6
  - the single instruction "Transcribe the text in this image exactly." with one image, the model's own chat template,
7
  generation prompt on, chat-template variables and answer-end token read from model/r5_export.json;
8
  - greedy decoding, one beam, no repetition penalty, left padding, stop on the generation-config end ids, the tokenizer end id and
 
1
  #!/usr/bin/env python
2
+ """Read word or line crops with the vision-language model in ./model (Turkic OCR).
3
 
4
  Input: one image, a folder of images, or a TSV manifest (columns id, image). Output: a TSV with the columns id and text.
5
+ The decoding is the one of our evaluation (scripts/r5_vlma/vlm_common.py and eval_vlm.py), copied here so the package stands alone:
6
  - the single instruction "Transcribe the text in this image exactly." with one image, the model's own chat template,
7
  generation prompt on, chat-template variables and answer-end token read from model/r5_export.json;
8
  - greedy decoding, one beam, no repetition penalty, left padding, stop on the generation-config end ids, the tokenizer end id and
release/turkic-ocr-qwen3-vl-2b/requirements.txt CHANGED
@@ -1,5 +1,5 @@
1
- # Exact package versions of the environment this model was evaluated in: CODE/.venv_vlm, Python 3.12.13.
2
- # Frozen with `uv pip freeze` on 2026-11-25 (cluster job 55104, file DATA/tmp/rc1_check/freeze_vlm.txt).
3
  # torch and torchvision are the CUDA 12.8 builds ("+cu128"); the index line below lets pip find them. On a machine without a GPU the same
4
  # versions run on the CPU (bfloat16 matrix products are used on CPU as well), or install torch==2.11.0 and torchvision==0.26.0 from PyPI.
5
  --extra-index-url https://download.pytorch.org/whl/cu128
 
1
+ # Exact package versions of the environment this model was evaluated in (Python 3.12.13),
2
+ # frozen with `uv pip freeze` on 2026-11-25.
3
  # torch and torchvision are the CUDA 12.8 builds ("+cu128"); the index line below lets pip find them. On a machine without a GPU the same
4
  # versions run on the CPU (bfloat16 matrix products are used on CPU as well), or install torch==2.11.0 and torchvision==0.26.0 from PyPI.
5
  --extra-index-url https://download.pytorch.org/whl/cu128
requirements.txt ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python 3.12. Packages for the unit tests, the scorer, the page generator and line detection on one machine.
2
+ # Versions match the project environments listed in environments/ (training needs more; see environments/).
3
+ numpy==2.5.5
4
+ scipy==1.18.1
5
+ regex==2026.11.19
6
+ shapely==2.1.2
7
+ pyyaml==6.0.3
8
+ pillow==13.0.0
9
+ opencv-python-headless==5.1.0.95
10
+ fonttools==4.68.0
11
+ rdkit==2026.9.2
12
+ pyarrow==26.0.1
13
+ huggingface-hub==2.4.0
14
+ torch==2.11.0
15
+ torchvision==0.26.0
16
+ ultralytics==8.4.216
17
+ pytest==9.2.0
18
+ ruff==0.17.6
results/figures/fig1_overview.png ADDED

Git LFS Details

  • SHA256: ac5bccf6782a906ad6ffa91e7d88e9bbb3e415f6eb9ea78ab67450912be2faf2
  • Pointer size: 131 Bytes
  • Size of remote file: 184 kB
results/figures/fig2_results.png ADDED
results/figures/fig3_forgetting.png ADDED
results/metrics.csv ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ model,set,metric,value,interval
2
+ PaddleOCR-VL-1.6 fine-tuned (shipped model),KOHTD sealed test (18615 Kazakh handwritten words),CER %,4.01,3.71 to 4.32
3
+ Qwen3-VL-2B fine-tuned,KOHTD sealed test (18615 Kazakh handwritten words),CER %,4.11,
4
+ PP-OCRv6-medium fine-tuned with 6-gram character LM,KOHTD sealed test (18615 Kazakh handwritten words),CER %,4.09,
5
+ PP-OCRv6-medium fine-tuned greedy,KOHTD sealed test (18615 Kazakh handwritten words),CER %,5.36,
6
+ PaddleOCR-VL-1.6 fine-tuned (shipped model),KOHTD sealed test words unseen in training (2228),CER %,7.63,
7
+ PaddleOCR-VL-1.6 fine-tuned (shipped model),real printed test lines (8265),CER %,0.244,0.116 to 0.465
8
+ Qwen3-VL-2B fine-tuned,real printed test lines (8265),CER %,0.154,0.090 to 0.243
9
+ PaddleOCR-VL-1.6 fine-tuned (shipped model),real Azerbaijani handwritten lines (442; descriptive),CER %,63.6,52.0 to 74.4
10
+ PaddleOCR-VL-1.6 untuned base,real Azerbaijani handwritten lines (442; descriptive),CER %,46.6,
11
+ PP-OCRv6-medium fine-tuned,real Azerbaijani handwritten lines (442; descriptive),CER %,36.9,
12
+ PaddleOCR-VL-1.6 fine-tuned (shipped model),TurkishOCR-Bench handwritten test pages (50),page CER %,49.8,
13
+ PaddleOCR-VL-1.6 fine-tuned (shipped model),Russian validation photos with teacher marks (150),page CER % ignoring line order,30.9,
14
+ Qwen3-VL-2B fine-tuned,Russian validation photos with teacher marks (150),page CER % ignoring line order,32.9,
15
+ PaddleOCR-VL-1.6 fine-tuned (shipped model),empty regions of real notebook validation photos (418),share with text written %,2.15,upper 95% bound 4.05
16
+ Qwen3-VL-2B fine-tuned,empty regions of real notebook validation photos (418),share with text written %,2.39,upper 95% bound 4.36
17
+ PaddleOCR-VL-1.6 continued training (mean of 3 seeds),KOHTD sealed test (18615 Kazakh handwritten words),CER %,4.16,
18
+ PaddleOCR-VL-1.6 continued training (3 seeds),real Latin-script validation lines (Portuguese and French; held-out writers),CER %,4.28,
19
+ PaddleOCR-VL-1.6 fine-tuned (shipped model),real Latin-script validation lines (Portuguese and French; held-out writers),CER %,63.31,
20
+ PaddleOCR-VL-1.6 continued training (3 seeds),IAM English handwritten test lines,CER %,24.18,
21
+ PaddleOCR-VL-1.6 fine-tuned (shipped model),IAM English handwritten test lines,CER %,52.65,
22
+ PaddleOCR-VL-1.6 continued training (3 seeds),real Azerbaijani handwritten lines (435; descriptive),CER %,31.93,
23
+ PaddleOCR-VL-1.6 fine-tuned (shipped model),real Azerbaijani handwritten lines (435; descriptive),CER %,63.20,
scripts/r5/r5_build_real.py CHANGED
@@ -641,7 +641,7 @@ def stage_dedupe():
641
  info["train_dropped_near_only"] = n_near_only
642
  info["train_dropped_total"] = len(drop)
643
 
644
- # HKR vs KOHTD: any split of KOHTD (the owner's extra check); HKR train rows overlapping any KOHTD image are dropped
645
  hk_all = [i for i, t in enumerate(meta) if t[1] == "hkr_words" and ok[i]]
646
  ko_all = [i for i, t in enumerate(meta) if t[1] == "kohtd" and ok[i]]
647
  ko_sha = collections.defaultdict(list)
 
641
  info["train_dropped_near_only"] = n_near_only
642
  info["train_dropped_total"] = len(drop)
643
 
644
+ # HKR vs KOHTD: any split of KOHTD (the project's extra check); HKR train rows overlapping any KOHTD image are dropped
645
  hk_all = [i for i, t in enumerate(meta) if t[1] == "hkr_words" and ok[i]]
646
  ko_all = [i for i, t in enumerate(meta) if t[1] == "kohtd" and ok[i]]
647
  ko_sha = collections.defaultdict(list)
scripts/r5_onemodel/onemodel_gate.sbatch CHANGED
@@ -8,7 +8,7 @@
8
  #SBATCH --time=04:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
  #SBATCH --dependency=singleton
11
- # Single-model page training (route C), queued early at the owner's request on 25 Nov 2026 so it holds a place in the
12
  # H100 queue while the code is still being reviewed. It runs only reviewed code: READY lists the sha256 of every file the
13
  # review approved, and the job refuses to start if READY is missing or any listed file changed since the review.
14
  # Self-resubmission by the training code must submit THIS file again, so every segment passes the same check.
 
8
  #SBATCH --time=04:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
  #SBATCH --dependency=singleton
11
+ # Single-model page training (route C), queued early on 25 Nov 2026 so it holds a place in the
12
  # H100 queue while the code is still being reviewed. It runs only reviewed code: READY lists the sha256 of every file the
13
  # review approved, and the job refuses to start if READY is missing or any listed file changed since the review.
14
  # Self-resubmission by the training code must submit THIS file again, so every segment passes the same check.
scripts/r5_testpass2/tp2_a1lf_kohtd.sbatch CHANGED
@@ -5,7 +5,7 @@
5
  #SBATCH --mem=64G
6
  #SBATCH --time=06:00:00
7
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
8
- # Test pass 2, amendment 4 (owner-authorized): M2 (A1) label-free re-score on the KOHTD sealed test. V1 gate first (as job 55280), then
9
  # kohtd_test (18,615 crops) once, then the R5 scorer and the paired comparison with M1's existing 24 Nov kohtd_test predictions.
10
  set -u
11
  CODE=/path/to/TURKIC_OCR_CODE
 
5
  #SBATCH --mem=64G
6
  #SBATCH --time=06:00:00
7
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
8
+ # Test pass 2, amendment 4: M2 (A1) label-free re-score on the KOHTD sealed test. V1 gate first (as job 55280), then
9
  # kohtd_test (18,615 crops) once, then the R5 scorer and the paired comparison with M1's existing 24 Nov kohtd_test predictions.
10
  set -u
11
  CODE=/path/to/TURKIC_OCR_CODE
scripts/r5_testpass2/tp2_amend2.py CHANGED
@@ -1,4 +1,4 @@
1
- """Appends amendment 2 (Kazakh real-document benchmark, owner-approved 25 Nov 2026) to records/R5/TESTPASS2/plan.json, before the model
2
  reads any of its pages.
3
  usage: tp2_amend2.py TESTPASS2_DIR
4
  """
 
1
+ """Appends amendment 2 (Kazakh real-document benchmark, 25 Nov 2026) to records/R5/TESTPASS2/plan.json, before the model
2
  reads any of its pages.
3
  usage: tp2_amend2.py TESTPASS2_DIR
4
  """
scripts/r5_testpass2/tp2_amend4.py CHANGED
@@ -1,4 +1,4 @@
1
- """Appends amendment 4 (owner-authorized label-free re-score of M2 on the KOHTD sealed test) to records/R5/TESTPASS2/plan.json, before any
2
  prediction on kohtd_test.
3
  usage: tp2_amend4.py TESTPASS2_DIR
4
  """
 
1
+ """Appends amendment 4 (label-free re-score of M2 on the KOHTD sealed test) to records/R5/TESTPASS2/plan.json, before any
2
  prediction on kohtd_test.
3
  usage: tp2_amend4.py TESTPASS2_DIR
4
  """
scripts/r5_testpass2/tp2_az_latin.py CHANGED
@@ -1,4 +1,4 @@
1
- """Test pass 2, amendment 6 (26 Nov, owner-requested, descriptive): M1 (PaddleOCR-VL 1.6 R5 leader) on az_localdoc_test with LATIN-ONLY
2
  decoding. Identical to the test pass 2 run (eval_vlm_test.py: vlm_common prompt builder and training instruction, greedy, num_beams 1, stop
3
  ids incl. the trained answer-end token, max_new_tokens 48/192 by unit, batch 16, left padding, bf16 on CPU, manifest order) except for one
4
  logits processor that sets to -inf every vocabulary token whose decoded text contains a Cyrillic character (Unicode Script_Extensions
 
1
+ """Test pass 2, amendment 6 (26 Nov, descriptive): M1 (PaddleOCR-VL 1.6 R5 leader) on az_localdoc_test with LATIN-ONLY
2
  decoding. Identical to the test pass 2 run (eval_vlm_test.py: vlm_common prompt builder and training instruction, greedy, num_beams 1, stop
3
  ids incl. the trained answer-end token, max_new_tokens 48/192 by unit, batch 16, left padding, bf16 on CPU, manifest order) except for one
4
  logits processor that sets to -inf every vocabulary token whose decoded text contains a Cyrillic character (Unicode Script_Extensions
scripts/r5_testpass2/tp2_kzb_card.sbatch CHANGED
@@ -5,7 +5,7 @@
5
  #SBATCH --mem=4G
6
  #SBATCH --time=00:20:00
7
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
8
- # Owner-approved (25 Nov 2026): pin the revision of Omar-2002/kz_benchmark_data, list its tree, fetch README.md only (no token).
9
  set -u
10
  CODE=/path/to/TURKIC_OCR_CODE
11
  D=/path/to/TURKIC_OCR_DATA
 
5
  #SBATCH --mem=4G
6
  #SBATCH --time=00:20:00
7
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
8
+ # 25 Nov 2026: pin the revision of Omar-2002/kz_benchmark_data, list its tree, fetch README.md only (no token).
9
  set -u
10
  CODE=/path/to/TURKIC_OCR_CODE
11
  D=/path/to/TURKIC_OCR_DATA
scripts/r5_testpass2/tp2_kzb_fetch.py CHANGED
@@ -1,4 +1,4 @@
1
- """Test pass 2, owner-approved download (25 Nov 2026): Omar-2002/kz_benchmark_data, handwritten config only, no token.
2
  huggingface_hub 2.4.0 (CODE/.venv_dl): HfApi.dataset_info / list_repo_tree (token=False), hf_hub_download, snapshot_download
3
  (allow_patterns, local_dir, token=False). Downloaded files are untrusted data: nothing in them is executed.
4
 
 
1
+ """Test pass 2, download (25 Nov 2026): Omar-2002/kz_benchmark_data, handwritten config only, no token.
2
  huggingface_hub 2.4.0 (CODE/.venv_dl): HfApi.dataset_info / list_repo_tree (token=False), hf_hub_download, snapshot_download
3
  (allow_patterns, local_dir, token=False). Downloaded files are untrusted data: nothing in them is executed.
4
 
scripts/r5_testpass2/tp2_kzb_fetch.sbatch CHANGED
@@ -5,7 +5,7 @@
5
  #SBATCH --mem=8G
6
  #SBATCH --time=01:00:00
7
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
8
- # Owner-approved (25 Nov 2026): download the handwritten config of Omar-2002/kz_benchmark_data at the pinned revision (no token) into
9
  # DATA/data/raw/kz_benchmark_hw, sha256 of every file, checksum file; then the page list and 1280 px detector copies (no model).
10
  set -u
11
  CODE=/path/to/TURKIC_OCR_CODE
 
5
  #SBATCH --mem=8G
6
  #SBATCH --time=01:00:00
7
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
8
+ # 25 Nov 2026: download the handwritten config of Omar-2002/kz_benchmark_data at the pinned revision (no token) into
9
  # DATA/data/raw/kz_benchmark_hw, sha256 of every file, checksum file; then the page list and 1280 px detector copies (no model).
10
  set -u
11
  CODE=/path/to/TURKIC_OCR_CODE
scripts/r5_vlma/testpass_runner.py CHANGED
@@ -26,7 +26,7 @@ evaluation tasks, the complete sets (rows not complete by 16:55 are "not run by
26
 
27
  kind vlma -> eval_vlm_test.py (.venv_vlm); kind vlmb -> CODE/scripts/r5_vlmb/vlmb_eval_vlm_testpass.py with the arm's
28
  own venv and environment (leader_cmds.py, read-only); kind cmd -> the task's argv (LINEDET's commands through
29
- linedet_ckpt_task.sh, linedet.lm_gate, REF's test_pass_commands.sh), unchanged owner scripts.
30
 
31
  usage: testpass_runner.py --config testpass_config.json --slot V --worker 0|1 [--nfile N_FILE] [--tasks FIXED_LIST.json]
32
  """
 
26
 
27
  kind vlma -> eval_vlm_test.py (.venv_vlm); kind vlmb -> CODE/scripts/r5_vlmb/vlmb_eval_vlm_testpass.py with the arm's
28
  own venv and environment (leader_cmds.py, read-only); kind cmd -> the task's argv (LINEDET's commands through
29
+ linedet_ckpt_task.sh, linedet.lm_gate, REF's test_pass_commands.sh), unchanged scripts of those stages.
30
 
31
  usage: testpass_runner.py --config testpass_config.json --slot V --worker 0|1 [--nfile N_FILE] [--tasks FIXED_LIST.json]
32
  """
scripts/r5_vlmb/vlmb_runner.py CHANGED
@@ -103,7 +103,7 @@ def mark(tid, **kw):
103
  # ---- shared arms across two slots (added by stage VLMC on 2026-11-21 on request) ----------------
104
  # A queue file may name another queue file under "shared_queue": this runner also takes that file's "short" arms, after
105
  # its own list. Arms listed there, and with "claim_own": true this runner's own arms, run only once across slots: the
106
- # runner that starts an arm first creates DATA/outputs/r5/vlmb/claims/<arm>.json atomically (O_CREAT|O_EXCL, owner =
107
  # slot name, so a restarted job of the same slot keeps its claim); any other slot skips that arm and counts it as
108
  # finished for exit_when_done. A queue file without these keys behaves exactly as before.
109
  CLAIMS = os.path.join(V, "claims")
 
103
  # ---- shared arms across two slots (added by stage VLMC on 2026-11-21 on request) ----------------
104
  # A queue file may name another queue file under "shared_queue": this runner also takes that file's "short" arms, after
105
  # its own list. Arms listed there, and with "claim_own": true this runner's own arms, run only once across slots: the
106
+ # runner that starts an arm first creates DATA/outputs/r5/vlmb/claims/<arm>.json atomically (O_CREAT|O_EXCL, holder =
107
  # slot name, so a restarted job of the same slot keeps its claim); any other slot skips that arm and counts it as
108
  # finished for exit_when_done. A queue file without these keys behaves exactly as before.
109
  CLAIMS = os.path.join(V, "claims")
scripts/release2/decisions.json CHANGED
@@ -1,21 +1,21 @@
1
  {
2
- "status": "used by job C (rel2_build_data.py); decided 2026-11-25 from records/R5/RELEASE2/work/licence_evidence.json",
3
  "text_source_kinds_allowed": {
4
  "wiki": true,
5
  "fw2": true,
6
  "ailab": false
7
  },
8
- "why_ailab_excluded": "The Sakha newspaper sentences (ailabykt/sakha-corpus-mono, sources kyym, eder_saas, sakha_sire, uluus_media) carry CC BY 4.0 on the corpus card, but the newspapers' own sites require a hyperlink to the source for any reuse and Ulus Media requires prior written consent and limits use to personal non-commercial purposes. The corpus rows hold no article links, so the hyperlink condition cannot be met per item, and the consent condition is not met. Conservative default: excluded; the owner may re-include kyym, eder_saas and sakha_sire after deciding that a site-level link satisfies their terms.",
9
  "text_licence_label": {
10
  "wiki": "CC-BY-SA-4.0 (Wikipedia text)",
11
  "fw2": "ODC-By-1.0 (FineWeb-2; Common Crawl terms of use apply)",
12
  "ailab": "CC-BY-4.0 corpus card; newspaper terms apply (not released)"
13
  },
14
  "extra_exclusions_json": "/path/to/TURKIC_OCR_DATA/tmp/release2/sakha_check.json",
15
- "why_extra_exclusions": "rel2_sakha_check.py (job 55414) found released Sakha items whose label text occurs exactly (6 items) or as a 3-word window (363 more) in a newspaper sentence drawn for their page, although their line attribution named no newspaper document; all 369 are excluded (conservative; window matches can be coincidences).",
16
  "build_print_pointers": true,
17
- "pointer_notice_text": "Real-print pointer list (release candidate; publishing it is an owner decision)\n\nWHAT THIS IS\nOne row per real printed text line that the project cut from born-digital PDFs for training (train) and validation (val): our line id, language, script, split, document id, source, the PDF's URL, a fingerprint of the PDF we fetched, the page number, our line box in PDF points (x0,y0,x1,y1), the render DPI and padding we used, a fingerprint of our crop and a fingerprint of the NFC label. No image and no text of any PDF is included. The test documents are not listed.\n\nSOURCES AND TERMS\nContains information from FinePDFs (HuggingFaceFW/finepdfs), which is made available under the Open Data Commons Attribution License (ODC-By) 1.0; use of FinePDFs is also subject to the Common Crawl terms of use. Turkish lines also come from minutes of the Grand National Assembly of Turkey (tbmm.gov.tr).\nEvery PDF remains under its owner's rights; this list grants no right to the PDFs or their content. To rebuild a line, fetch the PDF from its URL, check it against that fingerprint, render the page at the listed DPI and cut the listed box.\nThe line boxes, ids and fingerprints are the project's own work; the licence for them is chosen by the owner before publication.\n",
18
- "licence_file_text": "Turkic OCR generated data, release candidate rc1_data (page generator pagesynth 0.3.0, round R5, frozen 21 Nov 2026)\n\nLICENCE\nThis package is licensed under the Creative Commons Attribution-ShareAlike 4.0 International licence (CC BY-SA 4.0):\nhttps://creativecommons.org/licenses/by-sa/4.0/legalcode\nLicensor: the authors of this release (the owner names them before publication).\n\nWHY SHARE-ALIKE\nThe label texts, and the text drawn in the images, are sentences and words taken from Wikipedia (CC BY-SA) and from FineWeb-2 (ODC-By 1.0, built from Common Crawl).\nMaterial adapted from Wikipedia must be shared under CC BY-SA 4.0 or a compatible licence; one licence is used for the whole package so that every item is covered.\nWikipedia text contributed before 7 June 2023 is under CC BY-SA 3.0, whose ShareAlike clause allows adaptations under a later version with the same licence elements (CC BY-SA 3.0 legal code, section 4(b)(ii)); Wikipedia text is also available under the GFDL.\n\nATTRIBUTION (required by the sources; lists in the folder attribution/)\n- Wikipedia: every article whose text appears in a released label is listed by language and page id with its URL in attribution/wikipedia_articles.tsv. Text of Wikipedia, the free encyclopedia, by its contributors, CC BY-SA.\n- FineWeb-2 (HuggingFaceFW/fineweb-2), ODC-By 1.0: every source document is listed by its FineWeb-2 id in attribution/fineweb2_documents.tsv. The underlying web pages remain under their authors' rights; use of FineWeb-2 is subject to the Common Crawl terms of use.\n- Fonts: the images were rendered with fonts under the SIL Open Font License 1.1 or the Apache License 2.0 only (attribution/fonts_used.tsv); the fonts themselves are not included. No font of a personal-use licence was drawn on any page of a released item.\n- Maps: Natural Earth vector data (public domain).\n- Paper constants were measured on scans of Zenodo record 15479725 (CC BY 4.0); no pixel of those scans is in any image.\n\nCHANGES\nSentences were cleaned and split by source document, wrapped into lines and drawn as synthetic handwriting and print on synthetic pages, then degraded to look scanned or photographed. Every step is described in datasheet.json.\n\nNO WARRANTY\nThe material is provided as is, without warranties of any kind. The images contain no real person's handwriting; the texts are unfiltered web and encyclopedia sentences and can contain names of real people.\n",
19
  "notices": {
20
  "wikipedia": "Text from Wikipedia (dump 20231101 of the kk, ky, uz, tt, ba, sah, tr, az and tk editions, read through the Hugging Face dataset wikimedia/wikipedia), CC BY-SA; article list with URLs in wikipedia_articles.tsv.",
21
  "fineweb2": "Text from FineWeb-2 (HuggingFaceFW/fineweb-2, configs kaz_Cyrl, kir_Cyrl, uzn_Cyrl, uzn_Latn, tat_Cyrl, bak_Cyrl, sah_Cyrl, tur_Latn, azj_Latn, tuk_Latn), Open Data Commons Attribution License (ODC-By) 1.0; subject to the Common Crawl terms of use; document ids in fineweb2_documents.tsv.",
 
1
  {
2
+ "status": "Input of rel2_build_data.py: the text sources the released data may use, their licence labels, and the texts written as LICENSE, attribution/notices.json and the notice of the real-print pointer list.",
3
  "text_source_kinds_allowed": {
4
  "wiki": true,
5
  "fw2": true,
6
  "ailab": false
7
  },
8
+ "why_ailab_excluded": "The Sakha newspaper sentences (ailabykt/sakha-corpus-mono, sources kyym, eder_saas, sakha_sire, uluus_media) carry CC BY 4.0 on the corpus card, but the newspapers' own sites require a hyperlink to the source for any reuse and Ulus Media requires prior written consent and limits use to personal non-commercial purposes. The corpus rows hold no article links, so the hyperlink condition cannot be met per item, and the consent condition is not met. These sentences are therefore excluded.",
9
  "text_licence_label": {
10
  "wiki": "CC-BY-SA-4.0 (Wikipedia text)",
11
  "fw2": "ODC-By-1.0 (FineWeb-2; Common Crawl terms of use apply)",
12
  "ailab": "CC-BY-4.0 corpus card; newspaper terms apply (not released)"
13
  },
14
  "extra_exclusions_json": "/path/to/TURKIC_OCR_DATA/tmp/release2/sakha_check.json",
15
+ "why_extra_exclusions": "rel2_sakha_check.py found released Sakha items whose label text occurs exactly (6 items) or as a 3-word window (363 more) in a newspaper sentence drawn for their page, although their line attribution named no newspaper document; all 369 are excluded (conservative; window matches can be coincidences).",
16
  "build_print_pointers": true,
17
+ "pointer_notice_text": "Real-print pointer list\n\nWHAT THIS IS\nOne row per real printed text line that the project cut from born-digital PDFs for training (train) and validation (val). The columns include our line id, language, script, split, document id, source, the PDF's URL, the page number, our line box in PDF points (x0,y0,x1,y1), and the render DPI and padding we used. No image and no text of any PDF is included. The test documents are not listed.\n\nSOURCES AND TERMS\nContains information from FinePDFs (HuggingFaceFW/finepdfs), which is made available under the Open Data Commons Attribution License (ODC-By) 1.0; use of FinePDFs is also subject to the Common Crawl terms of use. Turkish lines also come from minutes of the Grand National Assembly of Turkey (tbmm.gov.tr).\nEvery PDF remains under the rights of its rights holders; this list grants no right to the PDFs or their content. To rebuild a line, fetch the PDF from its URL, render the page at the listed DPI and cut the listed box.\nThe line boxes and ids are the project's own work.\n",
18
+ "licence_file_text": "Turkic OCR generated data (page generator pagesynth 0.3.0, frozen 21 Nov 2026)\n\nLICENCE\nThis package is licensed under the Creative Commons Attribution-ShareAlike 4.0 International licence (CC BY-SA 4.0):\nhttps://creativecommons.org/licenses/by-sa/4.0/legalcode\nLicensor: the authors of the project report.\nCopyright 2026 the authors of the project report.\nCite as: A Handwriting Recognition Model for Turkic Languages in Latin and Cyrillic Script. Project report, Nazarbayev University, 2026.\n\nWHY SHARE-ALIKE\nThe label texts, and the text drawn in the images, are sentences and words taken from Wikipedia (CC BY-SA) and from FineWeb-2 (ODC-By 1.0, built from Common Crawl).\nMaterial adapted from Wikipedia must be shared under CC BY-SA 4.0 or a compatible licence; one licence is used for the whole package so that every item is covered.\nWikipedia text contributed before 7 June 2023 is under CC BY-SA 3.0, whose ShareAlike clause allows adaptations under a later version with the same licence elements (CC BY-SA 3.0 legal code, section 4(b)(ii)); Wikipedia text is also available under the GFDL.\n\nATTRIBUTION (required by the sources; lists in the folder attribution/)\n- Wikipedia: every article whose text appears in a released label is listed by language and page id with its URL in attribution/wikipedia_articles.tsv. Text of Wikipedia, the free encyclopedia, by its contributors, CC BY-SA.\n- FineWeb-2 (HuggingFaceFW/fineweb-2), ODC-By 1.0: every source document is listed by its FineWeb-2 id in attribution/fineweb2_documents.tsv. The underlying web pages remain under their authors' rights; use of FineWeb-2 is subject to the Common Crawl terms of use.\n- Fonts: the images were rendered with fonts under the SIL Open Font License 1.1 or the Apache License 2.0 only (attribution/fonts_used.tsv); the fonts themselves are not included. No font of a personal-use licence was drawn on any page of a released item.\n- Maps: Natural Earth vector data (public domain).\n- Paper constants were measured on scans of Zenodo record 15479725 (CC BY 4.0); no pixel of those scans is in any image.\n\nCHANGES\nSentences were cleaned and split by source document, wrapped into lines and drawn as synthetic handwriting and print on synthetic pages, then degraded to look scanned or photographed. Every step is described in datasheet.json.\n\nNO WARRANTY\nThe material is provided as is, without warranties of any kind. The images contain no real person's handwriting; the texts are unfiltered web and encyclopedia sentences and can contain names of real people.\n",
19
  "notices": {
20
  "wikipedia": "Text from Wikipedia (dump 20231101 of the kk, ky, uz, tt, ba, sah, tr, az and tk editions, read through the Hugging Face dataset wikimedia/wikipedia), CC BY-SA; article list with URLs in wikipedia_articles.tsv.",
21
  "fineweb2": "Text from FineWeb-2 (HuggingFaceFW/fineweb-2, configs kaz_Cyrl, kir_Cyrl, uzn_Cyrl, uzn_Latn, tat_Cyrl, bak_Cyrl, sah_Cyrl, tur_Latn, azj_Latn, tuk_Latn), Open Data Commons Attribution License (ODC-By) 1.0; subject to the Common Crawl terms of use; document ids in fineweb2_documents.tsv.",
scripts/release2/rel2_build_data.py CHANGED
@@ -16,7 +16,7 @@ Rules applied per item (all must pass, otherwise the item is excluded and counte
16
  Outputs
17
  hand|typed|clutter/<split>/<lang>/<bucket>/<id>.jpg, pages/<split>/<lang>/<id>.{jpg,json,xml} (PageXML 2019-07-15)
18
  labels/<kind>_<split>.jsonl and .tsv, excluded/excluded_items.tsv, excluded/exclusion_counts.json,
19
- attribution/*.tsv, LICENSE, real_print_pointers/*.tsv (owner decides whether to publish), build_report.json, SHA256SUMS
20
  usage: CODE/.venv_gen/bin/python -I rel2_build_data.py --decisions decisions.json --out DATA/release/rc1_data --threads 8
21
  """
22
  import argparse
@@ -506,7 +506,7 @@ def main():
506
  r.get("page", ""), r.get("dpi", ""), r.get("pad", ""), ",".join(str(v) for v in r.get("bbox_pt", [])),
507
  r.get("size_pt", ""), r.get("sha256", ""), lab)))
508
  pointer_counts[sp] += 1
509
- # separate package (owner decision D7): its own notice and checksums, outside the CC BY-SA data package
510
  PO = OUT.rstrip("/") + "_print_pointers" if not dec.get("pointer_dir") else dec["pointer_dir"]
511
  os.makedirs(PO, exist_ok=True)
512
  psums = {}
 
16
  Outputs
17
  hand|typed|clutter/<split>/<lang>/<bucket>/<id>.jpg, pages/<split>/<lang>/<id>.{jpg,json,xml} (PageXML 2019-07-15)
18
  labels/<kind>_<split>.jsonl and .tsv, excluded/excluded_items.tsv, excluded/exclusion_counts.json,
19
+ attribution/*.tsv, LICENSE, real_print_pointers/*.tsv (whether to publish them is decided separately), build_report.json, SHA256SUMS
20
  usage: CODE/.venv_gen/bin/python -I rel2_build_data.py --decisions decisions.json --out DATA/release/rc1_data --threads 8
21
  """
22
  import argparse
 
506
  r.get("page", ""), r.get("dpi", ""), r.get("pad", ""), ",".join(str(v) for v in r.get("bbox_pt", [])),
507
  r.get("size_pt", ""), r.get("sha256", ""), lab)))
508
  pointer_counts[sp] += 1
509
+ # separate package (project decision D7): its own notice and checksums, outside the CC BY-SA data package
510
  PO = OUT.rstrip("/") + "_print_pointers" if not dec.get("pointer_dir") else dec["pointer_dir"]
511
  os.makedirs(PO, exist_ok=True)
512
  psums = {}
scripts/release2/rel2_d5_data.sbatch CHANGED
@@ -7,7 +7,7 @@
7
  #SBATCH --mem=8G
8
  #SBATCH --time=01:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
- # RELEASE2 D5 finish, data packages: owner decisions of 26 Nov 2026 (D1/D2: real data sets cited with where to obtain them; D8: licensor,
11
  # copyright line and citation). Replaces datasheet.json and LICENSE in DATA/release/rc1_data and DATA/release/rc1_data_parquet, updates
12
  # their two SHA256SUMS lines the way rel2_decide (job 55668) did, verifies every file in full and checks that no file is outside the sums.
13
  # Preconditions (abort with nothing changed): the installed datasheet and LICENSE are the expected files; the staged files have the
 
7
  #SBATCH --mem=8G
8
  #SBATCH --time=01:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
+ # RELEASE2 D5 finish, data packages: project decisions of 26 Nov 2026 (D1/D2: real data sets cited with where to obtain them; D8: licensor,
11
  # copyright line and citation). Replaces datasheet.json and LICENSE in DATA/release/rc1_data and DATA/release/rc1_data_parquet, updates
12
  # their two SHA256SUMS lines the way rel2_decide (job 55668) did, verifies every file in full and checks that no file is outside the sums.
13
  # Preconditions (abort with nothing changed): the installed datasheet and LICENSE are the expected files; the staged files have the
scripts/release2/rel2_d5_detector_retrain.sbatch CHANGED
@@ -7,7 +7,7 @@
7
  #SBATCH --mem=96G
8
  #SBATCH --time=04:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
- # RELEASE2, owner decision D5 (25 Nov 2026): retrain the stage-2 line detector WITHOUT the 83 generated train pages that carry a
11
  # personal-use font, then release it under AGPL-3.0. NOT SUBMITTED by RELEASE2; it queues after the current GPU work.
12
  # Spec: records/R5/RELEASE2/d5/d5_retrain_spec.json. Same recipe as the released stage 2 (yolo_s2, args.yaml): start from our stage-1
13
  # weights yolo_s1c/weights/best.pt (trained on School Notebooks pages only, no generated page), image size 1280, batch 16, 200 epochs
 
7
  #SBATCH --mem=96G
8
  #SBATCH --time=04:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
+ # RELEASE2, project decision D5 (25 Nov 2026): retrain the stage-2 line detector WITHOUT the 83 generated train pages that carry a
11
  # personal-use font, then release it under AGPL-3.0. NOT SUBMITTED by RELEASE2; it queues after the current GPU work.
12
  # Spec: records/R5/RELEASE2/d5/d5_retrain_spec.json. Same recipe as the released stage 2 (yolo_s2, args.yaml): start from our stage-1
13
  # weights yolo_s1c/weights/best.pt (trained on School Notebooks pages only, no generated page), image size 1280, batch 16, 200 epochs
scripts/release2/rel2_d5_prep.py CHANGED
@@ -1,4 +1,4 @@
1
- """RELEASE2 owner decisions D4 and D5 (25 Nov 2026), CPU part. Nothing is trained here.
2
 
3
  D5: build the stage-2 detector training set without the 83 generated train pages that carry a personal-use font:
4
  DATA/data/processed/r5_linedet_det/gen_d5/train/{images,labels} copies of the 3,916 remaining generated train pages (image + YOLO label)
 
1
+ """RELEASE2 project decisions D4 and D5 (25 Nov 2026), CPU part. Nothing is trained here.
2
 
3
  D5: build the stage-2 detector training set without the 83 generated train pages that carry a personal-use font:
4
  DATA/data/processed/r5_linedet_det/gen_d5/train/{images,labels} copies of the 3,916 remaining generated train pages (image + YOLO label)
scripts/release2/rel2_d5_prep.sbatch CHANGED
@@ -7,7 +7,7 @@
7
  #SBATCH --mem=16G
8
  #SBATCH --time=00:40:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
- # RELEASE2 owner decisions (25 Nov 2026): D5 data preparation and D4 page counts (rel2_d5_prep.py), and the licence texts the packages
11
  # must ship (downloaded as plain text into DATA/tmp/release2/licence_texts/, never executed; sha256 recorded).
12
  set -u
13
  D=/path/to/TURKIC_OCR_DATA
 
7
  #SBATCH --mem=16G
8
  #SBATCH --time=00:40:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
+ # RELEASE2 project decisions (25 Nov 2026): D5 data preparation and D4 page counts (rel2_d5_prep.py), and the licence texts the packages
11
  # must ship (downloaded as plain text into DATA/tmp/release2/licence_texts/, never executed; sha256 recorded).
12
  set -u
13
  D=/path/to/TURKIC_OCR_DATA
scripts/release2/rel2_decisions_install.sbatch CHANGED
@@ -7,7 +7,7 @@
7
  #SBATCH --mem=8G
8
  #SBATCH --time=01:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
- # RELEASE2: install the owner decisions of 25 Nov 2026 into the release folders. No weight changes.
11
  # packages: new model_card.json; LICENSE / NOTICE; licence texts (LICENSE.Apache-2.0 for the readers, LICENSE.base-model for PaddleOCR-VL,
12
  # LICENSE = AGPL-3.0 text for detector and page pipeline); SHA256SUMS rewritten and verified; weights hashed before and after.
13
  # data: the updated datasheet.json into rc1_data and rc1_data_parquet; their SHA256SUMS updated and verified in full.
 
7
  #SBATCH --mem=8G
8
  #SBATCH --time=01:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
+ # RELEASE2: install the project decisions of 25 Nov 2026 into the release folders. No weight changes.
11
  # packages: new model_card.json; LICENSE / NOTICE; licence texts (LICENSE.Apache-2.0 for the readers, LICENSE.base-model for PaddleOCR-VL,
12
  # LICENSE = AGPL-3.0 text for detector and page pipeline); SHA256SUMS rewritten and verified; weights hashed before and after.
13
  # data: the updated datasheet.json into rc1_data and rc1_data_parquet; their SHA256SUMS updated and verified in full.
scripts/release2/rel2_parquet.py CHANGED
@@ -1,4 +1,4 @@
1
- """RELEASE2 owner decision D9 (25 Nov 2026): the generated-data package as Parquet shards with embedded images.
2
 
3
  Input : DATA/release/rc1_data (labels/<kind>_<split>.jsonl, the images, SHA256SUMS, LICENSE, attribution/, excluded/, build_report.json)
4
  Output: DATA/release/rc1_data_parquet/
 
1
+ """RELEASE2 project decision D9 (25 Nov 2026): the generated-data package as Parquet shards with embedded images.
2
 
3
  Input : DATA/release/rc1_data (labels/<kind>_<split>.jsonl, the images, SHA256SUMS, LICENSE, attribution/, excluded/, build_report.json)
4
  Output: DATA/release/rc1_data_parquet/
src/pagesynth/pagesynth/fonts.py CHANGED
@@ -20,13 +20,13 @@ apostrophe (U+02BC): the font's own U+2018/U+2019 or the ASCII apostrophe is
20
  drawn and the LABEL is changed to the drawn mark (orig text is kept in the
21
  page JSON).
22
 
23
- Licence classes: ofl, apache2 (open), personal_use_only (the owner's Latin signature fonts:
24
- "personal use only" or "demo"). R5 (20 Nov 2026): the owner allows these eight for TRAINING data;
25
  they are never shown on the pages or shipped (display mode drops them: include_personal=False).
26
 
27
  FONT WEIGHTS (R5, generator 0.3.0): every handwriting font gets the same weight (w = 1.0 for each script it
28
  may be used for). The older comment "Caveat and Bad Script highest, Pacifico low, Shantell Sans lowest" is
29
- superseded by the owner's instruction of 21 Nov 2026 (Caveat and Bad Script had 81 percent of the Cyrillic
30
  handwriting lines in pilot v0.2.0). A font is still drawn only for sentences that it fully covers
31
  (layouts.choose_writer rejects a font that draws fewer than 35 percent of the language's sentences), so
32
  the share of a font in a language is its weight divided by the weights of the fonts that cover that
 
20
  drawn and the LABEL is changed to the drawn mark (orig text is kept in the
21
  page JSON).
22
 
23
+ Licence classes: ofl, apache2 (open), personal_use_only (the project's Latin signature fonts:
24
+ "personal use only" or "demo"). R5 (20 Nov 2026): these eight are allowed for TRAINING data;
25
  they are never shown on the pages or shipped (display mode drops them: include_personal=False).
26
 
27
  FONT WEIGHTS (R5, generator 0.3.0): every handwriting font gets the same weight (w = 1.0 for each script it
28
  may be used for). The older comment "Caveat and Bad Script highest, Pacifico low, Shantell Sans lowest" is
29
+ superseded by the decision of 21 Nov 2026 (Caveat and Bad Script had 81 percent of the Cyrillic
30
  handwriting lines in pilot v0.2.0). A font is still drawn only for sentences that it fully covers
31
  (layouts.choose_writer rejects a font that draws fewer than 35 percent of the language's sentences), so
32
  the share of a font in a language is its weight divided by the weights of the fonts that cover that
src/pagesynth/pagesynth/langtext.py CHANGED
@@ -1,6 +1,6 @@
1
  """Counting words of the page language in drawn lines (shared by the h_language_text gate and the audit).
2
 
3
- Why a shared module: the owner's complaint (20 Nov 2026) was that figures carried only numbers and
4
  symbols. The audit and the gate must therefore count the same thing, otherwise "before" and "after"
5
  numbers are not comparable.
6
 
 
1
  """Counting words of the page language in drawn lines (shared by the h_language_text gate and the audit).
2
 
3
+ Why a shared module: figures must carry words of the page language, not only numbers and
4
  symbols. The audit and the gate must therefore count the same thing, otherwise "before" and "after"
5
  numbers are not comparable.
6
 
src/pagesynth/pagesynth/scenes.py CHANGED
@@ -661,7 +661,7 @@ def scene_worksheet(page, paper, layout, rng, bank, lang, include_personal, tabl
661
  def _table(page, paper, layout, rng, bank, lang, pw, hw, y, x0, x1, big=False):
662
  """Ruled table with a printed header row of words and hand-filled cells. Column 0 holds words (row labels, one or two
663
  vocabulary words per cell, never empty); every other column holds words or numbers. A table of only numbers is not
664
- drawn: it would carry no text of the language (owner, 20 Nov 2026)."""
665
  Wf, Hf = page.Wf, page.Hf
666
  n_cols = int(rng.integers(3 if big else 2, 7 if big else 5))
667
  n_rows = int(rng.integers(6 if big else 3, 14 if big else 6))
 
661
  def _table(page, paper, layout, rng, bank, lang, pw, hw, y, x0, x1, big=False):
662
  """Ruled table with a printed header row of words and hand-filled cells. Column 0 holds words (row labels, one or two
663
  vocabulary words per cell, never empty); every other column holds words or numbers. A table of only numbers is not
664
+ drawn: it would carry no text of the language."""
665
  Wf, Hf = page.Wf, page.Hf
666
  n_cols = int(rng.integers(3 if big else 2, 7 if big else 5))
667
  n_rows = int(rng.integers(6 if big else 3, 14 if big else 6))
src/pagesynth/pagesynth/vocab.py CHANGED
@@ -1,6 +1,6 @@
1
  """Label vocabulary: lower-case words of the language's own corpus for the word labels of figures, tables and maps.
2
 
3
- Why: a figure needs words in the page language (owner, 20 Nov 2026), and no word may be invented or
4
  translated here. The words are the frequency-ranked lower-case words of the corpus (scripts/build_label_vocab.py):
5
  * 3 to 12 letters, every letter in the language's own alphabet, no digits, no hyphen, no Russian function word;
6
  * lower-case only: a word counts only if it is (almost) never written with a capital in the middle of a
 
1
  """Label vocabulary: lower-case words of the language's own corpus for the word labels of figures, tables and maps.
2
 
3
+ Why: a figure needs words in the page language, and no word may be invented or
4
  translated here. The words are the frequency-ranked lower-case words of the corpus (scripts/build_label_vocab.py):
5
  * 3 to 12 letters, every letter in the language's own alphabet, no digits, no hyphen, no Russian function word;
6
  * lower-case only: a word counts only if it is (almost) never written with a capital in the middle of a
src/rq2/aug.py CHANGED
@@ -7,10 +7,10 @@ Random numbers: one generator per training sample, numpy default_rng([seed, 4242
7
  fixed and the same in both policies: slot u = integers(0, 7), then z1 = random(), z2 = random(); each policy maps (z1, z2) to
8
  its own parameter range, so the same sample gets the same slot and the same relative magnitude in all four arms of a seed.
9
 
10
- Typical = TrOCR build_data_aug(mode='train') (microsoft/unilm trocr/data_aug.py @ 581af18, torchvision 0.8.2 defaults); the
11
- constants and their line numbers are in records/R5/RQ2/trocr_policy.json.
12
  Safe = proposal section 5 as read by the design: rotation within +-2 deg (and never forcing a downscale below 0.75x), blur
13
- sigma <= H/64, shear +-0.5 DEGREES (owner decision 2026-11-26), 2x2 thickening at 64 px only, downscale >= 0.75x, translation
14
  by padding; it never thins strokes.
15
  """
16
  import math
 
7
  fixed and the same in both policies: slot u = integers(0, 7), then z1 = random(), z2 = random(); each policy maps (z1, z2) to
8
  its own parameter range, so the same sample gets the same slot and the same relative magnitude in all four arms of a seed.
9
 
10
+ Typical = TrOCR build_data_aug(mode='train') (microsoft/unilm trocr/data_aug.py, torchvision 0.8.2 defaults); the
11
+ constants below are copied from that file.
12
  Safe = proposal section 5 as read by the design: rotation within +-2 deg (and never forcing a downscale below 0.75x), blur
13
+ sigma <= H/64, shear +-0.5 DEGREES, 2x2 thickening at 64 px only, downscale >= 0.75x, translation
14
  by padding; it never thins strokes.
15
  """
16
  import math
tests/data/sample_eval/evalsets.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "registry_version": "sample",
3
+ "sets": [
4
+ {"name": "sample_lines", "manifest": "tests/data/sample_eval/manifests/sample_lines.tsv", "split": "val", "locked": false,
5
+ "group_unit": "page"}
6
+ ]
7
+ }
tests/data/sample_eval/manifests/sample_lines.tsv ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ id image text lang script kind source split group unit
2
+ sample:01 images/sample_01.png Мектеп ауласында бәйтерек өседі kk Cyrl hand_synth sample val page_1 line
3
+ sample:02 images/sample_02.png Қазақ тілі сабағы басталды kk Cyrl hand_synth sample val page_1 line
4
+ sample:03 images/sample_03.png Біз кітапханаға бардық kk Cyrl hand_synth sample val page_2 line
5
+ sample:04 images/sample_04.png Бүгүн аба ырайы жакшы ky Cyrl hand_synth sample val page_2 line
6
+ sample:05 images/sample_05.png Казан шәһәре зур tt Cyrl hand_synth sample val page_3 line
7
+ sample:06 images/sample_06.png Öğrenciler bahçede oynuyor tr Latn hand_synth sample val page_3 line
8
+ sample:07 images/sample_07.png Bakı dənizin sahilindədir az Latn hand_synth sample val page_4 line
9
+ sample:08 images/sample_08.png Toshkent katta shahar uz Latn hand_synth sample val page_4 line
10
+ sample:09 images/sample_09.png Aşgabat ak mermerden gurlan tk Latn hand_synth sample val page_5 line
11
+ sample:10 images/sample_10.png Саха сирэ кэрэ sah Cyrl hand_synth sample val page_5 line
tests/data/sample_eval/preds/demo/final/sample_lines.tsv ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ id ref hyp
2
+ sample:01 Мектеп ауласында бәйтерек өседі Мектеп ауласында байтерек өседі
3
+ sample:02 Қазақ тілі сабағы басталды Казак тілі сабағы басталды
4
+ sample:03 Біз кітапханаға бардық Біз кітапханаға бардық
5
+ sample:04 Бүгүн аба ырайы жакшы Бүгүн аба ырайы жакшы
6
+ sample:05 Казан шәһәре зур Казан шэһэре зур
7
+ sample:06 Öğrenciler bahçede oynuyor Ogrenciler bahçede oynuyor
8
+ sample:07 Bakı dənizin sahilindədir Baki dənizin sahilindədir
9
+ sample:08 Toshkent katta shahar Toshkent kata shahar
10
+ sample:09 Aşgabat ak mermerden gurlan Aşgabat ak mermerden gurlan.
11
+ sample:10 Саха сирэ кэрэ Саха сирэ кэрэ
tests/test_edit_distance.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Edit distance: the scorer's alignment (r5eval.align) against the reference implementation in r5eval/frozen."""
2
+ import random
3
+
4
+ import pytest
5
+
6
+ from r5eval import align
7
+ from r5eval.frozen import j2
8
+
9
+
10
+ def counts(ref: str, hyp: str) -> tuple[int, int, int, int]:
11
+ """Distance, substitutions, deletions and insertions from align_ops."""
12
+ dist, ops = align.align_ops(ref, hyp)
13
+ return (dist, *align.op_counts(ops))
14
+
15
+
16
+ @pytest.mark.parametrize(
17
+ "ref, hyp, expected",
18
+ [
19
+ ("kitten", "sitting", (3, 2, 0, 1)),
20
+ ("қазақ", "казак", (2, 2, 0, 0)),
21
+ ("Toshkent katta", "Toshkent kata", (1, 0, 1, 0)),
22
+ ("abc", "abc", (0, 0, 0, 0)),
23
+ ("", "ab", (2, 0, 0, 2)),
24
+ ("ab", "", (2, 0, 2, 0)),
25
+ ],
26
+ )
27
+ def test_align_ops_counts(ref, hyp, expected):
28
+ assert counts(ref, hyp) == expected
29
+ assert j2.align(ref, hyp) == expected
30
+
31
+
32
+ def test_align_ops_lists_every_character():
33
+ dist, ops = align.align_ops("бала", "бала!")
34
+ assert dist == 1
35
+ assert [o for o, _, _ in ops] == ["M", "M", "M", "M", "I"]
36
+
37
+
38
+ def test_fast_distance_matches_alignment_on_random_pairs():
39
+ rnd = random.Random(7)
40
+ letters = "аәбғқңөұүһіклмнопрс"
41
+ for _ in range(300):
42
+ a = "".join(rnd.choice(letters) for _ in range(rnd.randint(0, 20)))
43
+ b = "".join(rnd.choice(letters) for _ in range(rnd.randint(0, 20)))
44
+ assert align.lev_fast(a, b) == align.align_ops(a, b)[0] == j2.align(a, b)[0]
45
+
46
+
47
+ def test_line_assignment_pairs_lines_in_any_order():
48
+ total, pairs = align.min_cost_line_assignment(["abc", "de"], ["de", "abd"])
49
+ assert total == 1
50
+ assert sorted(pairs) == [(0, 1), (1, 0)]
51
+
52
+
53
+ def test_crop_cer_is_distance_over_reference_length():
54
+ s = j2.score_crop("Сәлем әлем", "Сэлем әлем")
55
+ assert s["ref"] == "Сәлем әлем"
56
+ assert s["dist"] == 1
57
+ assert s["cer"] == pytest.approx(1 / 10)