treoa commited on
Commit
0d02ed4
·
verified ·
1 Parent(s): 46fb086

Clean up comments and file headers; point to the model repositories

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. NOTICE +1 -2
  2. README.md +21 -4
  3. scripts/b1_page_check/b1_page_check.py +0 -8
  4. scripts/b1_page_check/b1_page_check.sbatch +0 -1
  5. scripts/b1_page_check/b1_page_score.py +0 -8
  6. scripts/b1_page_check/base_page_check.sbatch +0 -2
  7. scripts/b1_page_check/detb1_page_check.py +0 -9
  8. scripts/b1_page_check/detb1_page_check.sbatch +0 -1
  9. scripts/j2/build_screen_set.py +0 -4
  10. scripts/j2/check_images_kwargs.py +0 -2
  11. scripts/j2/collect.py +0 -9
  12. scripts/j2/contrast_stretch.py +0 -6
  13. scripts/j2/control_report.py +0 -4
  14. scripts/j2/control_run_cpu.sbatch +0 -2
  15. scripts/j2/control_run_gpu.sbatch +0 -2
  16. scripts/j2/controls2_report.py +0 -6
  17. scripts/j2/controls2_run_cpu.sbatch +0 -2
  18. scripts/j2/eligibility.py +0 -11
  19. scripts/j2/eligibility.sbatch +0 -1
  20. scripts/j2/fetch_weights_loadtest.py +0 -7
  21. scripts/j2/fetch_weights_loadtest.sbatch +0 -1
  22. scripts/j2/finalize.sbatch +0 -2
  23. scripts/j2/harness_audit.py +0 -6
  24. scripts/j2/harness_audit.sbatch +0 -1
  25. scripts/j2/keyaudit.py +0 -7
  26. scripts/j2/keyaudit.sbatch +0 -1
  27. scripts/j2/make_control_set.py +0 -11
  28. scripts/j2/make_control_set.sbatch +0 -1
  29. scripts/j2/make_controls2_set.py +0 -11
  30. scripts/j2/make_controls2_set.sbatch +0 -1
  31. scripts/j2/raw_samples.py +0 -5
  32. scripts/j2/run_gpu_job.sbatch +0 -4
  33. scripts/j2/run_screen.py +0 -10
  34. scripts/j2/setup_env_vlm.sbatch +0 -1
  35. scripts/j2/smoke_cpu.sbatch +0 -2
  36. scripts/j2/smoke_gpu.sbatch +0 -2
  37. scripts/j2/test_collect.py +0 -2
  38. scripts/j2/test_contrast_stretch.py +0 -1
  39. scripts/j2/test_controls2_report.py +0 -1
  40. scripts/kohtd_leak_scan.py +10 -10
  41. scripts/kohtd_leak_scan.sbatch +0 -1
  42. scripts/r5/r5_after_gen.sbatch +0 -3
  43. scripts/r5/r5_build_A.sbatch +0 -1
  44. scripts/r5/r5_build_B.sbatch +0 -1
  45. scripts/r5/r5_build_C.sbatch +0 -1
  46. scripts/r5/r5_build_real.py +8 -22
  47. scripts/r5/r5_disk_counts.py +0 -4
  48. scripts/r5/r5_fetch_az_htr.py +0 -5
  49. scripts/r5/r5_finalize.sbatch +0 -1
  50. scripts/r5/r5_kohtd_check.py +0 -1
NOTICE CHANGED
@@ -56,5 +56,4 @@ scripts/r5_ref/ref_common.py sets (PPOCR_ROOT); it is not included.
56
 
57
  NOT INCLUDED
58
 
59
- No data, no font files and no weights of the fine-tuned readers (PaddleOCR-VL-1.6, Qwen3-VL-2B, PP-OCRv6-medium and its
60
- character language model). See README.
 
56
 
57
  NOT INCLUDED
58
 
59
+ No data and no font files. The weights of the fine-tuned readers are in their own gated repositories (see README).
 
