Clean up comments and file headers; point to the model repositories
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- NOTICE+1-2
- README.md+21-4
- scripts/b1_page_check/b1_page_check.py-8
- scripts/b1_page_check/b1_page_check.sbatch-1
- scripts/b1_page_check/b1_page_score.py-8
- scripts/b1_page_check/base_page_check.sbatch-2
- scripts/b1_page_check/detb1_page_check.py-9
- scripts/b1_page_check/detb1_page_check.sbatch-1
- scripts/j2/build_screen_set.py-4
- scripts/j2/check_images_kwargs.py-2
- scripts/j2/collect.py-9
- scripts/j2/contrast_stretch.py-6
- scripts/j2/control_report.py-4
- scripts/j2/control_run_cpu.sbatch-2
- scripts/j2/control_run_gpu.sbatch-2
- scripts/j2/controls2_report.py-6
- scripts/j2/controls2_run_cpu.sbatch-2
- scripts/j2/eligibility.py-11
- scripts/j2/eligibility.sbatch-1
- scripts/j2/fetch_weights_loadtest.py-7
- scripts/j2/fetch_weights_loadtest.sbatch-1
- scripts/j2/finalize.sbatch-2
- scripts/j2/harness_audit.py-6
- scripts/j2/harness_audit.sbatch-1
- scripts/j2/keyaudit.py-7
- scripts/j2/keyaudit.sbatch-1
- scripts/j2/make_control_set.py-11
- scripts/j2/make_control_set.sbatch-1
- scripts/j2/make_controls2_set.py-11
- scripts/j2/make_controls2_set.sbatch-1
- scripts/j2/raw_samples.py-5
- scripts/j2/run_gpu_job.sbatch-4
- scripts/j2/run_screen.py-10
- scripts/j2/setup_env_vlm.sbatch-1
- scripts/j2/smoke_cpu.sbatch-2
- scripts/j2/smoke_gpu.sbatch-2
- scripts/j2/test_collect.py-2
- scripts/j2/test_contrast_stretch.py-1
- scripts/j2/test_controls2_report.py-1
- scripts/kohtd_leak_scan.py+10-10
- scripts/kohtd_leak_scan.sbatch-1
- scripts/r5/r5_after_gen.sbatch-3
- scripts/r5/r5_build_A.sbatch-1
- scripts/r5/r5_build_B.sbatch-1
- scripts/r5/r5_build_C.sbatch-1
- scripts/r5/r5_build_real.py+8-22
- scripts/r5/r5_disk_counts.py-4
- scripts/r5/r5_fetch_az_htr.py-5
- scripts/r5/r5_finalize.sbatch-1
- scripts/r5/r5_kohtd_check.py-1
55 unmodified lines565758596055 unmodified linesNOT INCLUDEDNo data, no font files and no weights of the fine-tuned readers (PaddleOCR-VL-1.6, Qwen3-VL-2B, PP-OCRv6-medium and itscharacter language model). See README.55 unmodified lines5657585955 unmodified linesNOT INCLUDEDNo data and no font files. The weights of the fine-tuned readers are in their own gated repositories (see README).
90 unmodified lines91929394959676 unmodified lines17317417517617717817918018114 unmodified lines19619719819920020120290 unmodified linesThe Slurm headers name the partitions of the original cluster. Many scripts read manifests and write records of theoriginal run; those files are not part of this package.## DataNo dataset is stored here. The generated data are on the Hugging Face Hub, in four configurations (`hand`, `typed`,76 unmodified linesTraining. The training entry points are `scripts/r5_vlma/train_vlm.py` (full fine-tuning of the vision-languagereaders), `scripts/r5_vlmb/vlmb_train.py` (readers that need their maker's code), `src/linedet/train_arm.py` (CTC linerecognizers), `src/linedet/det_yolo.py` (detector) and `scripts/r5_rq2/rq2_train.py` (augmentation study). The fullruns need H100 GPUs on a Slurm cluster and the licensed real data, KOHTD and HKR above all. The reader weights trained inthe project are not released: the terms of KOHTD and HKR limit their use to the applicant's group and to academicresearch. The detector was trained on School Notebooks photos and generated pages, and its weights are released.## Seeds14 unmodified lines## Not included- Data of any kind: real datasets, generated data, manifests, splits, predictions.- Weights of the fine-tuned readers (PaddleOCR-VL-1.6, Qwen3-VL-2B, PP-OCRv6-medium and its character language model).- Font files.- The scripts of the continued training on real Latin-script handwriting, of the IAM scoring and of the later,more realistic generator version.90 unmodified lines91929394959697989910010110210310410510610710810911011111211311411576 unmodified lines19219319419519619719814 unmodified lines21321421521621721821990 unmodified linesThe Slurm headers name the partitions of the original cluster. Many scripts read manifests and write records of theoriginal run; those files are not part of this package.## ModelsThe trained readers are gated repositories on the Hugging Face Hub: access follows a request in which you agree to use the weights fornon-commercial research only (they were trained on data with such terms). Each repository has `infer.py`, `requirements.txt`, a model cardand the weights in `model/`.| Repository | Content ||---|---|| `treoa/turkic-ocr-paddleocr-vl-1.6` | the shipped PaddleOCR-VL-1.6 (the headline results of the report) || `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 || `treoa/turkic-ocr-qwen3-vl-2b` | Qwen3-VL-2B, the comparison model || `treoa/turkic-ocr-qwen3-vl-2b-latin` | its continuation (two seeds) || `treoa/turkic-ocr-ppocrv6-medium` | the light CTC line recognizer with a character 6-gram language model || `treoa/turkic-line-detector-yolo11s` | the line detector (public) |```bashhf download treoa/turkic-ocr-paddleocr-vl-1.6 --local-dir models/paddleocr-vl```## DataNo dataset is stored here. The generated data are on the Hugging Face Hub, in four configurations (`hand`, `typed`,76 unmodified linesTraining. The training entry points are `scripts/r5_vlma/train_vlm.py` (full fine-tuning of the vision-languagereaders), `scripts/r5_vlmb/vlmb_train.py` (readers that need their maker's code), `src/linedet/train_arm.py` (CTC linerecognizers), `src/linedet/det_yolo.py` (detector) and `scripts/r5_rq2/rq2_train.py` (augmentation study). The fullruns 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.## Seeds14 unmodified lines## Not included- Data of any kind: real datasets, generated data, manifests, splits, predictions.- Weights of the fine-tuned readers: they are in their own gated repositories (see Models).- Font files.- The scripts of the continued training on real Latin-script handwriting, of the IAM scoring and of the later,more realistic generator version.
1234567891011"""Quick whole-page check of B1 (PaddleOCR-VL 1.6 R5 leader) on CPU: one prompt, a few validation pages.Not a benchmark: a smoke sample before a deadline. Validation pages only. Reuses the R5 loader and prompt builder(CODE/scripts/r5_vlma/vlm_common.py) with the instruction swapped, greedy decoding, bf16 as in the R5 evaluation.Writes one JSON line per page as soon as it is read, and stops before --stop_utc.usage: b1_page_check.py --model DIR --pages TSV --start K --n N --prompt spot|instr|ocr --out JSONL --stop_utc HH:MM"""import argparseimport jsonimport os123import argparseimport jsonimport os
5 unmodified lines67891011125 unmodified lines#SBATCH --time=00:45:00#SBATCH --array=0-7#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%A_%a.out# Task t: prompt = spot (t<4) or instr; set = gen (t%4<2) or school; chunk = t%2 of 2 (5 pages each).set -uCODE=/path/to/TURKIC_OCR_CODED=/path/to/TURKIC_OCR_DATA5 unmodified lines678910115 unmodified lines#SBATCH --time=00:45:00#SBATCH --array=0-7#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%A_%a.outset -uCODE=/path/to/TURKIC_OCR_CODED=/path/to/TURKIC_OCR_DATA
1234567891011"""Score the B1 whole-page check, and route A (YOLO11s stage 2 + A1 long) on the SAME pages for comparison.Page CER exactly as linedet.det_eval.page_cers (metric M28 reading order: lines joined by one space; M29 order free:lines matched one to one by minimum edit distance, unmatched lines count in full). Micro average: summed edits oversummed reference characters. B1 lines keep the model's own output order.usage: b1_page_score.py --dir OUT_DIR --routeA_dir DET_EVAL_DIR --out JSON"""import argparseimport globimport json123import argparseimport globimport json
5 unmodified lines6789101112135 unmodified lines#SBATCH --time=00:40:00#SBATCH --array=0-5#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%A_%a.out# The original PaddleOCR-VL 1.6 (the pinned copy B1 was fine-tuned from) on the same pages as b1_page_check.# Task t: prompt = spot (t<4) or ocr (t>=4, generated pages only); set = gen (t%4<2) or school; chunk = t%2.set -uCODE=/path/to/TURKIC_OCR_CODED=/path/to/TURKIC_OCR_DATA5 unmodified lines678910115 unmodified lines#SBATCH --time=00:40:00#SBATCH --array=0-5#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%A_%a.outset -uCODE=/path/to/TURKIC_OCR_CODED=/path/to/TURKIC_OCR_DATA
123456789101112"""Line detector + B1 on the same sampled validation pages as b1_page_check.py.The detector boxes are the stored YOLO11s stage-2 boxes from the route A run (det_eval e2e_yolo_s2_*_A1_long_pages.jsonl),so detection is identical to route A and only the reader changes (A1 -> B1). Reading order, crop margins and the schoolfull-resolution lookup are copied from linedet.det_eval. B1 reads each crop with its training instruction, greedy, bf16 onCPU, at most 192 new tokens per line (vlm_common.MAXNEW['line']).usage: detb1_page_check.py --set gen|school --pages TSV --stride K --n 10 --chunk C --chunks 2 --routeA JSONL --out JSONL"""import argparseimport jsonimport os123import argparseimport jsonimport os
5 unmodified lines67891011125 unmodified lines#SBATCH --time=00:35:00#SBATCH --array=0-7#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%A_%a.out# Task t: set = gen (t<4) or school; chunk = t%4 of 4 (2-3 pages each).set -uCODE=/path/to/TURKIC_OCR_CODED=/path/to/TURKIC_OCR_DATA5 unmodified lines678910115 unmodified lines#SBATCH --time=00:35:00#SBATCH --array=0-7#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%A_%a.outset -uCODE=/path/to/TURKIC_OCR_CODED=/path/to/TURKIC_OCR_DATA
1234567"""Build screen_set_v1.tsv by screen_rule_v1.txt. Reads only validation.tsv.usage: build_screen_set.py VALIDATION_TSV OUT_TSV"""import collectionsimport hashlibimport sys123import collectionsimport hashlibimport sys
12345"""Does images_kwargs (size) reach the image processor in apply_chat_template? Processor only, one crop, no model.usage: check_images_kwargs.py MODELS_DIR PROMPTS_JSON IMG_DIR CROP_FILE short [short ...]"""import jsonimport osimport sys123import jsonimport osimport sys
123456789101112"""Turn finished (or partly finished) J2 outputs into results.tsv. Run on the cluster (the per-crop files hold labels and stay there).usage: collect.py OUT_ROOT SCREEN_SET_TSV SCORELIB_PY RESULTS_TSV [model ...]OUT_ROOT = DATA/outputs/j11_stage1_kohtd (model folders s1/ s2/ s3/ with preds.jsonl, timing.jsonl, meta.json).Robust to a job killed by its time limit: a half-written last line of preds.jsonl or timing.jsonl is skipped and counted(bad_lines); if meta.json was never written the row is filled from timing.jsonl, the screen set and loadtest/<model>.json.Every speed and memory column carries the suffix _H100_not_5090: all figures come from one H100, not from an RTX 5090.A row is complete when crops_done == crops_in_list; the column complete says so."""import importlib.utilimport jsonimport os123import importlib.utilimport jsonimport os
123456789"""Per-crop contrast stretch for the J2 contrast control. One function; it changes the grey levels and nothing else.contrast_stretch(img): the 1st and 99th percentile of the crop's grey (PIL 'L' conversion) are mapped to 0 and 255; the samelinear map is applied to the three colour channels, so colour relations are kept; values are clipped to 0..255. Size and mode(RGB) do not change. A crop with a grey range below 1 level is returned unchanged (as RGB)."""import numpy as npfrom PIL import Image123import numpy as npfrom PIL import Image
1234567"""Score the positive control with the screen's scorelib (same post-processing, same CER) and write positive_control.tsv.usage: control_report.py CONTROL_LIST SCORELIB_PY OUT_TSV label=OUT_ROOT [label=OUT_ROOT ...]label is cpu or gpu; OUT_ROOT holds <model>/s1/preds.jsonl."""import importlib.utilimport jsonimport os123import importlib.utilimport jsonimport os
6 unmodified lines78910111213146 unmodified lines#SBATCH --mem=64G#SBATCH --time=06:00:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out# J2 positive control on ZEN4 CPU: the SAME run_screen.py, prompts, batch size 16, 1x, bf16, greedy, 48 new tokens, on the 400# printed control images. Output folder: DATA/outputs/j11_positive_control/out_cpu. usage: sbatch control_run_cpu.sbatch short [short ...]set -uCODE=/path/to/TURKIC_OCR_CODEDATA=/path/to/TURKIC_OCR_DATA6 unmodified lines7891011126 unmodified lines#SBATCH --mem=64G#SBATCH --time=06:00:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.outset -uCODE=/path/to/TURKIC_OCR_CODEDATA=/path/to/TURKIC_OCR_DATA
6 unmodified lines78910111213146 unmodified lines#SBATCH --mem=96G#SBATCH --time=01:30:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out# J2 positive control on one H100: the SAME run_screen.py, prompts, batch size 16, 1x, bf16, greedy, 48 new tokens, on the 400# printed control images. Output folder: DATA/outputs/j11_positive_control/out_gpu. usage: sbatch control_run_gpu.sbatch short [short ...]set -uCODE=/path/to/TURKIC_OCR_CODEDATA=/path/to/TURKIC_OCR_DATA6 unmodified lines7891011126 unmodified lines#SBATCH --mem=96G#SBATCH --time=01:30:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.outset -uCODE=/path/to/TURKIC_OCR_CODEDATA=/path/to/TURKIC_OCR_DATA
123456789"""Score the two small controls (contrast, handwriting fonts) with the screen's scorelib and write controls_2.tsv.A printed-text row (PT Sans, 40 px, from the first positive control) is scored with the same code for comparison.usage: controls2_report.py C2_DIR PRINTED_LIST PRINTED_OUT_ROOT SCORELIB_PY OUT_TSVC2_DIR holds contrast_stored_/contrast_stretch_/fonts_screen_set_v1.tsv and out_stored/ out_stretch/ out_fonts/."""import importlib.utilimport jsonimport os123import importlib.utilimport jsonimport os
6 unmodified lines78910111213146 unmodified lines#SBATCH --mem=64G#SBATCH --time=04:00:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out# J2 controls 2 on ZEN4 CPU: the SAME run_screen.py, prompts, batch size 16, 1x, bf16, greedy, 48 new tokens.# usage: sbatch controls2_run_cpu.sbatch SET:MODEL [SET:MODEL ...] with SET = stored | stretch | fontsset -uCODE=/path/to/TURKIC_OCR_CODEDATA=/path/to/TURKIC_OCR_DATA6 unmodified lines7891011126 unmodified lines#SBATCH --mem=64G#SBATCH --time=04:00:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.outset -uCODE=/path/to/TURKIC_OCR_CODEDATA=/path/to/TURKIC_OCR_DATA
1234567891011121314"""J2 step 2: eligibility facts for the 20 models of screen.list_S. Runs on a ZEN4 node with .venv_vlm.Downloads (no token, no .py file) only config, tokenizer, processor, chat template and README files andreads the file list with sizes from the Hub API. Then, with the pinned transformers release only:- checks that model_type and architecture are native classes (trust_remote_code is never set),- builds the native model class on the meta device (no weights) and counts parameters,- loads the tokenizer and the processor with trust_remote_code=False,- round-trips the 238 project symbols and all validation labels through the tokenizer (E3).usage: eligibility.py MODELS_TSV CODEC_JSON VALIDATION_TSV MODELS_DIR OUT_DIR [only_short ...]"""import collectionsimport jsonimport os123import collectionsimport jsonimport os
6 unmodified lines789101112136 unmodified lines#SBATCH --mem=24G#SBATCH --time=02:00:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out# J2 step 2: eligibility facts. Downloads only config/tokenizer/processor/template/README files (no .py, no weights), no token.set -euCODE=/path/to/TURKIC_OCR_CODEDATA=/path/to/TURKIC_OCR_DATA6 unmodified lines7891011126 unmodified lines#SBATCH --mem=24G#SBATCH --time=02:00:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.outset -euCODE=/path/to/TURKIC_OCR_CODEDATA=/path/to/TURKIC_OCR_DATA
12345678910"""J2 step 2b: fetch root-level safetensors weights of the run candidates and test the native weight load on CPU.No token, no .py file, trust_remote_code is never set. A model passes the load gate only if from_pretrained with thenative class reports no missing key and no mismatched key; unexpected keys are listed for reading.usage: fetch_weights_loadtest.py MODELS_DIR OUT_DIR short [short ...]"""import jsonimport osimport struct123import jsonimport osimport struct
6 unmodified lines789101112136 unmodified lines#SBATCH --mem=64G#SBATCH --time=03:00:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out# J2 step 2b: root-level safetensors download (no token, no .py) and native weight-load gate on CPU.set -euCODE=/path/to/TURKIC_OCR_CODEDATA=/path/to/TURKIC_OCR_DATA6 unmodified lines7891011126 unmodified lines#SBATCH --mem=64G#SBATCH --time=03:00:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.outset -euCODE=/path/to/TURKIC_OCR_CODEDATA=/path/to/TURKIC_OCR_DATA
6 unmodified lines78910111213146 unmodified lines#SBATCH --mem=16G#SBATCH --time=00:30:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out# J2: gather everything that has finished (CPU only, no model): results.tsv, raw_samples.tsv, positive_control.tsv (cpu and gpu roots),# controls_2.tsv. Safe to run again at any time.set -uCODE=/path/to/TURKIC_OCR_CODEDATA=/path/to/TURKIC_OCR_DATA6 unmodified lines7891011126 unmodified lines#SBATCH --mem=16G#SBATCH --time=00:30:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.outset -uCODE=/path/to/TURKIC_OCR_CODEDATA=/path/to/TURKIC_OCR_DATA
123456789"""J2 harness audit: what exactly goes into each model for 5 KOHTD validation crops and 5 positive-control images.Processor only (no model weights), CPU. The input is built the same way as run_screen.py (build_inputs, batch of one).Text and numbers only; no image data is printed.usage: harness_audit.py MODELS_DIR PROMPTS_JSON SCREEN_SET KOHTD_IMG_DIR CONTROL_LIST CONTROL_IMG_DIR OUT_TXT short [short ...]"""import copyimport jsonimport os123import copyimport jsonimport os
6 unmodified lines789101112136 unmodified lines#SBATCH --mem=24G#SBATCH --time=01:00:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out# J2 harness audit (processor only, CPU, offline). Writes DATA/outputs/j11_positive_control/harness_audit.txt (text and numbers only).set -uCODE=/path/to/TURKIC_OCR_CODEDATA=/path/to/TURKIC_OCR_DATA6 unmodified lines7891011126 unmodified lines#SBATCH --mem=24G#SBATCH --time=01:00:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.outset -uCODE=/path/to/TURKIC_OCR_CODEDATA=/path/to/TURKIC_OCR_DATA
12345678910"""J2: which checkpoint tensors does the native class not use, and which model tensors are not from the checkpoint?Exact match by (shape, sha1 of the bf16 bytes), so renamed keys still match. Checkpoint tensors with no matching modeltensor were dropped by the loader (not instantiated or ignored on load); model tensors with no matching checkpointtensor were created or changed by the loader (random init, fused, split or tied differently).usage: keyaudit.py MODELS_DIR OUT_DIR short [short ...]"""import hashlibimport jsonimport os123import hashlibimport jsonimport os
6 unmodified lines789101112136 unmodified lines#SBATCH --mem=64G#SBATCH --time=01:30:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out# J2: checkpoint-versus-model tensor audit (CPU, offline).set -euCODE=/path/to/TURKIC_OCR_CODEDATA=/path/to/TURKIC_OCR_DATA6 unmodified lines7891011126 unmodified lines#SBATCH --mem=64G#SBATCH --time=01:30:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.outset -euCODE=/path/to/TURKIC_OCR_CODEDATA=/path/to/TURKIC_OCR_DATA
1234567891011121314"""J2 positive control: 200 printed words (100 Kazakh + 100 Kyrgyz, Cyrillic) rendered in PT Sans (OFL 1.1), black on white, atheights 40 px and 80 px = 400 images. Words come from the DISPLAY sentence banks that pagesynth uses.(There is no Russian bank in pagesynth_text; the plan allows Kazakh + Kyrgyz then.)Word choice: whitespace tokens of the display sentences with punctuation stripped from both ends; keep tokens that areall letters, 3 to 12 characters, every letter in the Cyrillic block, every glyph in the font; ascending sha256 of"J2-control-v1:<lang>:<word>"; first 100 per language. Writes the list in the screen-set format(positive_control_screen_set_v1.tsv: crop_file, form_id, label) and the images.usage: make_control_set.py BANK_KK BANK_KY FONT_TTF OUT_DIR"""import hashlibimport osimport sys123import hashlibimport osimport sys
6 unmodified lines789101112136 unmodified lines#SBATCH --mem=16G#SBATCH --time=00:30:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out# J2 positive control: render 400 printed word images (CPU).set -euCODE=/path/to/TURKIC_OCR_CODEDATA=/path/to/TURKIC_OCR_DATA6 unmodified lines7891011126 unmodified lines#SBATCH --mem=16G#SBATCH --time=00:30:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.outset -euCODE=/path/to/TURKIC_OCR_CODEDATA=/path/to/TURKIC_OCR_DATA
1234567891011121314"""J2 second follow-up controls: build the image sets.A. Contrast: the first 300 crops of screen_set_v1.tsv (file order). List "stored" = the crops as stored (names unchanged, images areread from the KOHTD folder). List "stretch" = the same crops after contrast_stretch (own PNG copies; PNG so no new JPEG loss).The KOHTD images stay on the cluster.B. Handwriting fonts, no real ink: the same 200 Kazakh and Kyrgyz control words (the 40 px rows of control_words.tsv) rendered atheight 40 px in Caveat and Bad Script (OFL), black on white. A word with a letter the font lacks is left out for that fontand listed.usage: make_controls2_set.py SCREEN_SET KOHTD_IMG_DIR CONTROL_WORDS_TSV CONTRAST_STRETCH_PY FONT_CAVEAT FONT_BADSCRIPT OUT_DIR"""import importlib.utilimport osimport sys123import importlib.utilimport osimport sys
6 unmodified lines789101112136 unmodified lines#SBATCH --mem=16G#SBATCH --time=00:30:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out# J2 controls 2: contrast-stretched copies of the first 300 screen crops, and the 200 control words in two OFL handwriting fonts (CPU).set -euCODE=/path/to/TURKIC_OCR_CODEDATA=/path/to/TURKIC_OCR_DATA6 unmodified lines7891011126 unmodified lines#SBATCH --mem=16G#SBATCH --time=00:30:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.outset -euCODE=/path/to/TURKIC_OCR_CODEDATA=/path/to/TURKIC_OCR_DATA
12345678"""20 raw outputs per model and enlargement next to their references (for manual inspection only, never for a page).Same 20 crops for every model and scale: ascending sha256 of "J2-raw-sample-v1:" + crop_file over the screen set.Only crops that are already done are listed (a partial run shows fewer than 20 rows; the column crops_of_sample_done says so).usage: raw_samples.py OUT_ROOT SCREEN_SET_TSV SCORELIB_PY OUT_TSV"""import hashlibimport importlib.utilimport json123import hashlibimport importlib.utilimport json
6 unmodified lines789101112131415166 unmodified lines#SBATCH --mem=96G#SBATCH --time=02:00:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out# J2 step 6: zero-shot screen of 2-4 models on the KOHTD validation word crops, one model after another, offline.# Order: enlargement 1x for every model of the job first, then 2x, then 3x, so that a timeout still leaves 1x for all.# Every model writes JSONL after each batch and resumes from it: a job that ran out of time is simply submitted again.# usage: sbatch --job-name=j2_gpuA run_gpu_job.sbatch short [short ...]set -uCODE=/path/to/TURKIC_OCR_CODEDATA=/path/to/TURKIC_OCR_DATA6 unmodified lines7891011126 unmodified lines#SBATCH --mem=96G#SBATCH --time=02:00:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.outset -uCODE=/path/to/TURKIC_OCR_CODEDATA=/path/to/TURKIC_OCR_DATA
12345678910111213"""J2 screen: zero-shot reading of KOHTD validation word crops with one stock-transformers model.Native transformers classes only (trust_remote_code is never set), safetensors only, greedy, bf16, sdpa.This script never reads labels and never opens train.tsv or test.tsv: it reads crop_file from screen_set_v1.tsv only.Writes after every batch and resumes from preds.jsonl.usage: run_screen.py SHORT MODELS_DIR PROMPTS_JSON SCREEN_SET_TSV IMG_DIR OUT_ROOT[--batch-size 16] [--max-new-tokens 48] [--scales 1,2,3] [--limit N] [--device cuda|cpu][--threads N] [--check-batch-equal]"""import argparseimport copyimport json123import argparseimport copyimport json
6 unmodified lines789101112136 unmodified lines#SBATCH --mem=16G#SBATCH --time=01:00:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out# J2 step 1: new uv environment .venv_vlm (torch CUDA 12.8 build for H100, newest stable transformers, no vendor OCR packages).set -euUV=$HOME/.local/bin/uvVENV=/path/to/TURKIC_OCR_CODE/.venv_vlm6 unmodified lines7891011126 unmodified lines#SBATCH --mem=16G#SBATCH --time=01:00:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.outset -euUV=$HOME/.local/bin/uvVENV=/path/to/TURKIC_OCR_CODE/.venv_vlm
6 unmodified lines78910111213146 unmodified lines#SBATCH --mem=64G#SBATCH --time=03:00:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out# J2 step 6: smoke test, 5 crops per model on ZEN4 CPU, offline. Output goes to a separate folder (not the production one).# usage: sbatch smoke_cpu.sbatch short [short ...]set -uCODE=/path/to/TURKIC_OCR_CODEDATA=/path/to/TURKIC_OCR_DATA6 unmodified lines7891011126 unmodified lines#SBATCH --mem=64G#SBATCH --time=03:00:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.outset -uCODE=/path/to/TURKIC_OCR_CODEDATA=/path/to/TURKIC_OCR_DATA
6 unmodified lines78910111213146 unmodified lines#SBATCH --mem=96G#SBATCH --time=00:30:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out# 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# bookkeeping), offline, separate output folder. usage: sbatch smoke_gpu.sbatch short [short ...]set -uCODE=/path/to/TURKIC_OCR_CODEDATA=/path/to/TURKIC_OCR_DATA6 unmodified lines7891011126 unmodified lines#SBATCH --mem=96G#SBATCH --time=00:30:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.outset -uCODE=/path/to/TURKIC_OCR_CODEDATA=/path/to/TURKIC_OCR_DATA
12345"""Test collect.py on synthetic outputs with a half-written last line and no meta.json.usage: test_collect.py SCRIPTS_DIR WORK_DIR"""import jsonimport osimport subprocess123import jsonimport osimport subprocess
1234"""Unit test of contrast_stretch. usage: test_contrast_stretch.py PATH_TO_contrast_stretch.py"""import importlib.utilimport sys123import importlib.utilimport sys
1234"""Synthetic test of controls2_report.py. usage: test_controls2_report.py SCRIPTS_DIR WORK_DIR"""import jsonimport osimport subprocess123import jsonimport osimport subprocess
199 unmodified lines20020120220320420520619 unmodified lines22622722822923023123216 unmodified lines2492502512522532542553 unmodified lines25926026126226326426545 unmodified lines31131231331431531631731831912 unmodified lines33233333433533633733820 unmodified lines35936036136236336436556 unmodified lines42242342442542642742830 unmodified lines459460461462463464465199 unmodified linesres["membership_rebuilt_from_file_names"] = countsprint("counts", counts, flush=True)# ---- features for all crops (cached) ----cache = os.path.join(OUT, "features.npz")if os.path.exists(cache):z = np.load(cache, allow_pickle=True)19 unmodified linesres["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))}AR = (W / np.maximum(H, 1)).astype(np.float32)# ---- exact duplicates ----def dup_report(key, label):by = collections.defaultdict(list)for i in range(len(NAMES)):16 unmodified linesres["exact_duplicates_decoded_pixels"] = dup_report(pix, "sha256 of the decoded grayscale pixels")print("exact dup", res["exact_duplicates_file_sha256"], res["exact_duplicates_decoded_pixels"], flush=True)# ---- sets ----iS = np.where((grp == G_S) & valid)[0]iN = np.where((grp == G_N) & valid)[0]iV = np.where((grp == G_V) & valid)[0]3 unmodified linesDdh, Dph, Dar = DH[DBi], PH[DBi], AR[DBi]res["valid_crops_used"] = {"scan": len(iS), "train_numbered": len(iN), "validation": len(iV), "test": len(iT)}# ---- positive controls ----rng = random.Random(SEED)ctrl_src = rng.sample(list(iN), 600)pos_in_db = {int(d): k for k, d in enumerate(DBi)}45 unmodified lines"tau_easy_p95_of_true_pairs": round(tau_easy, 4), "tau_hard_p95_of_true_pairs": round(tau_hard, 4)}print("controls", json.dumps(ctrl)[:1500], flush=True)# ---- real query: scan-named crops against V, T, N ----bdS, biS, _ = nn(DH[iS], PH[iS], AR[iS], Ddh, Dph, Dar, segs)# ---- null query: a random sample of numbered TRAIN crops, same size, against V and T only (form-disjoint by construction) ----nrng = np.random.RandomState(SEED)sampN = nrng.choice(iN, len(iS), replace=False)VT = (0, len(iV) + len(iT))12 unmodified linesres["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))}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."# ---- NCC second check on the closest pairs ----from multiprocessing import Poolbest_seg = np.where(bdS[:, 0] <= bdS[:, 1], 0, 1)real_idx = np.where(best_seg == 0, biS[:, 0], biS[:, 1]) # DB index20 unmodified linesres["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()),"in_validation": int((best_seg[conf_q] == 0).sum()), "in_test": int((best_seg[conf_q] == 1).sum())}# ---- vote per scan name ----snames = np.array([re.match(scan, NAMES[i]).group(1) for i in iS])allbest = bdS.argmin(1)best_dist = bdS.min(1)56 unmodified linesres["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]],"crops_of_linked_names": int(sum(len(by_name[k]) for k, _, _ in ln))}# ---- examples: five closest scan-to-val/test pairs by NCC among the K closest by hash ----order_ex = np.argsort(-nccR)[:5]ex = []from PIL import Image, ImageDraw, ImageFont30 unmodified linespanel.save(os.path.join(OUT, "examples_panel.png"))res["examples_five_closest_scan_to_val_or_test"] = ex# ---- step 4: name structure and image traits ----snm = re.compile(r"^Скан_(\d{8})(?:_(\d+))?(?: \((\d+)\))?$")names_all = sorted(set(sname[i] for i in range(len(NAMES)) if grp[i] == G_S))per_date = collections.defaultdict(lambda: {"names": 0, "crops": 0, "n_values": set(), "heights": []})199 unmodified lines20020120220320420520619 unmodified lines22622722822923023123216 unmodified lines2492502512522532542553 unmodified lines25926026126226326426545 unmodified lines31131231331431531631731831912 unmodified lines33233333433533633733820 unmodified lines35936036136236336436556 unmodified lines42242342442542642742830 unmodified lines459460461462463464465199 unmodified linesres["membership_rebuilt_from_file_names"] = countsprint("counts", counts, flush=True)# features for all crops (cached)cache = os.path.join(OUT, "features.npz")if os.path.exists(cache):z = np.load(cache, allow_pickle=True)19 unmodified linesres["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))}AR = (W / np.maximum(H, 1)).astype(np.float32)# exact duplicatesdef dup_report(key, label):by = collections.defaultdict(list)for i in range(len(NAMES)):16 unmodified linesres["exact_duplicates_decoded_pixels"] = dup_report(pix, "sha256 of the decoded grayscale pixels")print("exact dup", res["exact_duplicates_file_sha256"], res["exact_duplicates_decoded_pixels"], flush=True)# setsiS = np.where((grp == G_S) & valid)[0]iN = np.where((grp == G_N) & valid)[0]iV = np.where((grp == G_V) & valid)[0]3 unmodified linesDdh, Dph, Dar = DH[DBi], PH[DBi], AR[DBi]res["valid_crops_used"] = {"scan": len(iS), "train_numbered": len(iN), "validation": len(iV), "test": len(iT)}# positive controlsrng = random.Random(SEED)ctrl_src = rng.sample(list(iN), 600)pos_in_db = {int(d): k for k, d in enumerate(DBi)}45 unmodified lines"tau_easy_p95_of_true_pairs": round(tau_easy, 4), "tau_hard_p95_of_true_pairs": round(tau_hard, 4)}print("controls", json.dumps(ctrl)[:1500], flush=True)# real query: scan-named crops against V, T, NbdS, biS, _ = nn(DH[iS], PH[iS], AR[iS], Ddh, Dph, Dar, segs)# null query: a random sample of numbered TRAIN crops, same size, against V and T only (form-disjoint by construction)nrng = np.random.RandomState(SEED)sampN = nrng.choice(iN, len(iS), replace=False)VT = (0, len(iV) + len(iT))12 unmodified linesres["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))}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."# NCC second check on the closest pairsfrom multiprocessing import Poolbest_seg = np.where(bdS[:, 0] <= bdS[:, 1], 0, 1)real_idx = np.where(best_seg == 0, biS[:, 0], biS[:, 1]) # DB index20 unmodified linesres["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()),"in_validation": int((best_seg[conf_q] == 0).sum()), "in_test": int((best_seg[conf_q] == 1).sum())}# vote per scan namesnames = np.array([re.match(scan, NAMES[i]).group(1) for i in iS])allbest = bdS.argmin(1)best_dist = bdS.min(1)56 unmodified linesres["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]],"crops_of_linked_names": int(sum(len(by_name[k]) for k, _, _ in ln))}# examples: five closest scan-to-val/test pairs by NCC among the K closest by hashorder_ex = np.argsort(-nccR)[:5]ex = []from PIL import Image, ImageDraw, ImageFont30 unmodified linespanel.save(os.path.join(OUT, "examples_panel.png"))res["examples_five_closest_scan_to_val_or_test"] = ex# step 4: name structure and image traitssnm = re.compile(r"^Скан_(\d{8})(?:_(\d+))?(?: \((\d+)\))?$")names_all = sorted(set(sname[i] for i in range(len(NAMES)) if grp[i] == G_S))per_date = collections.defaultdict(lambda: {"names": 0, "crops": 0, "n_values": set(), "heights": []})
6 unmodified lines789101112136 unmodified lines#SBATCH --mem=48G#SBATCH --time=01:30:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out# Leakage check on KOHTD: scan-named training crops versus validation/test crops, images only (no label file is read).C=/path/to/TURKIC_OCR_CODED=/path/to/TURKIC_OCR_DATAecho "== start $(date) job $SLURM_JOB_ID"6 unmodified lines7891011126 unmodified lines#SBATCH --mem=48G#SBATCH --time=01:30:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.outC=/path/to/TURKIC_OCR_CODED=/path/to/TURKIC_OCR_DATAecho "== start $(date) job $SLURM_JOB_ID"
6 unmodified lines7891011121314156 unmodified lines#SBATCH --mem=24G#SBATCH --time=02:00:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out# R5 DATA: run this ONCE GEN's synthetic manifests (synth_{hand,typed,clutter,pages}_{train,val,test}.tsv) are written and no longer change.# 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# synthetic train labels, 5 rewrite manifest_stats.json, evalsets.json and mix_v1_shares.json (placeholders become ready sets).PY=/path/to/TURKIC_OCR_CODE/.venv/bin/pythonS=/path/to/TURKIC_OCR_CODE/scripts/r5$PY -I $S/r5_build_real.py hash_synth dedupe_all --force6 unmodified lines7891011126 unmodified lines#SBATCH --mem=24G#SBATCH --time=02:00:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.outPY=/path/to/TURKIC_OCR_CODE/.venv/bin/pythonS=/path/to/TURKIC_OCR_CODE/scripts/r5$PY -I $S/r5_build_real.py hash_synth dedupe_all --force
6 unmodified lines789101112136 unmodified lines#SBATCH --mem=16G#SBATCH --time=02:00:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out# R5 DATA: real-data manifests, part A (see r5_build_real.py)PY=/path/to/TURKIC_OCR_CODE/.venv/bin/pythonS=/path/to/TURKIC_OCR_CODE/scripts/r5/r5_build_real.py$PY -I $S kohtd --force6 unmodified lines7891011126 unmodified lines#SBATCH --mem=16G#SBATCH --time=02:00:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.outPY=/path/to/TURKIC_OCR_CODE/.venv/bin/pythonS=/path/to/TURKIC_OCR_CODE/scripts/r5/r5_build_real.py$PY -I $S kohtd --force
6 unmodified lines789101112136 unmodified lines#SBATCH --mem=32G#SBATCH --time=03:00:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out# R5 DATA: real-data manifests, part B (see r5_build_real.py)PY=/path/to/TURKIC_OCR_CODE/.venv/bin/pythonS=/path/to/TURKIC_OCR_CODE/scripts/r5/r5_build_real.py$PY -I $S school6 unmodified lines7891011126 unmodified lines#SBATCH --mem=32G#SBATCH --time=03:00:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.outPY=/path/to/TURKIC_OCR_CODE/.venv/bin/pythonS=/path/to/TURKIC_OCR_CODE/scripts/r5/r5_build_real.py$PY -I $S school
6 unmodified lines789101112136 unmodified lines#SBATCH --mem=32G#SBATCH --time=02:00:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out# R5 DATA: real-data manifests, part C (see r5_build_real.py)PY=/path/to/TURKIC_OCR_CODE/.venv/bin/pythonS=/path/to/TURKIC_OCR_CODE/scripts/r5/r5_build_real.py$PY -I $S hash dedupe6 unmodified lines7891011126 unmodified lines#SBATCH --mem=32G#SBATCH --time=02:00:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.outPY=/path/to/TURKIC_OCR_CODE/.venv/bin/pythonS=/path/to/TURKIC_OCR_CODE/scripts/r5/r5_build_real.py$PY -I $S hash dedupe
123456789101112131415161784 unmodified lines10210310410510610710889 unmodified lines19819920020120220320451 unmodified lines25625725825926026126247 unmodified lines310311312313314315316130 unmodified lines44744844945045145245339 unmodified lines49349449549649749849945 unmodified lines545546547548549550551156 unmodified lines708709710711712713714"""R5 DATA: build the real-data manifests of round R5 (shared TSV format of the R5 common specification).Stages (run in this order; each stage writes its outputs and a stage log, and is skipped if its log exists, unless --force):kohtd K1 split -> kohtd_{train,val,test}, kohtd_screen_v1 (V1, unchanged), kohtd_lmtune (500 validation crops not in V1, seed 20261121)hkr HKR words (Kaggle mirror zip): extract jpg, official split (train / val / test1 / test2) from the project's HKR audit manifestchd Cyrillic Handwriting Dataset (CHD): extract png; official train / test; validation carved from train by word typeschool school_notebooks_ru: word crops from pupil_text polygons, page split keptrukopys RUKOPYS test: handwritten, legible, Ukrainian line crops from the boxes (test only)hash sha256 + perceptual hash (64-bit pHash) of every image in every manifestdedupe drop train images that are byte-identical or near-identical (pHash distance <= 4) to a val or test image of any sourceRaw manifests (before dedupe) go to DATA/data/processed/r5/manifests_pre_dedupe/, final ones to .../r5/manifests/.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."""import argparseimport collectionsimport csv84 unmodified linessource=source, split=split, group=group, unit=unit)# ----------------------------------------------------------------------------- KOHTDdef read_k1(path):out = []with open(path, encoding="utf-8", newline="") as f:89 unmodified linesprint(json.dumps(info, ensure_ascii=False)[:2000])# ----------------------------------------------------------------------------- HKRHKR_PREFIX = "HKR_Dataset_Words_Public/20200923_Dataset_Words_Public/"51 unmodified linesprint(json.dumps(info, ensure_ascii=False)[:2000])# ----------------------------------------------------------------------------- CHDdef stage_chd():info = {"stage": "chd"}z = zipfile.ZipFile(RAW / "chd/archive.zip")47 unmodified linesprint(json.dumps(info, ensure_ascii=False)[:2000])# ----------------------------------------------------------------------------- school notebooksdef poly_pts(seg):flat = seg[0] if seg and isinstance(seg[0], list) else segpts = np.array(flat, dtype=np.float32).reshape(-1, 2)130 unmodified linesprint(json.dumps(info, ensure_ascii=False, default=str)[:2000])# ----------------------------------------------------------------------------- RUKOPYS testdef stage_rukopys():info = {"stage": "rukopys"}base = RAW / "rukopys_test/test"39 unmodified linesprint(json.dumps(info, ensure_ascii=False)[:2000])# ----------------------------------------------------------------------------- hashingdef phash64(gray):small = cv2.resize(gray, (32, 32), interpolation=cv2.INTER_AREA).astype(np.float32)dct = cv2.dct(small)45 unmodified linesprint(info)# ----------------------------------------------------------------------------- dedupedef stage_dedupe():info = {"stage": "dedupe"}hashes = {}156 unmodified lines# ----------------------------------------------------------------------------- synthetic manifests of GEN: hash and report-only duplicate checkdef synth_manifest_names():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"))12384 unmodified lines8889909192939489 unmodified lines18418518618718818919051 unmodified lines24224324424524624724847 unmodified lines296297298299300301302130 unmodified lines43343443543643743843939 unmodified lines47948048148248348448545 unmodified lines531532533534535536537156 unmodified lines694695696697698699700import argparseimport collectionsimport csv84 unmodified linessource=source, split=split, group=group, unit=unit)# KOHTDdef read_k1(path):out = []with open(path, encoding="utf-8", newline="") as f:89 unmodified linesprint(json.dumps(info, ensure_ascii=False)[:2000])# HKRHKR_PREFIX = "HKR_Dataset_Words_Public/20200923_Dataset_Words_Public/"51 unmodified linesprint(json.dumps(info, ensure_ascii=False)[:2000])# CHDdef stage_chd():info = {"stage": "chd"}z = zipfile.ZipFile(RAW / "chd/archive.zip")47 unmodified linesprint(json.dumps(info, ensure_ascii=False)[:2000])# school notebooksdef poly_pts(seg):flat = seg[0] if seg and isinstance(seg[0], list) else segpts = np.array(flat, dtype=np.float32).reshape(-1, 2)130 unmodified linesprint(json.dumps(info, ensure_ascii=False, default=str)[:2000])# RUKOPYS testdef stage_rukopys():info = {"stage": "rukopys"}base = RAW / "rukopys_test/test"39 unmodified linesprint(json.dumps(info, ensure_ascii=False)[:2000])# hashingdef phash64(gray):small = cv2.resize(gray, (32, 32), interpolation=cv2.INTER_AREA).astype(np.float32)dct = cv2.dct(small)45 unmodified linesprint(info)# dedupedef stage_dedupe():info = {"stage": "dedupe"}hashes = {}156 unmodified lines# synthetic manifests: hash and report-only duplicate checkdef synth_manifest_names():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"))
1234567"""R5 DATA: count what is on disk for every data source held on the cluster.Writes DATA/outputs/r5/disk_counts.json: for each source the counts and the exact files or folders that were counted.Read-only. Usage: python -I r5_disk_counts.py"""import collectionsimport jsonimport os123import collectionsimport jsonimport os
12345678"""R5 DATA (extra, beyond the plan): fetch the open Azerbaijani handwriting benchmark LocalDoc/azerbaijani-htr-benchmark(CC BY 4.0, 442 human-annotated line crops from 29 pages, test-sized) and write a test-only manifest.Plain public downloads, no login, no token, no special headers. The files are untrusted data: parquet is read with pyarrow only, nothing is executed.Run on a ZEN4 node: python -I r5_fetch_az_htr.py fetch | manifest"""import hashlibimport ioimport json123import hashlibimport ioimport json
6 unmodified lines789101112136 unmodified lines#SBATCH --mem=8G#SBATCH --time=00:40:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out# R5 DATA: after the duplicate check: validate the manifests, cut the P2 slice, write manifest statistics, the registry and the effective mix shares.PY=/path/to/TURKIC_OCR_CODE/.venv/bin/pythonS=/path/to/TURKIC_OCR_CODE/scripts/r5$PY -I $S/r5_validate_manifests.py6 unmodified lines7891011126 unmodified lines#SBATCH --mem=8G#SBATCH --time=00:40:00#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.outPY=/path/to/TURKIC_OCR_CODE/.venv/bin/pythonS=/path/to/TURKIC_OCR_CODE/scripts/r5$PY -I $S/r5_validate_manifests.py
1234"""R5 DATA: what does cleaning change in KOHTD labels, and what is the form_id of scan-named crops."""import collectionsimport unicodedatafrom pathlib import Path123import collectionsimport unicodedatafrom pathlib import Path
NOTICE+1-2
README.md+21-4
scripts/b1_page_check/b1_page_check.py-8
scripts/b1_page_check/b1_page_check.sbatch-1
scripts/b1_page_check/b1_page_score.py-8
scripts/b1_page_check/base_page_check.sbatch-2
scripts/b1_page_check/detb1_page_check.py-9
scripts/b1_page_check/detb1_page_check.sbatch-1
scripts/j2/build_screen_set.py-4
scripts/j2/check_images_kwargs.py-2
scripts/j2/collect.py-9
scripts/j2/contrast_stretch.py-6
scripts/j2/control_report.py-4
scripts/j2/control_run_cpu.sbatch-2
scripts/j2/control_run_gpu.sbatch-2
scripts/j2/controls2_report.py-6
scripts/j2/controls2_run_cpu.sbatch-2
scripts/j2/eligibility.py-11
scripts/j2/eligibility.sbatch-1
scripts/j2/fetch_weights_loadtest.py-7
scripts/j2/fetch_weights_loadtest.sbatch-1
scripts/j2/finalize.sbatch-2
scripts/j2/harness_audit.py-6
scripts/j2/harness_audit.sbatch-1
scripts/j2/keyaudit.py-7
scripts/j2/keyaudit.sbatch-1
scripts/j2/make_control_set.py-11
scripts/j2/make_control_set.sbatch-1
scripts/j2/make_controls2_set.py-11
scripts/j2/make_controls2_set.sbatch-1
scripts/j2/raw_samples.py-5
scripts/j2/run_gpu_job.sbatch-4
scripts/j2/run_screen.py-10
scripts/j2/setup_env_vlm.sbatch-1
scripts/j2/smoke_cpu.sbatch-2
scripts/j2/smoke_gpu.sbatch-2
scripts/j2/test_collect.py-2
scripts/j2/test_contrast_stretch.py-1
scripts/j2/test_controls2_report.py-1
scripts/kohtd_leak_scan.py+10-10
scripts/kohtd_leak_scan.sbatch-1
scripts/r5/r5_after_gen.sbatch-3
scripts/r5/r5_build_A.sbatch-1
scripts/r5/r5_build_B.sbatch-1
scripts/r5/r5_build_C.sbatch-1
scripts/r5/r5_build_real.py+8-22
scripts/r5/r5_disk_counts.py-4
scripts/r5/r5_fetch_az_htr.py-5
scripts/r5/r5_finalize.sbatch-1
scripts/r5/r5_kohtd_check.py-1