README.md CHANGED
@@ -91,6 +91,25 @@ grep -rlF /path/to/TURKIC_OCR_DATA . | xargs sed -i 's#/path/to/TURKIC_OCR_DATA#
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`,
@@ -173,9 +192,7 @@ contain no item drawn with them.
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
 
@@ -196,7 +213,7 @@ study, run on validation data only.
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.
 
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
+ ## Models
95
+
96
+ The trained readers are gated repositories on the Hugging Face Hub: access follows a request in which you agree to use the weights for
97
+ non-commercial research only (they were trained on data with such terms). Each repository has `infer.py`, `requirements.txt`, a model card
98
+ and the weights in `model/`.
99
+
100
+ | Repository | Content |
101
+ |---|---|
102
+ | `treoa/turkic-ocr-paddleocr-vl-1.6` | the shipped PaddleOCR-VL-1.6 (the headline results of the report) |
103
+ | `treoa/turkic-ocr-paddleocr-vl-1.6-latin` | the same model after continued training on real Latin-script lines (three seeds); recommended for Latin-script text |
104
+ | `treoa/turkic-ocr-qwen3-vl-2b` | Qwen3-VL-2B, the comparison model |
105
+ | `treoa/turkic-ocr-qwen3-vl-2b-latin` | its continuation (two seeds) |
106
+ | `treoa/turkic-ocr-ppocrv6-medium` | the light CTC line recognizer with a character 6-gram language model |
107
+ | `treoa/turkic-line-detector-yolo11s` | the line detector (public) |
108
+
109
+ ```bash
110
+ hf download treoa/turkic-ocr-paddleocr-vl-1.6 --local-dir models/paddleocr-vl
111
+ ```
112
+
113
  ## Data
114
 
115
  No dataset is stored here. The generated data are on the Hugging Face Hub, in four configurations (`hand`, `typed`,
 
192
  Training. The training entry points are `scripts/r5_vlma/train_vlm.py` (full fine-tuning of the vision-language
193
  readers), `scripts/r5_vlmb/vlmb_train.py` (readers that need their maker's code), `src/linedet/train_arm.py` (CTC line
194
  recognizers), `src/linedet/det_yolo.py` (detector) and `scripts/r5_rq2/rq2_train.py` (augmentation study). The full
195
+ runs need H100 GPUs on a Slurm cluster and the licensed real data, KOHTD and HKR above all. The reader weights trained in the project are released in gated repositories for non-commercial research (see Models); the terms of KOHTD and HKR limit anything trained on them to academic research. The detector was trained on School Notebooks photos and generated pages, and its weights are public.
 
 
196
 
197
  ## Seeds
198
 
 
213
  ## Not included
214
 
215
  - Data of any kind: real datasets, generated data, manifests, splits, predictions.
216
+ - Weights of the fine-tuned readers: they are in their own gated repositories (see Models).
217
  - Font files.
218
  - The scripts of the continued training on real Latin-script handwriting, of the IAM scoring and of the later,
219
  more realistic generator version.
scripts/b1_page_check/b1_page_check.py CHANGED
@@ -1,11 +1,3 @@
1
- """Quick whole-page check of B1 (PaddleOCR-VL 1.6 R5 leader) on CPU: one prompt, a few validation pages.
2
-
3
- Not a benchmark: a smoke sample before a deadline. Validation pages only. Reuses the R5 loader and prompt builder
4
- (CODE/scripts/r5_vlma/vlm_common.py) with the instruction swapped, greedy decoding, bf16 as in the R5 evaluation.
5
- Writes one JSON line per page as soon as it is read, and stops before --stop_utc.
6
-
7
- usage: b1_page_check.py --model DIR --pages TSV --start K --n N --prompt spot|instr|ocr --out JSONL --stop_utc HH:MM
8
- """
9
  import argparse
10
  import json
11
  import os
 
 
 
 
 
 
 
 
 
1
  import argparse
2
  import json
3
  import os
scripts/b1_page_check/b1_page_check.sbatch CHANGED
@@ -6,7 +6,6 @@
6
  #SBATCH --time=00:45:00
7
  #SBATCH --array=0-7
8
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%A_%a.out
9
- # Task t: prompt = spot (t<4) or instr; set = gen (t%4<2) or school; chunk = t%2 of 2 (5 pages each).
10
  set -u
11
  CODE=/path/to/TURKIC_OCR_CODE
12
  D=/path/to/TURKIC_OCR_DATA
 
6
  #SBATCH --time=00:45:00
7
  #SBATCH --array=0-7
8
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%A_%a.out
 
9
  set -u
10
  CODE=/path/to/TURKIC_OCR_CODE
11
  D=/path/to/TURKIC_OCR_DATA
scripts/b1_page_check/b1_page_score.py CHANGED
@@ -1,11 +1,3 @@
1
- """Score the B1 whole-page check, and route A (YOLO11s stage 2 + A1 long) on the SAME pages for comparison.
2
-
3
- Page CER exactly as linedet.det_eval.page_cers (metric M28 reading order: lines joined by one space; M29 order free:
4
- lines matched one to one by minimum edit distance, unmatched lines count in full). Micro average: summed edits over
5
- summed reference characters. B1 lines keep the model's own output order.
6
-
7
- usage: b1_page_score.py --dir OUT_DIR --routeA_dir DET_EVAL_DIR --out JSON
8
- """
9
  import argparse
10
  import glob
11
  import json
 
 
 
 
 
 
 
 
 
1
  import argparse
2
  import glob
3
  import json
scripts/b1_page_check/base_page_check.sbatch CHANGED
@@ -6,8 +6,6 @@
6
  #SBATCH --time=00:40:00
7
  #SBATCH --array=0-5
8
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%A_%a.out
9
- # The original PaddleOCR-VL 1.6 (the pinned copy B1 was fine-tuned from) on the same pages as b1_page_check.
10
- # Task t: prompt = spot (t<4) or ocr (t>=4, generated pages only); set = gen (t%4<2) or school; chunk = t%2.
11
  set -u
12
  CODE=/path/to/TURKIC_OCR_CODE
13
  D=/path/to/TURKIC_OCR_DATA
 
6
  #SBATCH --time=00:40:00
7
  #SBATCH --array=0-5
8
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%A_%a.out
 
 
9
  set -u
10
  CODE=/path/to/TURKIC_OCR_CODE
11
  D=/path/to/TURKIC_OCR_DATA
scripts/b1_page_check/detb1_page_check.py CHANGED
@@ -1,12 +1,3 @@
1
- """Line detector + B1 on the same sampled validation pages as b1_page_check.py.
2
-
3
- The detector boxes are the stored YOLO11s stage-2 boxes from the route A run (det_eval e2e_yolo_s2_*_A1_long_pages.jsonl),
4
- so detection is identical to route A and only the reader changes (A1 -> B1). Reading order, crop margins and the school
5
- full-resolution lookup are copied from linedet.det_eval. B1 reads each crop with its training instruction, greedy, bf16 on
6
- CPU, at most 192 new tokens per line (vlm_common.MAXNEW['line']).
7
-
8
- usage: detb1_page_check.py --set gen|school --pages TSV --stride K --n 10 --chunk C --chunks 2 --routeA JSONL --out JSONL
9
- """
10
  import argparse
11
  import json
12
  import os
 
 
 
 
 
 
 
 
 
 
1
  import argparse
2
  import json
3
  import os
scripts/b1_page_check/detb1_page_check.sbatch CHANGED
@@ -6,7 +6,6 @@
6
  #SBATCH --time=00:35:00
7
  #SBATCH --array=0-7
8
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%A_%a.out
9
- # Task t: set = gen (t<4) or school; chunk = t%4 of 4 (2-3 pages each).
10
  set -u
11
  CODE=/path/to/TURKIC_OCR_CODE
12
  D=/path/to/TURKIC_OCR_DATA
 
6
  #SBATCH --time=00:35:00
7
  #SBATCH --array=0-7
8
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%A_%a.out
 
9
  set -u
10
  CODE=/path/to/TURKIC_OCR_CODE
11
  D=/path/to/TURKIC_OCR_DATA
scripts/j2/build_screen_set.py CHANGED
@@ -1,7 +1,3 @@
1
- """Build screen_set_v1.tsv by screen_rule_v1.txt. Reads only validation.tsv.
2
-
3
- usage: build_screen_set.py VALIDATION_TSV OUT_TSV
4
- """
5
  import collections
6
  import hashlib
7
  import sys
 
 
 
 
 
1
  import collections
2
  import hashlib
3
  import sys
scripts/j2/check_images_kwargs.py CHANGED
@@ -1,5 +1,3 @@
1
- """Does images_kwargs (size) reach the image processor in apply_chat_template? Processor only, one crop, no model.
2
- usage: check_images_kwargs.py MODELS_DIR PROMPTS_JSON IMG_DIR CROP_FILE short [short ...]"""
3
  import json
4
  import os
5
  import sys
 
 
 
1
  import json
2
  import os
3
  import sys
scripts/j2/collect.py CHANGED
@@ -1,12 +1,3 @@
1
- """Turn finished (or partly finished) J2 outputs into results.tsv. Run on the cluster (the per-crop files hold labels and stay there).
2
-
3
- usage: collect.py OUT_ROOT SCREEN_SET_TSV SCORELIB_PY RESULTS_TSV [model ...]
4
- OUT_ROOT = DATA/outputs/j11_stage1_kohtd (model folders s1/ s2/ s3/ with preds.jsonl, timing.jsonl, meta.json).
5
- Robust to a job killed by its time limit: a half-written last line of preds.jsonl or timing.jsonl is skipped and counted
6
- (bad_lines); if meta.json was never written the row is filled from timing.jsonl, the screen set and loadtest/<model>.json.
7
- Every speed and memory column carries the suffix _H100_not_5090: all figures come from one H100, not from an RTX 5090.
8
- A row is complete when crops_done == crops_in_list; the column complete says so.
9
- """
10
  import importlib.util
11
  import json
12
  import os
 
 
 
 
 
 
 
 
 
 
1
  import importlib.util
2
  import json
3
  import os
scripts/j2/contrast_stretch.py CHANGED
@@ -1,9 +1,3 @@
1
- """Per-crop contrast stretch for the J2 contrast control. One function; it changes the grey levels and nothing else.
2
-
3
- contrast_stretch(img): the 1st and 99th percentile of the crop's grey (PIL 'L' conversion) are mapped to 0 and 255; the same
4
- linear map is applied to the three colour channels, so colour relations are kept; values are clipped to 0..255. Size and mode
5
- (RGB) do not change. A crop with a grey range below 1 level is returned unchanged (as RGB).
6
- """
7
  import numpy as np
8
  from PIL import Image
9
 
 
 
 
 
 
 
 
1
  import numpy as np
2
  from PIL import Image
3
 
scripts/j2/control_report.py CHANGED
@@ -1,7 +1,3 @@
1
- """Score the positive control with the screen's scorelib (same post-processing, same CER) and write positive_control.tsv.
2
- usage: control_report.py CONTROL_LIST SCORELIB_PY OUT_TSV label=OUT_ROOT [label=OUT_ROOT ...]
3
- label is cpu or gpu; OUT_ROOT holds <model>/s1/preds.jsonl.
4
- """
5
  import importlib.util
6
  import json
7
  import os
 
 
 
 
 
1
  import importlib.util
2
  import json
3
  import os
scripts/j2/control_run_cpu.sbatch CHANGED
@@ -7,8 +7,6 @@
7
  #SBATCH --mem=64G
8
  #SBATCH --time=06:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
- # J2 positive control on ZEN4 CPU: the SAME run_screen.py, prompts, batch size 16, 1x, bf16, greedy, 48 new tokens, on the 400
11
- # printed control images. Output folder: DATA/outputs/j11_positive_control/out_cpu. usage: sbatch control_run_cpu.sbatch short [short ...]
12
  set -u
13
  CODE=/path/to/TURKIC_OCR_CODE
14
  DATA=/path/to/TURKIC_OCR_DATA
 
7
  #SBATCH --mem=64G
8
  #SBATCH --time=06:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
 
 
10
  set -u
11
  CODE=/path/to/TURKIC_OCR_CODE
12
  DATA=/path/to/TURKIC_OCR_DATA
scripts/j2/control_run_gpu.sbatch CHANGED
@@ -7,8 +7,6 @@
7
  #SBATCH --mem=96G
8
  #SBATCH --time=01:30:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
- # J2 positive control on one H100: the SAME run_screen.py, prompts, batch size 16, 1x, bf16, greedy, 48 new tokens, on the 400
11
- # printed control images. Output folder: DATA/outputs/j11_positive_control/out_gpu. usage: sbatch control_run_gpu.sbatch short [short ...]
12
  set -u
13
  CODE=/path/to/TURKIC_OCR_CODE
14
  DATA=/path/to/TURKIC_OCR_DATA
 
7
  #SBATCH --mem=96G
8
  #SBATCH --time=01:30:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
 
 
10
  set -u
11
  CODE=/path/to/TURKIC_OCR_CODE
12
  DATA=/path/to/TURKIC_OCR_DATA
scripts/j2/controls2_report.py CHANGED
@@ -1,9 +1,3 @@
1
- """Score the two small controls (contrast, handwriting fonts) with the screen's scorelib and write controls_2.tsv.
2
- A printed-text row (PT Sans, 40 px, from the first positive control) is scored with the same code for comparison.
3
-
4
- usage: controls2_report.py C2_DIR PRINTED_LIST PRINTED_OUT_ROOT SCORELIB_PY OUT_TSV
5
- C2_DIR holds contrast_stored_/contrast_stretch_/fonts_screen_set_v1.tsv and out_stored/ out_stretch/ out_fonts/.
6
- """
7
  import importlib.util
8
  import json
9
  import os
 
 
 
 
 
 
 
1
  import importlib.util
2
  import json
3
  import os
scripts/j2/controls2_run_cpu.sbatch CHANGED
@@ -7,8 +7,6 @@
7
  #SBATCH --mem=64G
8
  #SBATCH --time=04:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
- # J2 controls 2 on ZEN4 CPU: the SAME run_screen.py, prompts, batch size 16, 1x, bf16, greedy, 48 new tokens.
11
- # usage: sbatch controls2_run_cpu.sbatch SET:MODEL [SET:MODEL ...] with SET = stored | stretch | fonts
12
  set -u
13
  CODE=/path/to/TURKIC_OCR_CODE
14
  DATA=/path/to/TURKIC_OCR_DATA
 
7
  #SBATCH --mem=64G
8
  #SBATCH --time=04:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
 
 
10
  set -u
11
  CODE=/path/to/TURKIC_OCR_CODE
12
  DATA=/path/to/TURKIC_OCR_DATA
scripts/j2/eligibility.py CHANGED
@@ -1,14 +1,3 @@
1
- """J2 step 2: eligibility facts for the 20 models of screen.list_S. Runs on a ZEN4 node with .venv_vlm.
2
-
3
- Downloads (no token, no .py file) only config, tokenizer, processor, chat template and README files and
4
- reads the file list with sizes from the Hub API. Then, with the pinned transformers release only:
5
- - checks that model_type and architecture are native classes (trust_remote_code is never set),
6
- - builds the native model class on the meta device (no weights) and counts parameters,
7
- - loads the tokenizer and the processor with trust_remote_code=False,
8
- - round-trips the 238 project symbols and all validation labels through the tokenizer (E3).
9
-
10
- usage: eligibility.py MODELS_TSV CODEC_JSON VALIDATION_TSV MODELS_DIR OUT_DIR [only_short ...]
11
- """
12
  import collections
13
  import json
14
  import os
 
 
 
 
 
 
 
 
 
 
 
 
1
  import collections
2
  import json
3
  import os
scripts/j2/eligibility.sbatch CHANGED
@@ -7,7 +7,6 @@
7
  #SBATCH --mem=24G
8
  #SBATCH --time=02:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
- # J2 step 2: eligibility facts. Downloads only config/tokenizer/processor/template/README files (no .py, no weights), no token.
11
  set -eu
12
  CODE=/path/to/TURKIC_OCR_CODE
13
  DATA=/path/to/TURKIC_OCR_DATA
 
7
  #SBATCH --mem=24G
8
  #SBATCH --time=02:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
 
10
  set -eu
11
  CODE=/path/to/TURKIC_OCR_CODE
12
  DATA=/path/to/TURKIC_OCR_DATA
scripts/j2/fetch_weights_loadtest.py CHANGED
@@ -1,10 +1,3 @@
1
- """J2 step 2b: fetch root-level safetensors weights of the run candidates and test the native weight load on CPU.
2
-
3
- No token, no .py file, trust_remote_code is never set. A model passes the load gate only if from_pretrained with the
4
- native class reports no missing key and no mismatched key; unexpected keys are listed for reading.
5
-
6
- usage: fetch_weights_loadtest.py MODELS_DIR OUT_DIR short [short ...]
7
- """
8
  import json
9
  import os
10
  import struct
 
 
 
 
 
 
 
 
1
  import json
2
  import os
3
  import struct
scripts/j2/fetch_weights_loadtest.sbatch CHANGED
@@ -7,7 +7,6 @@
7
  #SBATCH --mem=64G
8
  #SBATCH --time=03:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
- # J2 step 2b: root-level safetensors download (no token, no .py) and native weight-load gate on CPU.
11
  set -eu
12
  CODE=/path/to/TURKIC_OCR_CODE
13
  DATA=/path/to/TURKIC_OCR_DATA
 
7
  #SBATCH --mem=64G
8
  #SBATCH --time=03:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
 
10
  set -eu
11
  CODE=/path/to/TURKIC_OCR_CODE
12
  DATA=/path/to/TURKIC_OCR_DATA
scripts/j2/finalize.sbatch CHANGED
@@ -7,8 +7,6 @@
7
  #SBATCH --mem=16G
8
  #SBATCH --time=00:30:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
- # J2: gather everything that has finished (CPU only, no model): results.tsv, raw_samples.tsv, positive_control.tsv (cpu and gpu roots),
11
- # controls_2.tsv. Safe to run again at any time.
12
  set -u
13
  CODE=/path/to/TURKIC_OCR_CODE
14
  DATA=/path/to/TURKIC_OCR_DATA
 
7
  #SBATCH --mem=16G
8
  #SBATCH --time=00:30:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
 
 
10
  set -u
11
  CODE=/path/to/TURKIC_OCR_CODE
12
  DATA=/path/to/TURKIC_OCR_DATA
scripts/j2/harness_audit.py CHANGED
@@ -1,9 +1,3 @@
1
- """J2 harness audit: what exactly goes into each model for 5 KOHTD validation crops and 5 positive-control images.
2
- Processor only (no model weights), CPU. The input is built the same way as run_screen.py (build_inputs, batch of one).
3
- Text and numbers only; no image data is printed.
4
-
5
- usage: harness_audit.py MODELS_DIR PROMPTS_JSON SCREEN_SET KOHTD_IMG_DIR CONTROL_LIST CONTROL_IMG_DIR OUT_TXT short [short ...]
6
- """
7
  import copy
8
  import json
9
  import os
 
 
 
 
 
 
 
1
  import copy
2
  import json
3
  import os
scripts/j2/harness_audit.sbatch CHANGED
@@ -7,7 +7,6 @@
7
  #SBATCH --mem=24G
8
  #SBATCH --time=01:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
- # J2 harness audit (processor only, CPU, offline). Writes DATA/outputs/j11_positive_control/harness_audit.txt (text and numbers only).
11
  set -u
12
  CODE=/path/to/TURKIC_OCR_CODE
13
  DATA=/path/to/TURKIC_OCR_DATA
 
7
  #SBATCH --mem=24G
8
  #SBATCH --time=01:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
 
10
  set -u
11
  CODE=/path/to/TURKIC_OCR_CODE
12
  DATA=/path/to/TURKIC_OCR_DATA
scripts/j2/keyaudit.py CHANGED
@@ -1,10 +1,3 @@
1
- """J2: which checkpoint tensors does the native class not use, and which model tensors are not from the checkpoint?
2
-
3
- Exact match by (shape, sha1 of the bf16 bytes), so renamed keys still match. Checkpoint tensors with no matching model
4
- tensor were dropped by the loader (not instantiated or ignored on load); model tensors with no matching checkpoint
5
- tensor were created or changed by the loader (random init, fused, split or tied differently).
6
- usage: keyaudit.py MODELS_DIR OUT_DIR short [short ...]
7
- """
8
  import hashlib
9
  import json
10
  import os
 
 
 
 
 
 
 
 
1
  import hashlib
2
  import json
3
  import os
scripts/j2/keyaudit.sbatch CHANGED
@@ -7,7 +7,6 @@
7
  #SBATCH --mem=64G
8
  #SBATCH --time=01:30:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
- # J2: checkpoint-versus-model tensor audit (CPU, offline).
11
  set -eu
12
  CODE=/path/to/TURKIC_OCR_CODE
13
  DATA=/path/to/TURKIC_OCR_DATA
 
7
  #SBATCH --mem=64G
8
  #SBATCH --time=01:30:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
 
10
  set -eu
11
  CODE=/path/to/TURKIC_OCR_CODE
12
  DATA=/path/to/TURKIC_OCR_DATA
scripts/j2/make_control_set.py CHANGED
@@ -1,14 +1,3 @@
1
- """J2 positive control: 200 printed words (100 Kazakh + 100 Kyrgyz, Cyrillic) rendered in PT Sans (OFL 1.1), black on white, at
2
- heights 40 px and 80 px = 400 images. Words come from the DISPLAY sentence banks that pagesynth uses.
3
- (There is no Russian bank in pagesynth_text; the plan allows Kazakh + Kyrgyz then.)
4
-
5
- Word choice: whitespace tokens of the display sentences with punctuation stripped from both ends; keep tokens that are
6
- all letters, 3 to 12 characters, every letter in the Cyrillic block, every glyph in the font; ascending sha256 of
7
- "J2-control-v1:<lang>:<word>"; first 100 per language. Writes the list in the screen-set format
8
- (positive_control_screen_set_v1.tsv: crop_file, form_id, label) and the images.
9
-
10
- usage: make_control_set.py BANK_KK BANK_KY FONT_TTF OUT_DIR
11
- """
12
  import hashlib
13
  import os
14
  import sys
 
 
 
 
 
 
 
 
 
 
 
 
1
  import hashlib
2
  import os
3
  import sys
scripts/j2/make_control_set.sbatch CHANGED
@@ -7,7 +7,6 @@
7
  #SBATCH --mem=16G
8
  #SBATCH --time=00:30:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
- # J2 positive control: render 400 printed word images (CPU).
11
  set -eu
12
  CODE=/path/to/TURKIC_OCR_CODE
13
  DATA=/path/to/TURKIC_OCR_DATA
 
7
  #SBATCH --mem=16G
8
  #SBATCH --time=00:30:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
 
10
  set -eu
11
  CODE=/path/to/TURKIC_OCR_CODE
12
  DATA=/path/to/TURKIC_OCR_DATA
scripts/j2/make_controls2_set.py CHANGED
@@ -1,14 +1,3 @@
1
- """J2 second follow-up controls: build the image sets.
2
-
3
- A. Contrast: the first 300 crops of screen_set_v1.tsv (file order). List "stored" = the crops as stored (names unchanged, images are
4
- read from the KOHTD folder). List "stretch" = the same crops after contrast_stretch (own PNG copies; PNG so no new JPEG loss).
5
- The KOHTD images stay on the cluster.
6
- B. Handwriting fonts, no real ink: the same 200 Kazakh and Kyrgyz control words (the 40 px rows of control_words.tsv) rendered at
7
- height 40 px in Caveat and Bad Script (OFL), black on white. A word with a letter the font lacks is left out for that font
8
- and listed.
9
-
10
- usage: make_controls2_set.py SCREEN_SET KOHTD_IMG_DIR CONTROL_WORDS_TSV CONTRAST_STRETCH_PY FONT_CAVEAT FONT_BADSCRIPT OUT_DIR
11
- """
12
  import importlib.util
13
  import os
14
  import sys
 
 
 
 
 
 
 
 
 
 
 
 
1
  import importlib.util
2
  import os
3
  import sys
scripts/j2/make_controls2_set.sbatch CHANGED
@@ -7,7 +7,6 @@
7
  #SBATCH --mem=16G
8
  #SBATCH --time=00:30:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
- # J2 controls 2: contrast-stretched copies of the first 300 screen crops, and the 200 control words in two OFL handwriting fonts (CPU).
11
  set -eu
12
  CODE=/path/to/TURKIC_OCR_CODE
13
  DATA=/path/to/TURKIC_OCR_DATA
 
7
  #SBATCH --mem=16G
8
  #SBATCH --time=00:30:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
 
10
  set -eu
11
  CODE=/path/to/TURKIC_OCR_CODE
12
  DATA=/path/to/TURKIC_OCR_DATA
scripts/j2/raw_samples.py CHANGED
@@ -1,8 +1,3 @@
1
- """20 raw outputs per model and enlargement next to their references (for manual inspection only, never for a page).
2
- Same 20 crops for every model and scale: ascending sha256 of "J2-raw-sample-v1:" + crop_file over the screen set.
3
- Only crops that are already done are listed (a partial run shows fewer than 20 rows; the column crops_of_sample_done says so).
4
- usage: raw_samples.py OUT_ROOT SCREEN_SET_TSV SCORELIB_PY OUT_TSV
5
- """
6
  import hashlib
7
  import importlib.util
8
  import json
 
 
 
 
 
 
1
  import hashlib
2
  import importlib.util
3
  import json
scripts/j2/run_gpu_job.sbatch CHANGED
@@ -7,10 +7,6 @@
7
  #SBATCH --mem=96G
8
  #SBATCH --time=02:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
- # J2 step 6: zero-shot screen of 2-4 models on the KOHTD validation word crops, one model after another, offline.
11
- # Order: enlargement 1x for every model of the job first, then 2x, then 3x, so that a timeout still leaves 1x for all.
12
- # Every model writes JSONL after each batch and resumes from it: a job that ran out of time is simply submitted again.
13
- # usage: sbatch --job-name=j2_gpuA run_gpu_job.sbatch short [short ...]
14
  set -u
15
  CODE=/path/to/TURKIC_OCR_CODE
16
  DATA=/path/to/TURKIC_OCR_DATA
 
7
  #SBATCH --mem=96G
8
  #SBATCH --time=02:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
 
 
 
 
10
  set -u
11
  CODE=/path/to/TURKIC_OCR_CODE
12
  DATA=/path/to/TURKIC_OCR_DATA
scripts/j2/run_screen.py CHANGED
@@ -1,13 +1,3 @@
1
- """J2 screen: zero-shot reading of KOHTD validation word crops with one stock-transformers model.
2
-
3
- Native transformers classes only (trust_remote_code is never set), safetensors only, greedy, bf16, sdpa.
4
- This script never reads labels and never opens train.tsv or test.tsv: it reads crop_file from screen_set_v1.tsv only.
5
- Writes after every batch and resumes from preds.jsonl.
6
-
7
- usage: run_screen.py SHORT MODELS_DIR PROMPTS_JSON SCREEN_SET_TSV IMG_DIR OUT_ROOT
8
- [--batch-size 16] [--max-new-tokens 48] [--scales 1,2,3] [--limit N] [--device cuda|cpu]
9
- [--threads N] [--check-batch-equal]
10
- """
11
  import argparse
12
  import copy
13
  import json
 
 
 
 
 
 
 
 
 
 
 
1
  import argparse
2
  import copy
3
  import json
scripts/j2/setup_env_vlm.sbatch CHANGED
@@ -7,7 +7,6 @@
7
  #SBATCH --mem=16G
8
  #SBATCH --time=01:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
- # J2 step 1: new uv environment .venv_vlm (torch CUDA 12.8 build for H100, newest stable transformers, no vendor OCR packages).
11
  set -eu
12
  UV=$HOME/.local/bin/uv
13
  VENV=/path/to/TURKIC_OCR_CODE/.venv_vlm
 
7
  #SBATCH --mem=16G
8
  #SBATCH --time=01:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
 
10
  set -eu
11
  UV=$HOME/.local/bin/uv
12
  VENV=/path/to/TURKIC_OCR_CODE/.venv_vlm
scripts/j2/smoke_cpu.sbatch CHANGED
@@ -7,8 +7,6 @@
7
  #SBATCH --mem=64G
8
  #SBATCH --time=03:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
- # J2 step 6: smoke test, 5 crops per model on ZEN4 CPU, offline. Output goes to a separate folder (not the production one).
11
- # usage: sbatch smoke_cpu.sbatch short [short ...]
12
  set -u
13
  CODE=/path/to/TURKIC_OCR_CODE
14
  DATA=/path/to/TURKIC_OCR_DATA
 
7
  #SBATCH --mem=64G
8
  #SBATCH --time=03:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
 
 
10
  set -u
11
  CODE=/path/to/TURKIC_OCR_CODE
12
  DATA=/path/to/TURKIC_OCR_DATA
scripts/j2/smoke_gpu.sbatch CHANGED
@@ -7,8 +7,6 @@
7
  #SBATCH --mem=96G
8
  #SBATCH --time=00:30:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
- # J2 step 6, GPU part: 16 crops per model at 1x and 2x on one H100 (checks the CUDA code path, memory counter and speed
11
- # bookkeeping), offline, separate output folder. usage: sbatch smoke_gpu.sbatch short [short ...]
12
  set -u
13
  CODE=/path/to/TURKIC_OCR_CODE
14
  DATA=/path/to/TURKIC_OCR_DATA
 
7
  #SBATCH --mem=96G
8
  #SBATCH --time=00:30:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
 
 
10
  set -u
11
  CODE=/path/to/TURKIC_OCR_CODE
12
  DATA=/path/to/TURKIC_OCR_DATA
scripts/j2/test_collect.py CHANGED
@@ -1,5 +1,3 @@
1
- """Test collect.py on synthetic outputs with a half-written last line and no meta.json.
2
- usage: test_collect.py SCRIPTS_DIR WORK_DIR"""
3
  import json
4
  import os
5
  import subprocess
 
 
 
1
  import json
2
  import os
3
  import subprocess
scripts/j2/test_contrast_stretch.py CHANGED
@@ -1,4 +1,3 @@
1
- """Unit test of contrast_stretch. usage: test_contrast_stretch.py PATH_TO_contrast_stretch.py"""
2
  import importlib.util
3
  import sys
4
 
 
 
1
  import importlib.util
2
  import sys
3
 
scripts/j2/test_controls2_report.py CHANGED
@@ -1,4 +1,3 @@
1
- """Synthetic test of controls2_report.py. usage: test_controls2_report.py SCRIPTS_DIR WORK_DIR"""
2
  import json
3
  import os
4
  import subprocess
 
 
1
  import json
2
  import os
3
  import subprocess
scripts/kohtd_leak_scan.py CHANGED
@@ -200,7 +200,7 @@ def main():
200
  res["membership_rebuilt_from_file_names"] = counts
201
  print("counts", counts, flush=True)
202
 
203
- # ---- features for all crops (cached) ----
204
  cache = os.path.join(OUT, "features.npz")
205
  if os.path.exists(cache):
206
  z = np.load(cache, allow_pickle=True)
@@ -226,7 +226,7 @@ def main():
226
  res["near_blank_dropped_std_le_5"] = {g: int(((grp == c) & ~BAD & (STD <= STD_MIN)).sum()) for g, c in (("scan", G_S), ("train_numbered", G_N), ("validation", G_V), ("test", G_T))}
227
  AR = (W / np.maximum(H, 1)).astype(np.float32)
228
 
229
- # ---- exact duplicates ----
230
  def dup_report(key, label):
231
  by = collections.defaultdict(list)
232
  for i in range(len(NAMES)):
@@ -249,7 +249,7 @@ def main():
249
  res["exact_duplicates_decoded_pixels"] = dup_report(pix, "sha256 of the decoded grayscale pixels")
250
  print("exact dup", res["exact_duplicates_file_sha256"], res["exact_duplicates_decoded_pixels"], flush=True)
251
 
252
- # ---- sets ----
253
  iS = np.where((grp == G_S) & valid)[0]
254
  iN = np.where((grp == G_N) & valid)[0]
255
  iV = np.where((grp == G_V) & valid)[0]
@@ -259,7 +259,7 @@ def main():
259
  Ddh, Dph, Dar = DH[DBi], PH[DBi], AR[DBi]
260
  res["valid_crops_used"] = {"scan": len(iS), "train_numbered": len(iN), "validation": len(iV), "test": len(iT)}
261
 
262
- # ---- positive controls ----
263
  rng = random.Random(SEED)
264
  ctrl_src = rng.sample(list(iN), 600)
265
  pos_in_db = {int(d): k for k, d in enumerate(DBi)}
@@ -311,9 +311,9 @@ def main():
311
  "tau_easy_p95_of_true_pairs": round(tau_easy, 4), "tau_hard_p95_of_true_pairs": round(tau_hard, 4)}
312
  print("controls", json.dumps(ctrl)[:1500], flush=True)
313
 
314
- # ---- real query: scan-named crops against V, T, N ----
315
  bdS, biS, _ = nn(DH[iS], PH[iS], AR[iS], Ddh, Dph, Dar, segs)
316
- # ---- null query: a random sample of numbered TRAIN crops, same size, against V and T only (form-disjoint by construction) ----
317
  nrng = np.random.RandomState(SEED)
318
  sampN = nrng.choice(iN, len(iS), replace=False)
319
  VT = (0, len(iV) + len(iT))
@@ -332,7 +332,7 @@ def main():
332
  res["nearest_distance_quantiles"] = {"scan_to_val_or_test": qs(realVT), "NULL_trainnumbered_to_val_or_test": qs(nullVT), "scan_to_train_numbered": qs(bdS[:, 2]), "scan_to_all_numbered": qs(bdS.min(1))}
333
  res["nearest_distance_note"] = "NULL = 24,989 random numbered TRAIN crops matched against validation+test crops; train forms differ from val/test forms by construction (checked by the hash rule), so every NULL neighbour is a different page."
334
 
335
- # ---- NCC second check on the closest pairs ----
336
  from multiprocessing import Pool
337
  best_seg = np.where(bdS[:, 0] <= bdS[:, 1], 0, 1)
338
  real_idx = np.where(best_seg == 0, biS[:, 0], biS[:, 1]) # DB index
@@ -359,7 +359,7 @@ def main():
359
  res["confirmed_near_duplicates"] = {"rule": "hash distance <= tau_hard AND NCC >= threshold_ncc", "crops": int(conf_mask.sum()), "NULL_expected_false_positives_same_rule": int(conf_null.sum()),
360
  "in_validation": int((best_seg[conf_q] == 0).sum()), "in_test": int((best_seg[conf_q] == 1).sum())}
361
 
362
- # ---- vote per scan name ----
363
  snames = np.array([re.match(scan, NAMES[i]).group(1) for i in iS])
364
  allbest = bdS.argmin(1)
365
  best_dist = bdS.min(1)
@@ -422,7 +422,7 @@ def main():
422
  res["vote_per_scan_name"]["linked_names_vote3_and_ncc_ge_threshold"] = {"count": len(ln), "details": [{"scan_name": k, "form": fid, "split": ["train", "validation", "test"][split_of_form(fid) - 1], "crops_voting_and_confirmed": c} for k, fid, c in ln[:20]],
423
  "crops_of_linked_names": int(sum(len(by_name[k]) for k, _, _ in ln))}
424
 
425
- # ---- examples: five closest scan-to-val/test pairs by NCC among the K closest by hash ----
426
  order_ex = np.argsort(-nccR)[:5]
427
  ex = []
428
  from PIL import Image, ImageDraw, ImageFont
@@ -459,7 +459,7 @@ def main():
459
  panel.save(os.path.join(OUT, "examples_panel.png"))
460
  res["examples_five_closest_scan_to_val_or_test"] = ex
461
 
462
- # ---- step 4: name structure and image traits ----
463
  snm = re.compile(r"^Скан_(\d{8})(?:_(\d+))?(?: \((\d+)\))?$")
464
  names_all = sorted(set(sname[i] for i in range(len(NAMES)) if grp[i] == G_S))
465
  per_date = collections.defaultdict(lambda: {"names": 0, "crops": 0, "n_values": set(), "heights": []})
 
200
  res["membership_rebuilt_from_file_names"] = counts
201
  print("counts", counts, flush=True)
202
 
203
+ # features for all crops (cached)
204
  cache = os.path.join(OUT, "features.npz")
205
  if os.path.exists(cache):
206
  z = np.load(cache, allow_pickle=True)
 
226
  res["near_blank_dropped_std_le_5"] = {g: int(((grp == c) & ~BAD & (STD <= STD_MIN)).sum()) for g, c in (("scan", G_S), ("train_numbered", G_N), ("validation", G_V), ("test", G_T))}
227
  AR = (W / np.maximum(H, 1)).astype(np.float32)
228
 
229
+ # exact duplicates
230
  def dup_report(key, label):
231
  by = collections.defaultdict(list)
232
  for i in range(len(NAMES)):
 
249
  res["exact_duplicates_decoded_pixels"] = dup_report(pix, "sha256 of the decoded grayscale pixels")
250
  print("exact dup", res["exact_duplicates_file_sha256"], res["exact_duplicates_decoded_pixels"], flush=True)
251
 
252
+ # sets
253
  iS = np.where((grp == G_S) & valid)[0]
254
  iN = np.where((grp == G_N) & valid)[0]
255
  iV = np.where((grp == G_V) & valid)[0]
 
259
  Ddh, Dph, Dar = DH[DBi], PH[DBi], AR[DBi]
260
  res["valid_crops_used"] = {"scan": len(iS), "train_numbered": len(iN), "validation": len(iV), "test": len(iT)}
261
 
262
+ # positive controls
263
  rng = random.Random(SEED)
264
  ctrl_src = rng.sample(list(iN), 600)
265
  pos_in_db = {int(d): k for k, d in enumerate(DBi)}
 
311
  "tau_easy_p95_of_true_pairs": round(tau_easy, 4), "tau_hard_p95_of_true_pairs": round(tau_hard, 4)}
312
  print("controls", json.dumps(ctrl)[:1500], flush=True)
313
 
314
+ # real query: scan-named crops against V, T, N
315
  bdS, biS, _ = nn(DH[iS], PH[iS], AR[iS], Ddh, Dph, Dar, segs)
316
+ # null query: a random sample of numbered TRAIN crops, same size, against V and T only (form-disjoint by construction)
317
  nrng = np.random.RandomState(SEED)
318
  sampN = nrng.choice(iN, len(iS), replace=False)
319
  VT = (0, len(iV) + len(iT))
 
332
  res["nearest_distance_quantiles"] = {"scan_to_val_or_test": qs(realVT), "NULL_trainnumbered_to_val_or_test": qs(nullVT), "scan_to_train_numbered": qs(bdS[:, 2]), "scan_to_all_numbered": qs(bdS.min(1))}
333
  res["nearest_distance_note"] = "NULL = 24,989 random numbered TRAIN crops matched against validation+test crops; train forms differ from val/test forms by construction (checked by the hash rule), so every NULL neighbour is a different page."
334
 
335
+ # NCC second check on the closest pairs
336
  from multiprocessing import Pool
337
  best_seg = np.where(bdS[:, 0] <= bdS[:, 1], 0, 1)
338
  real_idx = np.where(best_seg == 0, biS[:, 0], biS[:, 1]) # DB index
 
359
  res["confirmed_near_duplicates"] = {"rule": "hash distance <= tau_hard AND NCC >= threshold_ncc", "crops": int(conf_mask.sum()), "NULL_expected_false_positives_same_rule": int(conf_null.sum()),
360
  "in_validation": int((best_seg[conf_q] == 0).sum()), "in_test": int((best_seg[conf_q] == 1).sum())}
361
 
362
+ # vote per scan name
363
  snames = np.array([re.match(scan, NAMES[i]).group(1) for i in iS])
364
  allbest = bdS.argmin(1)
365
  best_dist = bdS.min(1)
 
422
  res["vote_per_scan_name"]["linked_names_vote3_and_ncc_ge_threshold"] = {"count": len(ln), "details": [{"scan_name": k, "form": fid, "split": ["train", "validation", "test"][split_of_form(fid) - 1], "crops_voting_and_confirmed": c} for k, fid, c in ln[:20]],
423
  "crops_of_linked_names": int(sum(len(by_name[k]) for k, _, _ in ln))}
424
 
425
+ # examples: five closest scan-to-val/test pairs by NCC among the K closest by hash
426
  order_ex = np.argsort(-nccR)[:5]
427
  ex = []
428
  from PIL import Image, ImageDraw, ImageFont
 
459
  panel.save(os.path.join(OUT, "examples_panel.png"))
460
  res["examples_five_closest_scan_to_val_or_test"] = ex
461
 
462
+ # step 4: name structure and image traits
463
  snm = re.compile(r"^Скан_(\d{8})(?:_(\d+))?(?: \((\d+)\))?$")
464
  names_all = sorted(set(sname[i] for i in range(len(NAMES)) if grp[i] == G_S))
465
  per_date = collections.defaultdict(lambda: {"names": 0, "crops": 0, "n_values": set(), "heights": []})
scripts/kohtd_leak_scan.sbatch CHANGED
@@ -7,7 +7,6 @@
7
  #SBATCH --mem=48G
8
  #SBATCH --time=01:30:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
- # Leakage check on KOHTD: scan-named training crops versus validation/test crops, images only (no label file is read).
11
  C=/path/to/TURKIC_OCR_CODE
12
  D=/path/to/TURKIC_OCR_DATA
13
  echo "== start $(date) job $SLURM_JOB_ID"
 
7
  #SBATCH --mem=48G
8
  #SBATCH --time=01:30:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
 
10
  C=/path/to/TURKIC_OCR_CODE
11
  D=/path/to/TURKIC_OCR_DATA
12
  echo "== start $(date) job $SLURM_JOB_ID"
scripts/r5/r5_after_gen.sbatch CHANGED
@@ -7,9 +7,6 @@
7
  #SBATCH --mem=24G
8
  #SBATCH --time=02:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
- # R5 DATA: run this ONCE GEN's synthetic manifests (synth_{hand,typed,clutter,pages}_{train,val,test}.tsv) are written and no longer change.
11
- # 1 hash GEN's images, 2 report-only duplicate check over all manifests (rewrites nothing), 3 validate every manifest, 4 recut the unseen-word slice P2 with the
12
- # synthetic train labels, 5 rewrite manifest_stats.json, evalsets.json and mix_v1_shares.json (placeholders become ready sets).
13
  PY=/path/to/TURKIC_OCR_CODE/.venv/bin/python
14
  S=/path/to/TURKIC_OCR_CODE/scripts/r5
15
  $PY -I $S/r5_build_real.py hash_synth dedupe_all --force
 
7
  #SBATCH --mem=24G
8
  #SBATCH --time=02:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
 
 
 
10
  PY=/path/to/TURKIC_OCR_CODE/.venv/bin/python
11
  S=/path/to/TURKIC_OCR_CODE/scripts/r5
12
  $PY -I $S/r5_build_real.py hash_synth dedupe_all --force
scripts/r5/r5_build_A.sbatch CHANGED
@@ -7,7 +7,6 @@
7
  #SBATCH --mem=16G
8
  #SBATCH --time=02:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
- # R5 DATA: real-data manifests, part A (see r5_build_real.py)
11
  PY=/path/to/TURKIC_OCR_CODE/.venv/bin/python
12
  S=/path/to/TURKIC_OCR_CODE/scripts/r5/r5_build_real.py
13
  $PY -I $S kohtd --force
 
7
  #SBATCH --mem=16G
8
  #SBATCH --time=02:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
 
10
  PY=/path/to/TURKIC_OCR_CODE/.venv/bin/python
11
  S=/path/to/TURKIC_OCR_CODE/scripts/r5/r5_build_real.py
12
  $PY -I $S kohtd --force
scripts/r5/r5_build_B.sbatch CHANGED
@@ -7,7 +7,6 @@
7
  #SBATCH --mem=32G
8
  #SBATCH --time=03:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
- # R5 DATA: real-data manifests, part B (see r5_build_real.py)
11
  PY=/path/to/TURKIC_OCR_CODE/.venv/bin/python
12
  S=/path/to/TURKIC_OCR_CODE/scripts/r5/r5_build_real.py
13
  $PY -I $S school
 
7
  #SBATCH --mem=32G
8
  #SBATCH --time=03:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
 
10
  PY=/path/to/TURKIC_OCR_CODE/.venv/bin/python
11
  S=/path/to/TURKIC_OCR_CODE/scripts/r5/r5_build_real.py
12
  $PY -I $S school
scripts/r5/r5_build_C.sbatch CHANGED
@@ -7,7 +7,6 @@
7
  #SBATCH --mem=32G
8
  #SBATCH --time=02:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
- # R5 DATA: real-data manifests, part C (see r5_build_real.py)
11
  PY=/path/to/TURKIC_OCR_CODE/.venv/bin/python
12
  S=/path/to/TURKIC_OCR_CODE/scripts/r5/r5_build_real.py
13
  $PY -I $S hash dedupe
 
7
  #SBATCH --mem=32G
8
  #SBATCH --time=02:00:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
 
10
  PY=/path/to/TURKIC_OCR_CODE/.venv/bin/python
11
  S=/path/to/TURKIC_OCR_CODE/scripts/r5/r5_build_real.py
12
  $PY -I $S hash dedupe
scripts/r5/r5_build_real.py CHANGED
@@ -1,17 +1,3 @@
1
- """R5 DATA: build the real-data manifests of round R5 (shared TSV format of the R5 common specification).
2
-
3
- Stages (run in this order; each stage writes its outputs and a stage log, and is skipped if its log exists, unless --force):
4
- kohtd K1 split -> kohtd_{train,val,test}, kohtd_screen_v1 (V1, unchanged), kohtd_lmtune (500 validation crops not in V1, seed 20261121)
5
- hkr HKR words (Kaggle mirror zip): extract jpg, official split (train / val / test1 / test2) from the project's HKR audit manifest
6
- chd Cyrillic Handwriting Dataset (CHD): extract png; official train / test; validation carved from train by word type
7
- school school_notebooks_ru: word crops from pupil_text polygons, page split kept
8
- rukopys RUKOPYS test: handwritten, legible, Ukrainian line crops from the boxes (test only)
9
- hash sha256 + perceptual hash (64-bit pHash) of every image in every manifest
10
- dedupe drop train images that are byte-identical or near-identical (pHash distance <= 4) to a val or test image of any source
11
-
12
- Raw manifests (before dedupe) go to DATA/data/processed/r5/manifests_pre_dedupe/, final ones to .../r5/manifests/.
13
- Nothing here trains or scores a model. Test images are read only to cut line crops (rukopys, school) and to hash them for the duplicate check; none is shown or scored.
14
- """
15
  import argparse
16
  import collections
17
  import csv
@@ -102,7 +88,7 @@ def row(id_, image, text, lang, script, kind, source, split, group, unit):
102
  source=source, split=split, group=group, unit=unit)
103
 
104
 
105
- # ----------------------------------------------------------------------------- KOHTD
106
  def read_k1(path):
107
  out = []
108
  with open(path, encoding="utf-8", newline="") as f:
@@ -198,7 +184,7 @@ def stage_kohtd():
198
  print(json.dumps(info, ensure_ascii=False)[:2000])
199
 
200
 
201
- # ----------------------------------------------------------------------------- HKR
202
  HKR_PREFIX = "HKR_Dataset_Words_Public/20200923_Dataset_Words_Public/"
203
 
204
 
@@ -256,7 +242,7 @@ def stage_hkr():
256
  print(json.dumps(info, ensure_ascii=False)[:2000])
257
 
258
 
259
- # ----------------------------------------------------------------------------- CHD
260
  def stage_chd():
261
  info = {"stage": "chd"}
262
  z = zipfile.ZipFile(RAW / "chd/archive.zip")
@@ -310,7 +296,7 @@ def stage_chd():
310
  print(json.dumps(info, ensure_ascii=False)[:2000])
311
 
312
 
313
- # ----------------------------------------------------------------------------- school notebooks
314
  def poly_pts(seg):
315
  flat = seg[0] if seg and isinstance(seg[0], list) else seg
316
  pts = np.array(flat, dtype=np.float32).reshape(-1, 2)
@@ -447,7 +433,7 @@ def stage_school():
447
  print(json.dumps(info, ensure_ascii=False, default=str)[:2000])
448
 
449
 
450
- # ----------------------------------------------------------------------------- RUKOPYS test
451
  def stage_rukopys():
452
  info = {"stage": "rukopys"}
453
  base = RAW / "rukopys_test/test"
@@ -493,7 +479,7 @@ def stage_rukopys():
493
  print(json.dumps(info, ensure_ascii=False)[:2000])
494
 
495
 
496
- # ----------------------------------------------------------------------------- hashing
497
  def phash64(gray):
498
  small = cv2.resize(gray, (32, 32), interpolation=cv2.INTER_AREA).astype(np.float32)
499
  dct = cv2.dct(small)
@@ -545,7 +531,7 @@ def stage_hash():
545
  print(info)
546
 
547
 
548
- # ----------------------------------------------------------------------------- dedupe
549
  def stage_dedupe():
550
  info = {"stage": "dedupe"}
551
  hashes = {}
@@ -708,7 +694,7 @@ def stage_dedupe():
708
 
709
 
710
 
711
- # ----------------------------------------------------------------------------- synthetic manifests of GEN: hash and report-only duplicate check
712
  def synth_manifest_names():
713
  return sorted(q.stem for pat in ("synth_*.tsv", "az_localdoc_*.tsv") for q in MAN.glob(pat) if q.stem.rsplit("_", 1)[-1] in ("train", "val", "test"))
714
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import argparse
2
  import collections
3
  import csv
 
88
  source=source, split=split, group=group, unit=unit)
89
 
90
 
91
+ # KOHTD
92
  def read_k1(path):
93
  out = []
94
  with open(path, encoding="utf-8", newline="") as f:
 
184
  print(json.dumps(info, ensure_ascii=False)[:2000])
185
 
186
 
187
+ # HKR
188
  HKR_PREFIX = "HKR_Dataset_Words_Public/20200923_Dataset_Words_Public/"
189
 
190
 
 
242
  print(json.dumps(info, ensure_ascii=False)[:2000])
243
 
244
 
245
+ # CHD
246
  def stage_chd():
247
  info = {"stage": "chd"}
248
  z = zipfile.ZipFile(RAW / "chd/archive.zip")
 
296
  print(json.dumps(info, ensure_ascii=False)[:2000])
297
 
298
 
299
+ # school notebooks
300
  def poly_pts(seg):
301
  flat = seg[0] if seg and isinstance(seg[0], list) else seg
302
  pts = np.array(flat, dtype=np.float32).reshape(-1, 2)
 
433
  print(json.dumps(info, ensure_ascii=False, default=str)[:2000])
434
 
435
 
436
+ # RUKOPYS test
437
  def stage_rukopys():
438
  info = {"stage": "rukopys"}
439
  base = RAW / "rukopys_test/test"
 
479
  print(json.dumps(info, ensure_ascii=False)[:2000])
480
 
481
 
482
+ # hashing
483
  def phash64(gray):
484
  small = cv2.resize(gray, (32, 32), interpolation=cv2.INTER_AREA).astype(np.float32)
485
  dct = cv2.dct(small)
 
531
  print(info)
532
 
533
 
534
+ # dedupe
535
  def stage_dedupe():
536
  info = {"stage": "dedupe"}
537
  hashes = {}
 
694
 
695
 
696
 
697
+ # synthetic manifests: hash and report-only duplicate check
698
  def synth_manifest_names():
699
  return sorted(q.stem for pat in ("synth_*.tsv", "az_localdoc_*.tsv") for q in MAN.glob(pat) if q.stem.rsplit("_", 1)[-1] in ("train", "val", "test"))
700
 
scripts/r5/r5_disk_counts.py CHANGED
@@ -1,7 +1,3 @@
1
- """R5 DATA: count what is on disk for every data source held on the cluster.
2
- Writes DATA/outputs/r5/disk_counts.json: for each source the counts and the exact files or folders that were counted.
3
- Read-only. Usage: python -I r5_disk_counts.py
4
- """
5
  import collections
6
  import json
7
  import os
 
 
 
 
 
1
  import collections
2
  import json
3
  import os
scripts/r5/r5_fetch_az_htr.py CHANGED
@@ -1,8 +1,3 @@
1
- """R5 DATA (extra, beyond the plan): fetch the open Azerbaijani handwriting benchmark LocalDoc/azerbaijani-htr-benchmark
2
- (CC BY 4.0, 442 human-annotated line crops from 29 pages, test-sized) and write a test-only manifest.
3
- Plain public downloads, no login, no token, no special headers. The files are untrusted data: parquet is read with pyarrow only, nothing is executed.
4
- Run on a ZEN4 node: python -I r5_fetch_az_htr.py fetch | manifest
5
- """
6
  import hashlib
7
  import io
8
  import json
 
 
 
 
 
 
1
  import hashlib
2
  import io
3
  import json
scripts/r5/r5_finalize.sbatch CHANGED
@@ -7,7 +7,6 @@
7
  #SBATCH --mem=8G
8
  #SBATCH --time=00:40:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
10
- # R5 DATA: after the duplicate check: validate the manifests, cut the P2 slice, write manifest statistics, the registry and the effective mix shares.
11
  PY=/path/to/TURKIC_OCR_CODE/.venv/bin/python
12
  S=/path/to/TURKIC_OCR_CODE/scripts/r5
13
  $PY -I $S/r5_validate_manifests.py
 
7
  #SBATCH --mem=8G
8
  #SBATCH --time=00:40:00
9
  #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
 
10
  PY=/path/to/TURKIC_OCR_CODE/.venv/bin/python
11
  S=/path/to/TURKIC_OCR_CODE/scripts/r5
12
  $PY -I $S/r5_validate_manifests.py
scripts/r5/r5_kohtd_check.py CHANGED
@@ -1,4 +1,3 @@
1
- """R5 DATA: what does cleaning change in KOHTD labels, and what is the form_id of scan-named crops."""
2
  import collections
3
  import unicodedata
4
  from pathlib import Path
 
 
1
  import collections
2
  import unicodedata
3
  from pathlib import Path