diff --git a/NOTICE b/NOTICE index 7b79c8c9d82f61e2478745430942f3dfbb29ea3d..bc993f135901bedd4df089394c4c067f1f2d781f 100644 --- a/NOTICE +++ b/NOTICE @@ -56,5 +56,4 @@ scripts/r5_ref/ref_common.py sets (PPOCR_ROOT); it is not included. NOT INCLUDED -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 -character language model). See README. +No data and no font files. The weights of the fine-tuned readers are in their own gated repositories (see README). diff --git a/README.md b/README.md index 7497b3cba4e176b6d5cbc5daaff57285151d57c1..78af5d495fea64bf637e6dab0e1a7552315fca33 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,25 @@ grep -rlF /path/to/TURKIC_OCR_DATA . | xargs sed -i 's#/path/to/TURKIC_OCR_DATA# The Slurm headers name the partitions of the original cluster. Many scripts read manifests and write records of the original run; those files are not part of this package. +## Models + +The trained readers are gated repositories on the Hugging Face Hub: access follows a request in which you agree to use the weights for +non-commercial research only (they were trained on data with such terms). Each repository has `infer.py`, `requirements.txt`, a model card +and 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) | + +```bash +hf download treoa/turkic-ocr-paddleocr-vl-1.6 --local-dir models/paddleocr-vl +``` + ## Data 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. Training. The training entry points are `scripts/r5_vlma/train_vlm.py` (full fine-tuning of the vision-language readers), `scripts/r5_vlmb/vlmb_train.py` (readers that need their maker's code), `src/linedet/train_arm.py` (CTC line recognizers), `src/linedet/det_yolo.py` (detector) and `scripts/r5_rq2/rq2_train.py` (augmentation study). The full -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 not released: the terms of KOHTD and HKR limit their use to the applicant's group and to academic -research. The detector was trained on School Notebooks photos and generated pages, and its weights are released. +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. ## Seeds @@ -196,7 +213,7 @@ study, run on validation data only. ## 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). +- 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. diff --git a/scripts/b1_page_check/b1_page_check.py b/scripts/b1_page_check/b1_page_check.py index 4e5eec042cdcd08db8fe58baf2b00b4c063aafd5..ee48872a790ad052db186b4e67d7255940204ed7 100644 --- a/scripts/b1_page_check/b1_page_check.py +++ b/scripts/b1_page_check/b1_page_check.py @@ -1,11 +1,3 @@ -"""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 argparse import json import os diff --git a/scripts/b1_page_check/b1_page_check.sbatch b/scripts/b1_page_check/b1_page_check.sbatch index 9d6b4384e7a5480cafca51871a55154e33f6a56f..fe2c1557f9bf1b130e8eac1102f6b012bd2eec8f 100644 --- a/scripts/b1_page_check/b1_page_check.sbatch +++ b/scripts/b1_page_check/b1_page_check.sbatch @@ -6,7 +6,6 @@ #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 -u CODE=/path/to/TURKIC_OCR_CODE D=/path/to/TURKIC_OCR_DATA diff --git a/scripts/b1_page_check/b1_page_score.py b/scripts/b1_page_check/b1_page_score.py index a3ffb1af6f58e07c6d65c9b41be69258ed52b0d6..7bb268418e6f82da5f7b7f0e6f459c3b7c5638ba 100644 --- a/scripts/b1_page_check/b1_page_score.py +++ b/scripts/b1_page_check/b1_page_score.py @@ -1,11 +1,3 @@ -"""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 over -summed 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 argparse import glob import json diff --git a/scripts/b1_page_check/base_page_check.sbatch b/scripts/b1_page_check/base_page_check.sbatch index 143671483b714b365ec1335100f0d7deb3b2e57a..bd8cab5efef0f012401dbe0a4d105452330b4387 100644 --- a/scripts/b1_page_check/base_page_check.sbatch +++ b/scripts/b1_page_check/base_page_check.sbatch @@ -6,8 +6,6 @@ #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 -u CODE=/path/to/TURKIC_OCR_CODE D=/path/to/TURKIC_OCR_DATA diff --git a/scripts/b1_page_check/detb1_page_check.py b/scripts/b1_page_check/detb1_page_check.py index 36cd2db1eafdd072877c3b00d031e8703e1aa07c..3f534d370b58d1b34e41b04f1bf4ece2b0908047 100644 --- a/scripts/b1_page_check/detb1_page_check.py +++ b/scripts/b1_page_check/detb1_page_check.py @@ -1,12 +1,3 @@ -"""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 school -full-resolution lookup are copied from linedet.det_eval. B1 reads each crop with its training instruction, greedy, bf16 on -CPU, 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 argparse import json import os diff --git a/scripts/b1_page_check/detb1_page_check.sbatch b/scripts/b1_page_check/detb1_page_check.sbatch index 28ffbf646c82b0e05bf94a7b23539be8f88e151f..619a802d5a7211d6d5d2edf9a0a5f42bb10cfe3e 100644 --- a/scripts/b1_page_check/detb1_page_check.sbatch +++ b/scripts/b1_page_check/detb1_page_check.sbatch @@ -6,7 +6,6 @@ #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 -u CODE=/path/to/TURKIC_OCR_CODE D=/path/to/TURKIC_OCR_DATA diff --git a/scripts/j2/build_screen_set.py b/scripts/j2/build_screen_set.py index 35d8d8234b2c902f56f541b2c5ddd10b18520a5a..e25c6c3638bb5025f79179b3648a27fe1e503c8e 100644 --- a/scripts/j2/build_screen_set.py +++ b/scripts/j2/build_screen_set.py @@ -1,7 +1,3 @@ -"""Build screen_set_v1.tsv by screen_rule_v1.txt. Reads only validation.tsv. - -usage: build_screen_set.py VALIDATION_TSV OUT_TSV -""" import collections import hashlib import sys diff --git a/scripts/j2/check_images_kwargs.py b/scripts/j2/check_images_kwargs.py index c63ca9133cd7bfc044a36b473f6e1368c2f2bf56..d0b2efddae02006c31a0980ff57035741a0e8410 100644 --- a/scripts/j2/check_images_kwargs.py +++ b/scripts/j2/check_images_kwargs.py @@ -1,5 +1,3 @@ -"""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 json import os import sys diff --git a/scripts/j2/collect.py b/scripts/j2/collect.py index a834ec2e8939121d8a3109f38a2e586b0d10770c..31180f69a8df73800d0aa17106aed1d798dd1cfe 100644 --- a/scripts/j2/collect.py +++ b/scripts/j2/collect.py @@ -1,12 +1,3 @@ -"""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/.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.util import json import os diff --git a/scripts/j2/contrast_stretch.py b/scripts/j2/contrast_stretch.py index 49cf7a55019282dd5e0cb4ea6342374501415c73..20a110869b8bc11c3b6024efc613c288592c1ef5 100644 --- a/scripts/j2/contrast_stretch.py +++ b/scripts/j2/contrast_stretch.py @@ -1,9 +1,3 @@ -"""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 same -linear 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 np from PIL import Image diff --git a/scripts/j2/control_report.py b/scripts/j2/control_report.py index e760df29809b58be6091e2273c2b04ce042cfacb..1f653387b5d4245e9036c2d33ae833316381ffed 100644 --- a/scripts/j2/control_report.py +++ b/scripts/j2/control_report.py @@ -1,7 +1,3 @@ -"""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 /s1/preds.jsonl. -""" import importlib.util import json import os diff --git a/scripts/j2/control_run_cpu.sbatch b/scripts/j2/control_run_cpu.sbatch index 31e5a1726be837d9b3a17fad61de794051ba5653..24bc01295d2668074991209268519817dde1336b 100644 --- a/scripts/j2/control_run_cpu.sbatch +++ b/scripts/j2/control_run_cpu.sbatch @@ -7,8 +7,6 @@ #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 -u CODE=/path/to/TURKIC_OCR_CODE DATA=/path/to/TURKIC_OCR_DATA diff --git a/scripts/j2/control_run_gpu.sbatch b/scripts/j2/control_run_gpu.sbatch index a4942c0550278ef21ed87bb19f23e55da5cde11d..c29b8704f65b441ef9c32c6147e432f2146c69c6 100644 --- a/scripts/j2/control_run_gpu.sbatch +++ b/scripts/j2/control_run_gpu.sbatch @@ -7,8 +7,6 @@ #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 -u CODE=/path/to/TURKIC_OCR_CODE DATA=/path/to/TURKIC_OCR_DATA diff --git a/scripts/j2/controls2_report.py b/scripts/j2/controls2_report.py index f1cf3ea6925eebccf23fdbbf95ea63e2eb2a61f8..b3b7239c095488e43d6f35f7899c0ac69e38213d 100644 --- a/scripts/j2/controls2_report.py +++ b/scripts/j2/controls2_report.py @@ -1,9 +1,3 @@ -"""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_TSV -C2_DIR holds contrast_stored_/contrast_stretch_/fonts_screen_set_v1.tsv and out_stored/ out_stretch/ out_fonts/. -""" import importlib.util import json import os diff --git a/scripts/j2/controls2_run_cpu.sbatch b/scripts/j2/controls2_run_cpu.sbatch index f93fd8d1a81ef94f72a83857ee63fd8840e1ea8d..560a8c876901dd8ab9da83a6e3e28858ce02779d 100644 --- a/scripts/j2/controls2_run_cpu.sbatch +++ b/scripts/j2/controls2_run_cpu.sbatch @@ -7,8 +7,6 @@ #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 | fonts set -u CODE=/path/to/TURKIC_OCR_CODE DATA=/path/to/TURKIC_OCR_DATA diff --git a/scripts/j2/eligibility.py b/scripts/j2/eligibility.py index 7d7fddb71d4bea6c6c281d53122d9146188cd54d..eaa5998bafe79102576b0fe7d38e7c3489c604fa 100644 --- a/scripts/j2/eligibility.py +++ b/scripts/j2/eligibility.py @@ -1,14 +1,3 @@ -"""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 and -reads 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 collections import json import os diff --git a/scripts/j2/eligibility.sbatch b/scripts/j2/eligibility.sbatch index 96c449d7303ce73a1f6452d56d0ef95cb566edf5..c27eb265b43eb1850988856e0a62e8d947c504b4 100644 --- a/scripts/j2/eligibility.sbatch +++ b/scripts/j2/eligibility.sbatch @@ -7,7 +7,6 @@ #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 -eu CODE=/path/to/TURKIC_OCR_CODE DATA=/path/to/TURKIC_OCR_DATA diff --git a/scripts/j2/fetch_weights_loadtest.py b/scripts/j2/fetch_weights_loadtest.py index 881e85a06a421a79a307c96479ce665969f88141..37ca0c7eb4dfb621ffccc56ed8194f3e0f748002 100644 --- a/scripts/j2/fetch_weights_loadtest.py +++ b/scripts/j2/fetch_weights_loadtest.py @@ -1,10 +1,3 @@ -"""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 the -native 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 json import os import struct diff --git a/scripts/j2/fetch_weights_loadtest.sbatch b/scripts/j2/fetch_weights_loadtest.sbatch index 0793413519fd6a0373d55ea27082f008246970b7..4ff643117eba343b05c84be6b1a47f119c726a8f 100644 --- a/scripts/j2/fetch_weights_loadtest.sbatch +++ b/scripts/j2/fetch_weights_loadtest.sbatch @@ -7,7 +7,6 @@ #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 -eu CODE=/path/to/TURKIC_OCR_CODE DATA=/path/to/TURKIC_OCR_DATA diff --git a/scripts/j2/finalize.sbatch b/scripts/j2/finalize.sbatch index a12a1cfcc4d7d92c3de09d0c8b41114c9d0714a7..daa3b771ab76c8830227a7a63711462682b6b766 100644 --- a/scripts/j2/finalize.sbatch +++ b/scripts/j2/finalize.sbatch @@ -7,8 +7,6 @@ #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 -u CODE=/path/to/TURKIC_OCR_CODE DATA=/path/to/TURKIC_OCR_DATA diff --git a/scripts/j2/harness_audit.py b/scripts/j2/harness_audit.py index 5a185afd3c4b2bb1939fd13827bffa3fcb001df1..d6ffa313f630adde67c8e4822b9443ff35e4558c 100644 --- a/scripts/j2/harness_audit.py +++ b/scripts/j2/harness_audit.py @@ -1,9 +1,3 @@ -"""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 copy import json import os diff --git a/scripts/j2/harness_audit.sbatch b/scripts/j2/harness_audit.sbatch index 3efb9c7d2b4a22947c9de63acd93b71b19c5ad3d..c3b9acebff1485929a90130b4d518ec0927deb14 100644 --- a/scripts/j2/harness_audit.sbatch +++ b/scripts/j2/harness_audit.sbatch @@ -7,7 +7,6 @@ #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 -u CODE=/path/to/TURKIC_OCR_CODE DATA=/path/to/TURKIC_OCR_DATA diff --git a/scripts/j2/keyaudit.py b/scripts/j2/keyaudit.py index 9da41e772108b72749befdba67004e8b96ef54cd..33a3c6a30f55f19e514a4f6d1992b0a1ea8ce607 100644 --- a/scripts/j2/keyaudit.py +++ b/scripts/j2/keyaudit.py @@ -1,10 +1,3 @@ -"""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 model -tensor were dropped by the loader (not instantiated or ignored on load); model tensors with no matching checkpoint -tensor were created or changed by the loader (random init, fused, split or tied differently). -usage: keyaudit.py MODELS_DIR OUT_DIR short [short ...] -""" import hashlib import json import os diff --git a/scripts/j2/keyaudit.sbatch b/scripts/j2/keyaudit.sbatch index d4ee8f025582c909bc0a787273f80a9f6feedf76..b64df68d427f279f1c63f4f0c93d4dcf1029c52e 100644 --- a/scripts/j2/keyaudit.sbatch +++ b/scripts/j2/keyaudit.sbatch @@ -7,7 +7,6 @@ #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 -eu CODE=/path/to/TURKIC_OCR_CODE DATA=/path/to/TURKIC_OCR_DATA diff --git a/scripts/j2/make_control_set.py b/scripts/j2/make_control_set.py index 47efda7234ea957c959f9474955374fcee5868bf..b1732734fd334057c2b773f5d36f58ec05fbe471 100644 --- a/scripts/j2/make_control_set.py +++ b/scripts/j2/make_control_set.py @@ -1,14 +1,3 @@ -"""J2 positive control: 200 printed words (100 Kazakh + 100 Kyrgyz, Cyrillic) rendered in PT Sans (OFL 1.1), black on white, at -heights 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 are -all letters, 3 to 12 characters, every letter in the Cyrillic block, every glyph in the font; ascending sha256 of -"J2-control-v1::"; 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 hashlib import os import sys diff --git a/scripts/j2/make_control_set.sbatch b/scripts/j2/make_control_set.sbatch index 4f77cf2350796c9f9388c3e63ae03cfa6b5c7ce5..b2740b54689b8fd6eacbcb9beb06772e3dd2f927 100644 --- a/scripts/j2/make_control_set.sbatch +++ b/scripts/j2/make_control_set.sbatch @@ -7,7 +7,6 @@ #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 -eu CODE=/path/to/TURKIC_OCR_CODE DATA=/path/to/TURKIC_OCR_DATA diff --git a/scripts/j2/make_controls2_set.py b/scripts/j2/make_controls2_set.py index ca2335cda6efcdaae3802eb842e0e785b69a7d98..e3b131fb901befdba7e5908cd10381c6634bac69 100644 --- a/scripts/j2/make_controls2_set.py +++ b/scripts/j2/make_controls2_set.py @@ -1,14 +1,3 @@ -"""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 are - read 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 at - 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 - and 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.util import os import sys diff --git a/scripts/j2/make_controls2_set.sbatch b/scripts/j2/make_controls2_set.sbatch index 24fe6b0d390c377d46d90d1600b039fe861caeef..cad69cf954e162acc1d39988fae9399e9905383b 100644 --- a/scripts/j2/make_controls2_set.sbatch +++ b/scripts/j2/make_controls2_set.sbatch @@ -7,7 +7,6 @@ #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 -eu CODE=/path/to/TURKIC_OCR_CODE DATA=/path/to/TURKIC_OCR_DATA diff --git a/scripts/j2/raw_samples.py b/scripts/j2/raw_samples.py index bc590945ea82054906c165945220a5572ae64ab5..e35ba700638ac2050b2737d583817b9a7ec065a0 100644 --- a/scripts/j2/raw_samples.py +++ b/scripts/j2/raw_samples.py @@ -1,8 +1,3 @@ -"""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 hashlib import importlib.util import json diff --git a/scripts/j2/run_gpu_job.sbatch b/scripts/j2/run_gpu_job.sbatch index 99460a0fee7f15f204efcaa4a081ec16b319402a..09ed72a152422e5ccc50af820c757e6443f7fbd6 100644 --- a/scripts/j2/run_gpu_job.sbatch +++ b/scripts/j2/run_gpu_job.sbatch @@ -7,10 +7,6 @@ #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 -u CODE=/path/to/TURKIC_OCR_CODE DATA=/path/to/TURKIC_OCR_DATA diff --git a/scripts/j2/run_screen.py b/scripts/j2/run_screen.py index 73aa0b8e0635f577dc65577c2f9c5d749f7d180b..45a66f182c7907a7f4519a9c03ab407968fdea58 100644 --- a/scripts/j2/run_screen.py +++ b/scripts/j2/run_screen.py @@ -1,13 +1,3 @@ -"""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 argparse import copy import json diff --git a/scripts/j2/setup_env_vlm.sbatch b/scripts/j2/setup_env_vlm.sbatch index ed5f3601d19f3df1cf04e3a2f6843de7b6c66a32..ff431fe5843a1e8b6dc3594a635dce759b4f6d58 100644 --- a/scripts/j2/setup_env_vlm.sbatch +++ b/scripts/j2/setup_env_vlm.sbatch @@ -7,7 +7,6 @@ #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 -eu UV=$HOME/.local/bin/uv VENV=/path/to/TURKIC_OCR_CODE/.venv_vlm diff --git a/scripts/j2/smoke_cpu.sbatch b/scripts/j2/smoke_cpu.sbatch index 9c7e70e00fe4ffb1a4802ce257f2bb25e74781dd..f10c134ce380ce7709a3b9d43f328a04734c74c4 100644 --- a/scripts/j2/smoke_cpu.sbatch +++ b/scripts/j2/smoke_cpu.sbatch @@ -7,8 +7,6 @@ #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 -u CODE=/path/to/TURKIC_OCR_CODE DATA=/path/to/TURKIC_OCR_DATA diff --git a/scripts/j2/smoke_gpu.sbatch b/scripts/j2/smoke_gpu.sbatch index e31d0e4f233c5aacdb5821bc359362ee852dc72d..fba66c50b66b03222f62ad99e7a6e972d1fac95c 100644 --- a/scripts/j2/smoke_gpu.sbatch +++ b/scripts/j2/smoke_gpu.sbatch @@ -7,8 +7,6 @@ #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 -u CODE=/path/to/TURKIC_OCR_CODE DATA=/path/to/TURKIC_OCR_DATA diff --git a/scripts/j2/test_collect.py b/scripts/j2/test_collect.py index 02e3feb1ade38bfd0833a3ab467e0ea1701de7bb..07a76a0f9b1737243b0321808da392a11e1f2033 100644 --- a/scripts/j2/test_collect.py +++ b/scripts/j2/test_collect.py @@ -1,5 +1,3 @@ -"""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 json import os import subprocess diff --git a/scripts/j2/test_contrast_stretch.py b/scripts/j2/test_contrast_stretch.py index 926d1918f74862cf5b51615e5785198e620bd1b7..b1e51b087daf64c5a5a9420bc580cbfc9d50ab69 100644 --- a/scripts/j2/test_contrast_stretch.py +++ b/scripts/j2/test_contrast_stretch.py @@ -1,4 +1,3 @@ -"""Unit test of contrast_stretch. usage: test_contrast_stretch.py PATH_TO_contrast_stretch.py""" import importlib.util import sys diff --git a/scripts/j2/test_controls2_report.py b/scripts/j2/test_controls2_report.py index fbce9c314451801a1bdf1e07989aa5ca09782789..b054670d1724c70fb1ea0ae3545e07d987aeab7d 100644 --- a/scripts/j2/test_controls2_report.py +++ b/scripts/j2/test_controls2_report.py @@ -1,4 +1,3 @@ -"""Synthetic test of controls2_report.py. usage: test_controls2_report.py SCRIPTS_DIR WORK_DIR""" import json import os import subprocess diff --git a/scripts/kohtd_leak_scan.py b/scripts/kohtd_leak_scan.py index 1867b0550ea8fcf2bba46f237212ba00ad9f7aa8..0d3392f917c25e09485e735d4f4e206fb28dad39 100644 --- a/scripts/kohtd_leak_scan.py +++ b/scripts/kohtd_leak_scan.py @@ -200,7 +200,7 @@ def main(): res["membership_rebuilt_from_file_names"] = counts print("counts", counts, flush=True) - # ---- features for all crops (cached) ---- + # features for all crops (cached) cache = os.path.join(OUT, "features.npz") if os.path.exists(cache): z = np.load(cache, allow_pickle=True) @@ -226,7 +226,7 @@ def main(): 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))} AR = (W / np.maximum(H, 1)).astype(np.float32) - # ---- exact duplicates ---- + # exact duplicates def dup_report(key, label): by = collections.defaultdict(list) for i in range(len(NAMES)): @@ -249,7 +249,7 @@ def main(): res["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 ---- + # 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] @@ -259,7 +259,7 @@ def main(): Ddh, 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 ---- + # 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)} @@ -311,9 +311,9 @@ def main(): "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 ---- + # 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) ---- + # 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)) @@ -332,7 +332,7 @@ def main(): 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))} 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 ---- + # NCC second check on the closest pairs from multiprocessing import Pool best_seg = np.where(bdS[:, 0] <= bdS[:, 1], 0, 1) real_idx = np.where(best_seg == 0, biS[:, 0], biS[:, 1]) # DB index @@ -359,7 +359,7 @@ def main(): 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()), "in_validation": int((best_seg[conf_q] == 0).sum()), "in_test": int((best_seg[conf_q] == 1).sum())} - # ---- vote per scan name ---- + # 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) @@ -422,7 +422,7 @@ def main(): 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]], "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 ---- + # 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, ImageFont @@ -459,7 +459,7 @@ def main(): panel.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 ---- + # 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": []}) diff --git a/scripts/kohtd_leak_scan.sbatch b/scripts/kohtd_leak_scan.sbatch index 05037e9d6ecd93c01af9562b5d23fbfbcfbb7e09..dbec06f74681a66b69c402fdb32bdaf4378281a1 100644 --- a/scripts/kohtd_leak_scan.sbatch +++ b/scripts/kohtd_leak_scan.sbatch @@ -7,7 +7,6 @@ #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_CODE D=/path/to/TURKIC_OCR_DATA echo "== start $(date) job $SLURM_JOB_ID" diff --git a/scripts/r5/r5_after_gen.sbatch b/scripts/r5/r5_after_gen.sbatch index 539c31b05fefe33126e5faa12223010b76883048..2584d5a6dfff5e8a5e54806e1b1538a793f2a025 100644 --- a/scripts/r5/r5_after_gen.sbatch +++ b/scripts/r5/r5_after_gen.sbatch @@ -7,9 +7,6 @@ #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/python S=/path/to/TURKIC_OCR_CODE/scripts/r5 $PY -I $S/r5_build_real.py hash_synth dedupe_all --force diff --git a/scripts/r5/r5_build_A.sbatch b/scripts/r5/r5_build_A.sbatch index a868adc7b70ae217f24e7486ed74d0b3ce0a8d1b..00cf47037ce244b2dc1f1c31ceb85aa72ac45857 100644 --- a/scripts/r5/r5_build_A.sbatch +++ b/scripts/r5/r5_build_A.sbatch @@ -7,7 +7,6 @@ #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/python S=/path/to/TURKIC_OCR_CODE/scripts/r5/r5_build_real.py $PY -I $S kohtd --force diff --git a/scripts/r5/r5_build_B.sbatch b/scripts/r5/r5_build_B.sbatch index 832d7a78fdfe53a898f597a20f4e5d9439d51064..57ff139b6fc7abff48eb02d4a6dc4191788e80f2 100644 --- a/scripts/r5/r5_build_B.sbatch +++ b/scripts/r5/r5_build_B.sbatch @@ -7,7 +7,6 @@ #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/python S=/path/to/TURKIC_OCR_CODE/scripts/r5/r5_build_real.py $PY -I $S school diff --git a/scripts/r5/r5_build_C.sbatch b/scripts/r5/r5_build_C.sbatch index 214c2671604e87d449e9ebc068afedbae4261a39..8f0c0d83ef939b7ffda1aeadba5aa8f3e0a1b7a5 100644 --- a/scripts/r5/r5_build_C.sbatch +++ b/scripts/r5/r5_build_C.sbatch @@ -7,7 +7,6 @@ #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/python S=/path/to/TURKIC_OCR_CODE/scripts/r5/r5_build_real.py $PY -I $S hash dedupe diff --git a/scripts/r5/r5_build_real.py b/scripts/r5/r5_build_real.py index 0da1b5f6117e68a7011ea0412a2f2329d00c2f43..c8e4940b3f9016f72f45a12163a2d75a99367d9e 100644 --- a/scripts/r5/r5_build_real.py +++ b/scripts/r5/r5_build_real.py @@ -1,17 +1,3 @@ -"""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 manifest - chd Cyrillic Handwriting Dataset (CHD): extract png; official train / test; validation carved from train by word type - school school_notebooks_ru: word crops from pupil_text polygons, page split kept - rukopys RUKOPYS test: handwritten, legible, Ukrainian line crops from the boxes (test only) - hash sha256 + perceptual hash (64-bit pHash) of every image in every manifest - dedupe drop train images that are byte-identical or near-identical (pHash distance <= 4) to a val or test image of any source - -Raw 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 argparse import collections import csv @@ -102,7 +88,7 @@ def row(id_, image, text, lang, script, kind, source, split, group, unit): source=source, split=split, group=group, unit=unit) -# ----------------------------------------------------------------------------- KOHTD +# KOHTD def read_k1(path): out = [] with open(path, encoding="utf-8", newline="") as f: @@ -198,7 +184,7 @@ def stage_kohtd(): print(json.dumps(info, ensure_ascii=False)[:2000]) -# ----------------------------------------------------------------------------- HKR +# HKR HKR_PREFIX = "HKR_Dataset_Words_Public/20200923_Dataset_Words_Public/" @@ -256,7 +242,7 @@ def stage_hkr(): print(json.dumps(info, ensure_ascii=False)[:2000]) -# ----------------------------------------------------------------------------- CHD +# CHD def stage_chd(): info = {"stage": "chd"} z = zipfile.ZipFile(RAW / "chd/archive.zip") @@ -310,7 +296,7 @@ def stage_chd(): print(json.dumps(info, ensure_ascii=False)[:2000]) -# ----------------------------------------------------------------------------- school notebooks +# school notebooks def poly_pts(seg): flat = seg[0] if seg and isinstance(seg[0], list) else seg pts = np.array(flat, dtype=np.float32).reshape(-1, 2) @@ -447,7 +433,7 @@ def stage_school(): print(json.dumps(info, ensure_ascii=False, default=str)[:2000]) -# ----------------------------------------------------------------------------- RUKOPYS test +# RUKOPYS test def stage_rukopys(): info = {"stage": "rukopys"} base = RAW / "rukopys_test/test" @@ -493,7 +479,7 @@ def stage_rukopys(): print(json.dumps(info, ensure_ascii=False)[:2000]) -# ----------------------------------------------------------------------------- hashing +# hashing def phash64(gray): small = cv2.resize(gray, (32, 32), interpolation=cv2.INTER_AREA).astype(np.float32) dct = cv2.dct(small) @@ -545,7 +531,7 @@ def stage_hash(): print(info) -# ----------------------------------------------------------------------------- dedupe +# dedupe def stage_dedupe(): info = {"stage": "dedupe"} hashes = {} @@ -708,7 +694,7 @@ def stage_dedupe(): -# ----------------------------------------------------------------------------- synthetic manifests of GEN: hash and report-only duplicate check +# synthetic manifests: hash and report-only duplicate check def 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")) diff --git a/scripts/r5/r5_disk_counts.py b/scripts/r5/r5_disk_counts.py index 449c11ac794f6ba7e8a298c8833135d33ae1813a..8b3ee625a5535f8d97a88e546f6006c9f421ec3b 100644 --- a/scripts/r5/r5_disk_counts.py +++ b/scripts/r5/r5_disk_counts.py @@ -1,7 +1,3 @@ -"""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 collections import json import os diff --git a/scripts/r5/r5_fetch_az_htr.py b/scripts/r5/r5_fetch_az_htr.py index e24f7bbfd766c4c8883f0f0d235b70085324af99..1896aadcb529e3d736d816e1a61cff67ba99260c 100644 --- a/scripts/r5/r5_fetch_az_htr.py +++ b/scripts/r5/r5_fetch_az_htr.py @@ -1,8 +1,3 @@ -"""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 hashlib import io import json diff --git a/scripts/r5/r5_finalize.sbatch b/scripts/r5/r5_finalize.sbatch index 7a867cce97fa31b0210beae4c4f13a27cb479149..a3d368b1dc5709ed97fa83a075cadeea4086e72f 100644 --- a/scripts/r5/r5_finalize.sbatch +++ b/scripts/r5/r5_finalize.sbatch @@ -7,7 +7,6 @@ #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/python S=/path/to/TURKIC_OCR_CODE/scripts/r5 $PY -I $S/r5_validate_manifests.py diff --git a/scripts/r5/r5_kohtd_check.py b/scripts/r5/r5_kohtd_check.py index 75e83759efa64e1c1c9405cc2b28d2be72920388..5d4cbad1d1a99cab6a60f5037ce7ac0e2d07616a 100644 --- a/scripts/r5/r5_kohtd_check.py +++ b/scripts/r5/r5_kohtd_check.py @@ -1,4 +1,3 @@ -"""R5 DATA: what does cleaning change in KOHTD labels, and what is the form_id of scan-named crops.""" import collections import unicodedata from pathlib import Path diff --git a/scripts/r5/r5_p2_slice.py b/scripts/r5/r5_p2_slice.py index 7464a8edefe1575a07134a007f128c863fc8d4b8..95f0dbe98cdba6e688fa5f9a7c9d6b632f6e7512 100644 --- a/scripts/r5/r5_p2_slice.py +++ b/scripts/r5/r5_p2_slice.py @@ -1,14 +1,3 @@ -"""R5 DATA: the unseen-word slice P2 (and P2b) of the KOHTD test, by version 3 section 1. - -P2 = KOHTD test crops whose normalised label does not occur among the normalised labels of any handwriting training crop - (real handwriting train manifests plus hand_synth train manifests when they exist). -P2b = P2 crops whose normalised label also equals no whitespace token of any training label of any kind - (typed_synth, hand_synth, clutter excluded because empty). Reported only. -Normalisation: NFC, lower case, keep only letters and digits (Unicode categories L* and N*). -A test crop whose normalised label is empty (for example "-" or ".") belongs to neither slice. -Reads only label text and manifests; opens no image. Writes kohtd_test_p2.tsv, kohtd_test_p2b.tsv and p2_slice_info.json. -Run again when GEN's synthetic train manifests are frozen. Usage: python -I r5_p2_slice.py -""" import json import time import unicodedata diff --git a/scripts/r5/r5_registry.py b/scripts/r5/r5_registry.py index 75ddc6e2314342077afcd5e66dcbbe7968e91754..bdb4671e4b4359dbd83d31e17b6bc77d16cba7a8 100644 --- a/scripts/r5/r5_registry.py +++ b/scripts/r5/r5_registry.py @@ -1,7 +1,3 @@ -"""R5 DATA: manifest statistics, the evaluation registry (evalsets.json) and the effective mix_v1 shares. -Reads only the manifests (text columns); opens no image. Run on a cluster compute node after dedupe (and again when GEN's manifests appear). -Writes DATA/data/processed/r5/manifest_stats.json, DATA/data/processed/r5/evalsets.json, DATA/outputs/r5/mix_v1_shares.json. -""" import collections import hashlib import json @@ -47,7 +43,7 @@ def stats(p): mstats = {} for p in sorted(MAN.glob("*.tsv")): - if p.name.endswith(".meta.tsv"): # FREEZE 21 Nov: GEN's per-row sidecars are not manifests (extra columns) + if p.name.endswith(".meta.tsv"): # the generator's per-row sidecars are not manifests (extra columns) continue mstats[p.stem] = stats(p) json.dump({"generated_utc": NOW, "manifests": mstats}, open(R5 / "manifest_stats.json", "w", encoding="utf-8"), ensure_ascii=False, indent=1) diff --git a/scripts/r5/r5_val_subsets.py b/scripts/r5/r5_val_subsets.py index 87e5fd1627b48fef31d13e1dbc2998a3a510eb16..2c407baf595ce059c39a151424fbdd751c433489 100644 --- a/scripts/r5/r5_val_subsets.py +++ b/scripts/r5/r5_val_subsets.py @@ -1,8 +1,3 @@ -"""R5 DATA (optional helper): fixed 2,000-row random subsets of the three large Russian validation manifests (hkr_val, chd_val, school_val), -so that a validation pass over many checkpoints stays cheap. The full validation manifests stay as they are. -Draw: numpy.random.default_rng(20261121).choice(n, 2000, replace=False), rows kept in manifest order. Opens no image. -Usage: python -I r5_val_subsets.py -""" import numpy as np from pathlib import Path diff --git a/scripts/r5/r5_validate_manifests.py b/scripts/r5/r5_validate_manifests.py index 6a7ec40b4311621ff969cdf507cdd87f1e67a5bc..3be8d8fcf077a98235544dd19f5ecb3bfa603d28 100644 --- a/scripts/r5/r5_validate_manifests.py +++ b/scripts/r5/r5_validate_manifests.py @@ -1,8 +1,3 @@ -"""R5 DATA: check every manifest in DATA/data/processed/r5/manifests against the shared format. -Checks: header; allowed values of lang, script, kind, split, unit; text is NFC and has no tab or line break; ids unique across all manifests of the folder -(except the named subsets V1 and lmtune, which repeat validation ids on purpose); image path is absolute and exists; train/val/test value agrees with the file name. -Writes DATA/outputs/r5/manifest_validation.json. Usage: python -I r5_validate_manifests.py [manifest names to check only; then the output file is manifest_validation_partial.json] -""" import collections import json import os diff --git a/scripts/r5_curve_set.sbatch b/scripts/r5_curve_set.sbatch index 0b5bd0c1f890337c471fed8d58ca4a529e2a95d2..c899fc52dd3ac2e9c42113b1d17178aee3a6fe65 100644 --- a/scripts/r5_curve_set.sbatch +++ b/scripts/r5_curve_set.sbatch @@ -7,7 +7,5 @@ #SBATCH --mem=8G #SBATCH --time=00:20:00 #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out -# R5 EVALCODE: (re)builds the fixed learning-curve set curve_v1 from the validation manifests that exist and registers it in evalsets.json. -# Re-run when GEN's or PRINT's validation manifests appear; use "--register-only" after DATA's r5_registry.py rewrote evalsets.json. C=/path/to/TURKIC_OCR_CODE $C/.venv_kraken/bin/python -I $C/scripts/r5eval/build_curve_set.py "$@" diff --git a/scripts/r5_erran/erran_analysis.py b/scripts/r5_erran/erran_analysis.py index d0af4fe68e9454e8982af1c2b0355230917a811a..2e6d3267ad54b65bfcb63bbf5636c47b6d9e1bf5 100644 --- a/scripts/r5_erran/erran_analysis.py +++ b/scripts/r5_erran/erran_analysis.py @@ -1,19 +1,3 @@ -"""ERRAN (R5): descriptive error analysis of every arm on VALIDATION data only. - -Tasks (ERRAN plan): - 1 error taxonomy on V1 (KOHTD validation screen set) and on hkr/chd/school _val_s2000, with form-bootstrap intervals, - top-20 confusion pairs and per-letter error rates of the Kazakh special letters; - 3 overlap of error-crop sets between arms (Jaccard) and the crops every arm gets wrong; - 4 attribute breakdown on synth_hand_val, synth_typed_val, print_real_val and synth_clutter_val from the generator side files; - 6 learning curves on curve_v1 (25/50/75/100% of P_short). -Scoring conventions are those of the frozen R5 scorer (CODE/src/r5eval): reference = manifest text joined on id after N0, -output = N0 of the TSV hyp, alignment = r5eval.align.align_ops (J2 tie-break), bootstrap = r5eval.stats weights (seed 20261121, -B = 10,000, clusters = the manifest 'group' column: forms for KOHTD, form instances for HKR, pages, source documents). -Locked (test) sets are never opened: every manifest path is taken from a registry entry whose split is 'val' and locked is false. - -Private outputs (reference and output strings of real persons' handwriting) are written only under OUT/private/ on the cluster. -The public JSON files contain counts, rates and single characters only. -""" import argparse import collections import json @@ -242,7 +226,7 @@ def classify_crop(ref, hyp, row_script): return res -# ------------------------------------------------------------------------------------------------ bootstrap helpers +# bootstrap helpers class Boot: """Cluster bootstrap over a fixed sorted cluster list (the scorer's S01: multinomial cluster counts, ratio of sums).""" @@ -307,7 +291,7 @@ def rate(num, den, lo=None, hi=None, n_rows=None): return out -# ------------------------------------------------------------------------------------------------ loading +# loading def arm_list(): arms = [(a, "short", a) for a in VLM_ARMS] + [(a, ck, "%s %s" % (a, ck)) for a, ck in LINE_ARMS] return arms @@ -353,7 +337,7 @@ def score_file_counts(arm, ck, set_name): return {"path": p, "error": repr(e)} -# ------------------------------------------------------------------------------------------------ task 1 (+ data for 3 and 2) +# task 1 (+ data for 3 and 2) def taxonomy_one(rows, arm_label, set_name, sc_counts, priv): scored = [r for r in rows if r["ref"] != ""] boot = Boot([r["group"] for r in scored]) @@ -565,7 +549,7 @@ def repaired_view(scored): "note": "references repaired with the frozen look-alike table (r5eval.lookalike.repair_label); outputs unchanged; no interval"} -# ------------------------------------------------------------------------------------------------ task 3 +# task 3 def overlap(err_sets, all_ids, arms): out = {"arms": arms, "n_crops": len(all_ids), "pairs": []} for a_i in range(len(arms)): @@ -590,7 +574,7 @@ def overlap(err_sets, all_ids, arms): return out, allw -# ------------------------------------------------------------------------------------------------ task 4 +# task 4 def attr_rows(rows, side): """Attach side-file attributes and the length bucket.""" for r in rows: @@ -797,7 +781,7 @@ def stratified_contrasts(rows, dist, refl, bt): return out -# ------------------------------------------------------------------------------------------------ task 6 +# task 6 def curves(reg): entry = reg.get("curve_v1") man = read_manifest(entry["manifest"]) @@ -904,7 +888,7 @@ def curves(reg): return out -# ------------------------------------------------------------------------------------------------ main +# main def main(): ap = argparse.ArgumentParser() ap.add_argument("--out", required=True) diff --git a/scripts/r5_erran/erran_inventory.py b/scripts/r5_erran/erran_inventory.py index 7157837cd4b8da0a1ff4ef883347baa028750bb6..1ff46bb6012e53b476b525fb6abfa1b934e42741 100644 --- a/scripts/r5_erran/erran_inventory.py +++ b/scripts/r5_erran/erran_inventory.py @@ -1,5 +1,3 @@ -"""ERRAN (R5) inventory: which prediction files exist, row counts, registry entries of the validation sets used, and the -distinct values of the generator side-file columns. Validation sets only; locked (test) entries are listed by name only and never opened.""" import collections import json import os diff --git a/scripts/r5_erran/erran_sample.py b/scripts/r5_erran/erran_sample.py index 62b14409ba175076eae54c617647e6ceb2b8bdeb..f2a020a06f67001b355d9adfacf66318565b621b 100644 --- a/scripts/r5_erran/erran_sample.py +++ b/scripts/r5_erran/erran_sample.py @@ -1,13 +1,3 @@ -"""ERRAN (R5) task 2: draw the V1 error crops to view, and build contact sheets for viewing. - -Design (fixed before viewing, ERRAN plan task 2): - - one random order of all V1 crop ids: numpy default_rng(20261122).permutation(sorted ids); - - for each of the four arms (hunyuanocr, minicpm_ocr_1_0, paddleocr_vl_1_6, A1 long_lm_gated) the first 120 of ITS error crops - in that order: a uniform random sample of that arm's error crops (the shared order only makes the samples overlap); - - a separate stratum: the crops every arm of the task-1 list gets wrong (all of them if at most 80, else the first 80 in the order). -Contact sheets show the crop images with a running number only (no text drawn); the references and outputs go to a separate index -file. Everything is written under OUT/private/ on the cluster (real students' handwriting: never copied into page files). -""" import argparse import json import os diff --git a/scripts/r5_erran/erran_visual.py b/scripts/r5_erran/erran_visual.py index d3922ae7fd5f740b31a20bcff1474b53a4345fc5..a5e96fcfa21d67a9b4bdd94d596d641f67356f56 100644 --- a/scripts/r5_erran/erran_visual.py +++ b/scripts/r5_erran/erran_visual.py @@ -1,10 +1,3 @@ -"""ERRAN (R5) task 2: shares of the visual causes per arm, with Wilson 95% intervals, from the viewer's judgements. - -Input (cluster only, OUT/private/): sheets/index.jsonl (crop number -> id, which arm samples hold it, stratum flag) and -visual_judgements.tsv with columns n, cause, overrides (arm=cause;...), written by the viewer after looking at each crop next to -its reference and the outputs. One primary cause per (crop, arm): the crop's cause unless an override names the arm. -Output: OUT/visual_causes_counts.json with counts and shares only (no ids, no text). -""" import argparse import collections import json diff --git a/scripts/r5_erran/r5_erran.sbatch b/scripts/r5_erran/r5_erran.sbatch index e40ad66b1f7b60be46f0573780b8021c81b9bb48..982aba6ab7bf0e760b6171f067f17db7744101c1 100644 --- a/scripts/r5_erran/r5_erran.sbatch +++ b/scripts/r5_erran/r5_erran.sbatch @@ -7,8 +7,6 @@ #SBATCH --mem=32G #SBATCH --time=02:00:00 #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out -# R5 ERRAN: descriptive error analysis on validation data only. Arguments pass through to erran_analysis.py -# (for example: --out DATA/outputs/r5/erran --tasks 1,3,4,6 [--limit-arms hunyuanocr]). C=/path/to/TURKIC_OCR_CODE export OMP_NUM_THREADS=16 export OPENBLAS_NUM_THREADS=16 diff --git a/scripts/r5_erran/r5_erran_py.sbatch b/scripts/r5_erran/r5_erran_py.sbatch index f1f4916a1c8e398d0eb25a43a3b87bcfade9ed78..8db208c0576c81e25df0a93bae1029f4ffedc68e 100644 --- a/scripts/r5_erran/r5_erran_py.sbatch +++ b/scripts/r5_erran/r5_erran_py.sbatch @@ -7,8 +7,6 @@ #SBATCH --mem=16G #SBATCH --time=00:30:00 #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out -# R5 ERRAN: run one ERRAN script from CODE/scripts/r5_erran with its arguments, e.g. -# sbatch r5_erran_py.sbatch erran_sample.py --out DATA/outputs/r5/erran C=/path/to/TURKIC_OCR_CODE S=$1 shift diff --git a/scripts/r5_freeze/build_seq2.sbatch b/scripts/r5_freeze/build_seq2.sbatch index 5d6b7e266861db64dccfa6b146ac11f74f0b7724..edb4b7b164da8fd09a546851df154dc2ce175fc4 100644 --- a/scripts/r5_freeze/build_seq2.sbatch +++ b/scripts/r5_freeze/build_seq2.sbatch @@ -7,9 +7,6 @@ #SBATCH --mem=32G #SBATCH --time=01:30:00 #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out -# R5 stage FREEZE, part B step 5: the seed-2 sample sequence for the leader runs (amendment 3.3 D2), built with VLMA's own builder -# from the frozen mix_v1.yaml, data-order seed 20261122, 6,000,000 rows (the builder's default), beside seed 1's sequence. -# leader_runner.py (ensure_seq) uses it as is when .done exists. set -u unset HF_TOKEN HUGGING_FACE_HUB_TOKEN C=/path/to/TURKIC_OCR_CODE diff --git a/scripts/r5_freeze/check_curve.py b/scripts/r5_freeze/check_curve.py index a3b7ca6f29ba39349f564949ca4d9e2b387292de..e6a0d2bab9b445cceaa242ba6951a39ff5dec06c 100644 --- a/scripts/r5_freeze/check_curve.py +++ b/scripts/r5_freeze/check_curve.py @@ -1,8 +1,3 @@ -"""R5 FREEZE: after r5_freeze_curve.sh, check that every part of curve_v1 was drawn from the expected version of its source manifest -(GEN production_done.json stage 1 for the synthetic val sets, PRINT's sha256 for print_real_val, the registry for kohtd_lmtune), that no -part is missing, and that the registry entry matches the frozen file. -usage: python -I check_curve.py CURVE_INFO_JSON CURVE_FROZEN_JSON PRODUCTION_DONE_JSON EVALSETS_JSON OUT_JSON -""" import json import sys diff --git a/scripts/r5_freeze/compare_parsers.py b/scripts/r5_freeze/compare_parsers.py index de67aed07b9114f71c2506a651af2d85f5c67d84..21d072e893916386db69ef9d059d954e01ebb467 100644 --- a/scripts/r5_freeze/compare_parsers.py +++ b/scripts/r5_freeze/compare_parsers.py @@ -1,15 +1,3 @@ -"""R5 FREEZE: do all consumers of mix_v1.yaml read the same leaves and shares? (audit part 1, CAN'T TELL item on the two parsers) - -Reads the yaml with the consumers' OWN code (imported, not copied): - - LINEDET: linedet.data.load_mix (CODE/src/linedet/data.py), also used by make_codec, train_arm and lm_prep; - - REF: load_mix of CODE/scripts/r5_ref/ref_make_mix_lists.py (its stated verbatim copy of LINEDET's); - - EVALCODE: r5eval.ktrain.read_mix_leaves (leaves and filters only; K_train uses no shares); - - VLMA: build_sequence.py's per-stratum target_share, taken from the summary JSON that build_sequence.py wrote for this yaml - (its walk is module-level code, so it is run, not imported; the summary's mix_yaml_sha256 must equal the yaml's sha256); - - the generator's own exact shares (gen report JSON). -A leaf is identified by (manifest path, lang filter). PASS when every reader has the same leaf set and every share agrees within 1e-9. -usage: python -I compare_parsers.py YAML VLMA_SUMMARY_JSON GEN_REPORT_JSON OUT_JSON -""" import hashlib import json import sys diff --git a/scripts/r5_freeze/dedupe_verdict.py b/scripts/r5_freeze/dedupe_verdict.py index c3904b7767d9cd9cb0d45bf537524dfd7d7cddae..3524b0d256f6fa6887daa898c70397c96c5be338 100644 --- a/scripts/r5_freeze/dedupe_verdict.py +++ b/scripts/r5_freeze/dedupe_verdict.py @@ -1,16 +1,3 @@ -"""R5 FREEZE: reads DATA's report-only duplicate check (build_logs/dedupe_all.json + dedupe_all_dropped.tsv) and applies the -freeze rule written in records/R5/FREEZE/status.json BEFORE the report existed: - - pairs where the train side is kohtd_rand_train or the partner is kohtd_rand_val / kohtd_rand_test are the deliberate - replication overlap (amendment 3.3 D5 (ii), clarification H1): left out, counted; - - any pair whose partner is kohtd_test: STOP (H1 guarantee and the form split); - - any other byte-identical pair: STOP; - - near-pHash pairs with the same non-empty label: STOP for manual review; - - near-pHash pairs with different labels or empty (clutter) labels: reported, not a stop. -Also counts, per manifest, how many row ids have an image hash in hashes.tsv / hashes_synth.tsv (rows without a hash are silently -skipped by dedupe_all: they are 'not checked', not 'clean'). Reads ids only from the manifests (no text of test rows, no image). -Also checks whether kohtd_rand_train / kohtd_rand_val ids are KOHTD ids (overlap with kohtd_train / kohtd_val ids). -usage: python -I dedupe_verdict.py OUT_JSON -""" import collections import csv import json diff --git a/scripts/r5_freeze/drop_rows.py b/scripts/r5_freeze/drop_rows.py index dfc8375d1aec7afbcb46c1c00a20e1c68fa30a3f..040a2174c1c7b364bec6aff4db88590cc1ae386b 100644 --- a/scripts/r5_freeze/drop_rows.py +++ b/scripts/r5_freeze/drop_rows.py @@ -1,15 +1,3 @@ -"""R5 FREEZE: decision of 21 Nov 2026 ~02:05 UTC (option B extended). From the FROZEN synthetic train copies only, drop - (a) near_dup_same_label: the synthetic train rows that DATA's duplicate check (build_logs/dedupe_all_dropped.tsv, run 01:58:30 UTC) - pairs with a synthetic val/test row by near pHash (distance <= 4) AND the same non-empty label; - (b) text_leak_ge20: every synthetic train row whose label equals the label of a synthetic val/test LINE of at least 20 characters - (same definition as AUDIT's data_audit.py lines 278-286: unit == line, len(text) >= 20, whitespace collapsed). -Val/test labels are read from the read-only copies in frozen_eval_v1/ and are never printed or written; outputs hold ids only. -Non-synthetic train rows that match (b) are counted and listed (ids), not dropped (the decision covers synthetic rows only). -Writes into OUT_DIR: synth_hand_train.tsv, synth_typed_train.tsv and their .meta.tsv sidecars without the dropped rows (raw lines -copied byte for byte), dropped_rows.tsv (id, manifest, reason, matched_valtest_id, matched_valtest_manifest, detail), drop_report.json. -usage: python -I drop_rows.py FROZEN_TRAIN_DIR FROZEN_EVAL_DIR DEDUPE_DROPPED_TSV OUT_DIR PREDROP_DIR -(the two synthetic train manifests and their sidecars are read from PREDROP_DIR, the copies made before any drop) -""" import collections import csv import hashlib diff --git a/scripts/r5_freeze/freeze_drop.sbatch b/scripts/r5_freeze/freeze_drop.sbatch index 7c216a1ef869fddc2bffd6395e6b415cfcd99774..9a7400c19b1d696725fb5e5924c57732c345d081 100644 --- a/scripts/r5_freeze/freeze_drop.sbatch +++ b/scripts/r5_freeze/freeze_drop.sbatch @@ -7,14 +7,6 @@ #SBATCH --mem=32G #SBATCH --time=01:00:00 #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out -# R5 stage FREEZE, decision of 21 Nov ~02:05 UTC (option B extended). Never creates mix_v1.yaml. Steps: -# 1 keep the pre-drop synthetic train copies (outputs/r5/freeze/predrop/, read-only); drop_rows.py -> filtered copies + dropped_rows.tsv -# 2 replace synth_hand_train / synth_typed_train (+ .meta.tsv) in frozen_mix_v1 (atomic mv), read-only again, new sha256 list -# 3 gen_mix_v1.py --dropped -> mix_v1.yaml.tmp (frozen = pre-drop minus exactly the listed ids; pre-drop = production_done) -# 4 repoint_evalsets.py: synth_*_val/test registry entries -> read-only copies in frozen_eval_v1/ -# 5 AUDIT's data audit (reads manifests/): only if no GEN finalize job runs or may begin within 5 minutes (it takes ~80 s and -# GEN's finalize reads its parts for ~4 minutes before it writes); otherwise skipped and noted -# 6 VLMA check_mix, LINEDET make_codec, parser comparison on the tmp yaml set -u unset HF_TOKEN HUGGING_FACE_HUB_TOKEN C=/path/to/TURKIC_OCR_CODE diff --git a/scripts/r5_freeze/freeze_post.sbatch b/scripts/r5_freeze/freeze_post.sbatch index 7c37ceaf11ca37dcfe8627827698af427d38b25f..37583e0c6407fb7da9895b71a2e291a2e438f86c 100644 --- a/scripts/r5_freeze/freeze_post.sbatch +++ b/scripts/r5_freeze/freeze_post.sbatch @@ -7,14 +7,6 @@ #SBATCH --mem=32G #SBATCH --time=01:30:00 #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out -# R5 stage FREEZE, job 2 of 2. Every step reads manifests/, which GEN finalize jobs 51065/51066 rewrite in place: the guard -# below stops the job (exit 4) if one of them runs or may begin within 20 minutes; then resubmit with -# --dependency=afterany:51065:51066. Steps: -# 6 DATA's r5_after_gen.sbatch, run with bash inside this job (hash GEN images, report-only dedupe of all manifests, validate, -# P2 slice, registry) -# 6b dedupe_verdict.py: the freeze rule on the dedupe report + per-manifest hash coverage -# 7 merge_evalsets.py: put back the sets r5_registry.py drops (PRINT's 3, REF's kohtd_rand_test, curve_v1 if present) -# 8 AUDIT's data_audit.sbatch, run with bash inside this job (stat() of every image path of every manifest; no image opened) set -u unset HF_TOKEN HUGGING_FACE_HUB_TOKEN C=/path/to/TURKIC_OCR_CODE @@ -26,7 +18,7 @@ PYD=$C/.venv/bin/python mkdir -p $W echo "start $(date -u +%FT%TZ) on $(hostname), job $SLURM_JOB_ID, cpus $SLURM_CPUS_PER_TASK" echo "GEN finalize jobs running now: [$(squeue -h -u $USER -n r5_gen_final -t R -o %i)]" -# guard: GEN finalize jobs 51065/51066 rewrite manifests/synth_* in place. Stop (exit 4) if one runs now or may begin within +# guard: the generator's finalize jobs rewrite manifests/synth_* in place. Stop (exit 4) if one runs now or may begin within # 20 minutes (its begin time is read from squeue in cluster local time and compared with the node clock). No waiting. guard() { NOWS=$(date +%s) diff --git a/scripts/r5_freeze/freeze_post2.sbatch b/scripts/r5_freeze/freeze_post2.sbatch index 39230587b6eb64e16f394b6c5ada81ce4a790e30..47d72a9922375da072217fa44311edb3d00db0d0 100644 --- a/scripts/r5_freeze/freeze_post2.sbatch +++ b/scripts/r5_freeze/freeze_post2.sbatch @@ -7,9 +7,6 @@ #SBATCH --mem=32G #SBATCH --time=01:00:00 #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out -# R5 stage FREEZE: rerun of the two DATA steps that failed in job 51293 on GEN's .meta.tsv sidecars (fixed: they are skipped now, -# diff records/R5/FREEZE/data_scripts_meta_fix.diff): the report-only duplicate check over all manifests (dedupe_all, using the -# hashes_synth.tsv written by 51293 at 01:52:29 UTC) and the manifest validator; then dedupe_verdict.py. Same guard as freeze_post. set -u unset HF_TOKEN HUGGING_FACE_HUB_TOKEN C=/path/to/TURKIC_OCR_CODE diff --git a/scripts/r5_freeze/freeze_prep.sbatch b/scripts/r5_freeze/freeze_prep.sbatch index 8912ae9b38f51425eca124123de25ee3df3e9dbb..1d8e191ee0fbf621f66314503340d07189b7c492 100644 --- a/scripts/r5_freeze/freeze_prep.sbatch +++ b/scripts/r5_freeze/freeze_prep.sbatch @@ -7,16 +7,6 @@ #SBATCH --mem=32G #SBATCH --time=01:00:00 #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out -# R5 stage FREEZE, job 1 of 2 (part A plus the checks of part B step 3). It never creates mix_v1.yaml (the file that starts -# the GPU jobs). Reads manifests/ only in step 1 (the copy), and refuses to copy while a GEN finalize job (r5_gen_final) runs, -# because that job rewrites manifests/synth_* in place. Steps: -# 1 copies of the 8 train manifests + 3 GEN sidecars into DATA/data/processed/r5/frozen_mix_v1/, files chmod a-w -# 2 gen_mix_v1.py -> DATA/data/processed/r5/mix_v1.yaml.tmp (+ gen_report.json); fails closed on any sha256 or row problem; -# only then the folder itself is made read-only -# 3 VLMA's check_mix.sbatch, run with bash inside this job (build_sequence.py, 200,000 rows, every train image checked) -# 4 LINEDET's make_codec on the tmp yaml (--out DATA/tmp/codec_check/codec_union.json) -# 5 compare_parsers.py: LINEDET, REF, EVALCODE and VLMA parsers read the same leaves and shares -# Outputs in DATA/outputs/r5/freeze/. set -u unset HF_TOKEN HUGGING_FACE_HUB_TOKEN C=/path/to/TURKIC_OCR_CODE diff --git a/scripts/r5_freeze/gen_finalize_stage2.sbatch b/scripts/r5_freeze/gen_finalize_stage2.sbatch index 00ed641d53beb94cc32ca281609b8a9d860e11d6..328d1133271ade3fd9de9da2a06300e5a878c819 100644 --- a/scripts/r5_freeze/gen_finalize_stage2.sbatch +++ b/scripts/r5_freeze/gen_finalize_stage2.sbatch @@ -7,16 +7,13 @@ #SBATCH --mem=24G #SBATCH --time=00:40:00 #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out -# R5 GEN: merge the production parts into the manifests and write counts, realised statistics and production_done.json. -# usage: sbatch [--dependency=...] [--begin=...] r5_finalize.sbatch PLAN_JSON STAGE -# Safe to run again at any time (reads _parts, rewrites manifests; --keep-extra: no image is deleted). Stage 2 first copies the stage 1 manifests to manifests/stage1/. CODE=/path/to/TURKIC_OCR_CODE/src/pagesynth D=/path/to/TURKIC_OCR_DATA PLAN=${1:-$D/tmp/r5_plan_stage1.json} STAGE=${2:-1} -# Stage FREEZE, 21 Nov 2026: copy of src/pagesynth/scripts/r5_finalize.sbatch with ONE change: stage 2 writes its manifests to +# Copy of src/pagesynth/scripts/r5_finalize.sbatch with ONE change: stage 2 writes its manifests to # manifests_stage2/ instead of rewriting manifests/ (the frozen mix_v1 and the registry point to the stage-1 files there). -# Stage-2 lines are extra data for the leaders only (amendment 3.3 D2). Reports keep their stage-2 names (counts_stage2.json, +# Stage-2 lines are extra data for the leaders only. Reports keep their stage-2 names (counts_stage2.json, # realised_stats_stage2.json, production_done_stage2.json), so stage-1 reports are not overwritten. M=$D/data/processed/r5/manifests_stage2 mkdir -p $D/outputs/r5/gen_reports $M diff --git a/scripts/r5_freeze/gen_mix_v1.py b/scripts/r5_freeze/gen_mix_v1.py index 9d2461148d95d7239fc7de4566065ddda47aa079..8b2aabff4ea53853d8955f78a777636019a7412e 100644 --- a/scripts/r5_freeze/gen_mix_v1.py +++ b/scripts/r5_freeze/gen_mix_v1.py @@ -1,26 +1,3 @@ -"""R5 FREEZE: writes mix_v1.yaml, the frozen training mix of round R5, from the recorded mix decision. - -Source of the shares: the project decision log key "mix_v1_decision", restated in the freeze plan, part A step 2: - hand_real kk 35; hand_real other Cyrillic 15 (HKR, CHD, school equally, at most 3 passes of a source per 1M samples); - hand_synth 35 = 30 equally over the 10 language-scripts + the 5 points of the empty hand_real Latin, split equally over - uz_latn, tr, az, tk; typed_synth 6 and typed_real 6, equal over the 10 language-scripts (a language-script without - print_real_train rows gives its typed_real part to its typed_synth); clutter 3. NOT from DATA's mix_v1_shares.json - (that file has typed_synth 12 and no typed_real; superseded). - -Every leaf points to a READ-ONLY copy in --frozen-dir (made by freeze_prep.sbatch before this script runs). The script checks: - - each frozen copy is byte-identical to its source in --source-dir and to the expected sha256 (GEN's production_done.json - for synth_*, PRINT's stated sha256 for print_real_train, DATA's manifest_stats.json for the real handwriting sets); - - each frozen copy and sidecar has no write bit; - - header = the 10 shared columns; every row has split train; every leaf has train rows after its filter; - - shares are exact fractions that sum to exactly 1; the 3-pass cap does not bind. -YAML layout (read by four parsers; see records/R5/FREEZE/schema.json): top-level key "components" (a list); a component is either -a LEAF (name, share, manifest, sha256, optional filter {lang: x}) or a GROUP (name, share, members = list of leaves with -ABSOLUTE shares that sum to the group's share). No top-level key may be one of mix, members, sources, manifests, items, -children, parts, strata, groups, entries, streams, shares, manifest, path, file, tsv. - -usage: python -I gen_mix_v1.py --frozen-dir DIR --source-dir DIR --out YAML --report JSON -Exit 0 = yaml written and re-read; any failed check: exit 2 and no yaml. -""" import argparse import csv import hashlib @@ -41,7 +18,7 @@ CYR = ["kk", "ky", "uz_cyrl", "tt", "ba", "sah"] LAT = ["uz_latn", "tr", "az", "tk"] LANGS = CYR + LAT P_SHORT = 150000 -PRINT_TRAIN_SHA = "6fe8df2acc693637009150d00947153ab3a22b32c5dc1be1332c8e52b70d1f14" # PRINT final (01:45 UTC), re-hashed 01:35 UTC +PRINT_TRAIN_SHA = "6fe8df2acc693637009150d00947153ab3a22b32c5dc1be1332c8e52b70d1f14" # final print_real_train manifest MANIFESTS = ["kohtd_train", "hkr_train", "chd_train", "school_train", "synth_hand_train", "synth_typed_train", "print_real_train", "synth_clutter_train"] SIDECARS = {"synth_hand_train": "synth_hand_train.meta.tsv", "synth_typed_train": "synth_typed_train.meta.tsv", @@ -186,7 +163,7 @@ def main(): bl = files[m]["train_rows_by_lang"] return sum(bl.values()) if lang is None else bl.get(lang, 0) - # ------------------------------------------------------------------ shares (exact fractions) + # shares as exact fractions notes = [] comps = [] comps.append({"name": "hand_real_kk", "stream": "hand_real", "share": F(35, 100), "leaf": ("kohtd_train", None), @@ -243,7 +220,7 @@ def main(): print("FAIL", *problems, sep="\n ") sys.exit(2) - # ------------------------------------------------------------------ yaml text + # yaml text def fnum(x): v = float(x) if F(repr(v)) != x: diff --git a/scripts/r5_freeze/make_endpoints.py b/scripts/r5_freeze/make_endpoints.py index 917286795e4c55d387c9516008826f574fbf9405..85adead500101d3b76e490ba4dfda1998ce2d5b3 100644 --- a/scripts/r5_freeze/make_endpoints.py +++ b/scripts/r5_freeze/make_endpoints.py @@ -1,9 +1,3 @@ -"""R5 FREEZE: endpoints.json for the scorer = EVALCODE's endpoints_proposal.json with three settings filled (freeze plan part B step 7): - T2.audited_languages = the language-scripts of PRINT's audit with at least 49 of 50 test lines matching, label 'checked by machine viewing'; - reader_only_counts_as_pipeline = true (clarification H6 of amendment 3.3); - confirmed = true. -Nothing else is changed. usage: python -I make_endpoints.py PROPOSAL_JSON PRINT_AUDIT_JSON OUT_JSON -""" import json import sys import time diff --git a/scripts/r5_freeze/merge_evalsets.py b/scripts/r5_freeze/merge_evalsets.py index 483d99f38504dffbcc0ca36fdef380bf82f5e5fc..35b73b9309161339a1828da62ff0b7aa31264753 100644 --- a/scripts/r5_freeze/merge_evalsets.py +++ b/scripts/r5_freeze/merge_evalsets.py @@ -1,13 +1,3 @@ -"""R5 FREEZE: after DATA's r5_registry.py rewrote evalsets.json from its own list, put back the sets it dropped. - -Dropped by design (r5_registry.py writes a fixed list): PRINT's print_real_val / print_real_test / more_real_print -(evalsets_extra_print.json), REF's kohtd_rand_test, and curve_v1 if it was registered. Every set that was in the registry before -the rewrite (BEFORE) and is missing now is added back unchanged, except that n_rows and manifest_sha256 are re-measured from the -manifest; a difference is logged (and the measured values are written, so the registry matches the file on disk). -PRINT's entries are taken from evalsets_extra_print.json when present there. Checks: every split=test set is locked; every set -locked BEFORE is still locked; no duplicate names. Also marks DATA's mix_v1_shares.json as superseded (key added, nothing removed). -usage: python -I merge_evalsets.py BEFORE_JSON REGISTRY_JSON EXTRA_PRINT_JSON SHARES_JSON LOG_JSON -""" import hashlib import json import os diff --git a/scripts/r5_freeze/repoint_evalsets.py b/scripts/r5_freeze/repoint_evalsets.py index 91fd93a184b43a527fc1b4a4b938b2d7a01ca6d6..e85e04462c0d3d72b2dfaeccf6feebf1f9266583 100644 --- a/scripts/r5_freeze/repoint_evalsets.py +++ b/scripts/r5_freeze/repoint_evalsets.py @@ -1,9 +1,3 @@ -"""R5 FREEZE: point the registry entries synth_{hand,typed,clutter,pages}_{val,test} at their read-only copies in frozen_eval_v1/ -(decision 4, 21 Nov 2026), so evaluation sets cannot change when GEN jobs rewrite manifests/. A path is changed only if -the copy's sha256 equals the entry's manifest_sha256; the old path is kept in 'manifest_original'. Every other entry is unchanged. -Note: DATA's r5_registry.py rewrites evalsets.json from manifests/; if it is ever run again, run this script and merge_evalsets.py again. -usage: python -I repoint_evalsets.py REGISTRY_JSON FROZEN_EVAL_DIR LOG_JSON -""" import hashlib import json import os diff --git a/scripts/r5_freeze_curve.sh b/scripts/r5_freeze_curve.sh index 46ddebc1edae0d02c6852e801c0353f11ea976ad..f2cccb28fd313c9b4ca1d80e12419a4a882d3814 100644 --- a/scripts/r5_freeze_curve.sh +++ b/scripts/r5_freeze_curve.sh @@ -1,9 +1,4 @@ #!/bin/bash -# R5 EVALCODE: the FINAL, complete build of the fixed learning-curve set curve_v1 (rule: build it once by 05:45 UTC on 21 Nov from the parts that exist, -# freeze it at the mix freeze, never rebuild it after the first run starts; a part missing now is left out for good). -# It reads three small validation manifests (about 1 second), so it is run directly, not queued behind the ZEN4 backlog. Prints the sha256 and the row counts by part. -# Writes DATA/data/processed/r5/manifests/curve_v1.tsv, curve_v1_info.json, curve_v1_frozen.json and registers curve_v1 in evalsets.json. -# After DATA's r5_registry.py rewrote evalsets.json, run: CODE/.venv_kraken/bin/python -I CODE/scripts/r5eval/build_curve_set.py --register-only C=/path/to/TURKIC_OCR_CODE D=/path/to/TURKIC_OCR_DATA $C/.venv_kraken/bin/python -I $C/scripts/r5eval/build_curve_set.py --final && cat $D/data/processed/r5/curve_v1_frozen.json diff --git a/scripts/r5_gate/gate_backup.sbatch b/scripts/r5_gate/gate_backup.sbatch index 5b467f40e747729f63f7ae3968af12983699e1ab..da2c58d3bbec3b5518e33c185e69b68b7b424f9e 100644 --- a/scripts/r5_gate/gate_backup.sbatch +++ b/scripts/r5_gate/gate_backup.sbatch @@ -8,15 +8,6 @@ #SBATCH --time=00:10:00 #SBATCH --begin=2026-11-24T17:00:05 #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out -# R5 backup writer of the test-pass gate file (clarification J10, records/R5/RULE/j12_v3_4_clarifications_3.txt). -# --begin is cluster local time (+05): 17:00:05 there is 12:00:05 UTC on 24 Nov 2026. -# eval_vlm_test.py, score.py, LINEDET and REF only check that the gate file exists, so this script checks the clock -# itself and never writes before 12:00:00 UTC, whenever Slurm happens to start it. -# Exclusive create (noclobber): a gate file already written by hand is left alone, because -# eval_vlm_test.py records the gate file's sha256 in every meta and a rewrite would break those records. -# GATE_TEST_DIR and GATE_OPEN_UTC exist only for the dry tests in DATA/tmp; the real jobs set neither. -# GATE_MAX_WAIT (seconds, default 120): the second real copy is submitted hours early without --begin and sleeps -# until 12:00:00 UTC, so that a full ZEN4 queue at noon cannot delay the gate. set -u D=${GATE_TEST_DIR:-/path/to/TURKIC_OCR_DATA/outputs/r5} OPEN=$(date -u -d "${GATE_OPEN_UTC:-2026-11-24T12:00:00Z}" +%s) || { echo "bad open time; nothing written"; exit 2; } diff --git a/scripts/r5_gate/select_dryrun.sbatch b/scripts/r5_gate/select_dryrun.sbatch index 760f91de084d31d6840bd63259516de7f9b87cbf..87f547a99199e8e897f8b32544ef5597e35e5c6c 100644 --- a/scripts/r5_gate/select_dryrun.sbatch +++ b/scripts/r5_gate/select_dryrun.sbatch @@ -7,9 +7,6 @@ #SBATCH --mem=48G #SBATCH --time=00:30:00 #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out -# Dry run of select_b1b2.py on the validation scores present now, with the same arguments as -# r5_select_verdict.sbatch select. It writes to DATA/tmp, never to DATA/outputs/r5/selection.json, which the -# test-pass runner reads. Validation only, not hashed into records/R5/RULE; it is not the J7 selection. C=/path/to/TURKIC_OCR_CODE D=/path/to/TURKIC_OCR_DATA TSV=$C/scripts/r5_vlma/models_r5.tsv,$C/scripts/r5_vlmb/models_r5_vlmb.tsv diff --git a/scripts/r5_ktrain.sbatch b/scripts/r5_ktrain.sbatch index 22ee059638c7fe5c269726b7a6ad2f7a63d47a44..ff22853d625bbe1303dd681c9689594b543ac933 100644 --- a/scripts/r5_ktrain.sbatch +++ b/scripts/r5_ktrain.sbatch @@ -7,8 +7,6 @@ #SBATCH --mem=48G #SBATCH --time=01:00:00 #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out -# R5 EVALCODE: builds and hashes K_train (clarification G3) from the train manifests of the FROZEN mix_v1.yaml and the generator's train text. -# Run once, after the freeze. Reads training text only. Output: DATA/data/processed/r5/p2/ktrain_manifest.json and three key files. C=/path/to/TURKIC_OCR_CODE D=/path/to/TURKIC_OCR_DATA $C/.venv_kraken/bin/python -I $C/scripts/r5eval/build_ktrain.py --mix $D/data/processed/r5/mix_v1.yaml --out $D/data/processed/r5/p2 diff --git a/scripts/r5_ktrain_scratch.sbatch b/scripts/r5_ktrain_scratch.sbatch index ae220957ab4a274a0570dbf5d304ebe854a3d4c6..a288ef3ffe9996dad17491ea5ab5c65fb6225563 100644 --- a/scripts/r5_ktrain_scratch.sbatch +++ b/scripts/r5_ktrain_scratch.sbatch @@ -7,8 +7,6 @@ #SBATCH --mem=48G #SBATCH --time=01:00:00 #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out -# R5 EVALCODE: time and size check of build_ktrain.py on the real TRAIN manifests (scratch mix, not mix_v1) and the generator's train text. -# Reads training text only. Output under DATA/tmp/evalcode_ktrain_scratch; then loads it back and prints sizes, time and a slice-flag example. C=/path/to/TURKIC_OCR_CODE D=/path/to/TURKIC_OCR_DATA S=$C/.venv_kraken/bin/python diff --git a/scripts/r5_linedet/blla_stage2.sh b/scripts/r5_linedet/blla_stage2.sh index 03495f1a364cf774751f03dee45b4a36a4db07ee..5c837fe82bcb5b0f50bcf7c2a7afdf7f385827b8 100644 --- a/scripts/r5_linedet/blla_stage2.sh +++ b/scripts/r5_linedet/blla_stage2.sh @@ -1,5 +1,4 @@ #!/bin/bash -# kraken BLLA stage 2: continue from the best stage-1 weights on school + generator pages. set -eu DATA=/path/to/TURKIC_OCR_DATA CK=$DATA/checkpoints/r5/linedet diff --git a/scripts/r5_linedet/curve_post.sbatch b/scripts/r5_linedet/curve_post.sbatch index 9e2ba90ec015dacf01c509e43c2e76198b27c781..0d9d06ffe566ee27b70030f48ab5abcfcbcdf144 100644 --- a/scripts/r5_linedet/curve_post.sbatch +++ b/scripts/r5_linedet/curve_post.sbatch @@ -7,7 +7,6 @@ #SBATCH --mem=32G #SBATCH --time=03:00:00 #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out -# After the GPU job: greedy scoring of every learning-curve checkpoint that has no curve_v1.tsv yet (CPU). CODE=/path/to/TURKIC_OCR_CODE unset HF_TOKEN HUGGING_FACE_HUB_TOKEN export OMP_NUM_THREADS=8 MKL_NUM_THREADS=8 diff --git a/scripts/r5_linedet/env_setup.sh b/scripts/r5_linedet/env_setup.sh index a477e31d752abf4edba5c331653eee70fcd02dcd..defbabc2c0525f1a1922de8abf6fd1aaa619ae76 100644 --- a/scripts/r5_linedet/env_setup.sh +++ b/scripts/r5_linedet/env_setup.sh @@ -1,5 +1,4 @@ #!/bin/bash -# R5 LINEDET: create the kraken + ultralytics uv environment (plain shell). Run on a compute node (CPU job). set -eu UV=$HOME/.local/bin/uv CODE=/path/to/TURKIC_OCR_CODE diff --git a/scripts/r5_linedet/ext_selftest.sh b/scripts/r5_linedet/ext_selftest.sh index 11351a8f336ac4f438454842cd26e4539709132a..d58495ce0dedf295d67a96ced04d75795ae27d70 100644 --- a/scripts/r5_linedet/ext_selftest.sh +++ b/scripts/r5_linedet/ext_selftest.sh @@ -1,5 +1,4 @@ #!/bin/bash -# Self-test of the extension mode (amendment 3.4 E5) on the KOHTD smoke data with arm A3 on CPU: (1) the sample target comes first, (2) the time budget comes first. set -u DATA=/path/to/TURKIC_OCR_DATA LD=$DATA/outputs/r5/linedet diff --git a/scripts/r5_linedet/fetch_weights.sh b/scripts/r5_linedet/fetch_weights.sh index 1b4878298e73e99b39a1aa000685c944c4f6fba2..3d5a6f73b41849e140c44766eff4fb250dc44e99 100644 --- a/scripts/r5_linedet/fetch_weights.sh +++ b/scripts/r5_linedet/fetch_weights.sh @@ -1,5 +1,4 @@ #!/bin/bash -# Download the two kraken PP-OCRv6 weight files from Zenodo (records 21788410 medium, 21788405 small), verify md5. set -eu DATA=/path/to/TURKIC_OCR_DATA unset HF_TOKEN HUGGING_FACE_HUB_TOKEN diff --git a/scripts/r5_linedet/gate_unittest.py b/scripts/r5_linedet/gate_unittest.py index c60273d4d033db83e7bf8892c8557a4a0f294d57..0bea04d0a152ce37eeeaa41d1292700e1a0942d8 100644 --- a/scripts/r5_linedet/gate_unittest.py +++ b/scripts/r5_linedet/gate_unittest.py @@ -1,4 +1,3 @@ -"""Unit test of linedet.lm_gate on a toy folder (no real prediction file): plain outputs '' , ' ', ' ', 'a', and LM outputs with text. Expect the gated output empty for the first three.""" import csv, os, sys, tempfile sys.path.insert(0, "/path/to/TURKIC_OCR_CODE/src") import importlib diff --git a/scripts/r5_linedet/gpu_driver.sbatch b/scripts/r5_linedet/gpu_driver.sbatch index f3a9a642f0d94cb101b34b6fca8912dfb1482fe8..be0c04c5680c263523a907229b8ceec060a3b7e5 100644 --- a/scripts/r5_linedet/gpu_driver.sbatch +++ b/scripts/r5_linedet/gpu_driver.sbatch @@ -7,9 +7,6 @@ #SBATCH --mem=160G #SBATCH --time=16:00:00 #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out -# Stage LINEDET, round R5: the one GPU job of slot L. A task driver runs, as separate processes: timing at batch 1, the five -# line recognizers (A1, A2, A3, A4, A1s) concurrently on mix_v1, their validation predictions, and the detectors. The task list -# (LD_OUT/tasks.json) is re-read while the job runs. Stop time is inside the file (stop_utc). CODE=/path/to/TURKIC_OCR_CODE DATA=/path/to/TURKIC_OCR_DATA unset HF_TOKEN HUGGING_FACE_HUB_TOKEN diff --git a/scripts/r5_linedet/h10_selftest.sh b/scripts/r5_linedet/h10_selftest.sh index dab72f9e809d993f8563c55bea4e418de6db9d4c..4e823ef0dcacdb309a57ce5161fac95b4b9c8dc2 100644 --- a/scripts/r5_linedet/h10_selftest.sh +++ b/scripts/r5_linedet/h10_selftest.sh @@ -1,7 +1,4 @@ #!/bin/bash -# Self-test of the test-pass code path (clarification H10) on SMOKE data only: 100 KOHTD validation crops relabelled as a fake locked "test" set, a fake gate file -# in a scratch folder. Checks: predict --test_pass and lm_decode --test_pass run without a cap, write meta_test_pass.json and leave meta.json alone, -# lm_gate gates the new set. No real test file is opened. set -u DATA=/path/to/TURKIC_OCR_DATA LD=$DATA/outputs/r5/linedet diff --git a/scripts/r5_linedet/kenlm_build.sbatch b/scripts/r5_linedet/kenlm_build.sbatch index d38ec7742ebec0322ba8beebbb53a4b51f7df40b..05b6b8fa7db8242efe73498ed7d7f7dcf1138c6f 100644 --- a/scripts/r5_linedet/kenlm_build.sbatch +++ b/scripts/r5_linedet/kenlm_build.sbatch @@ -7,7 +7,6 @@ #SBATCH --mem=16G #SBATCH --time=00:40:00 #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out -# Build lmplz and build_binary from the kenlm 0.3.0 PyPI source (sha256 pinned). No credentials in the environment. DATA=/path/to/TURKIC_OCR_DATA unset HF_TOKEN HUGGING_FACE_HUB_TOKEN export UV_CACHE_DIR=$DATA/tmp/uv_cache diff --git a/scripts/r5_linedet/lb_smoke.sh b/scripts/r5_linedet/lb_smoke.sh index ec7b4f2a9408b137e73e7e48a95d574360ec490f..77421272e2ab7a50f6a26aa60d5eca8231843648 100644 --- a/scripts/r5_linedet/lb_smoke.sh +++ b/scripts/r5_linedet/lb_smoke.sh @@ -1,6 +1,4 @@ #!/bin/bash -# Miniature of the line block on the KOHTD smoke data (own folders): seed 2 of A1 in two phases with a plan file, predictions with arm_label, -# seed voting against the seed-1 smoke run, and one H06 run with its report. Not arm results. set -u DATA=/path/to/TURKIC_OCR_DATA LD=$DATA/outputs/r5/linedet diff --git a/scripts/r5_linedet/line_block.sbatch b/scripts/r5_linedet/line_block.sbatch index f5d1b25c81d021e74a6d0662ccddd24093fa5ad1..6f07ae34ac32f829eb09720029cb0a4dd33f57da 100644 --- a/scripts/r5_linedet/line_block.sbatch +++ b/scripts/r5_linedet/line_block.sbatch @@ -7,8 +7,6 @@ #SBATCH --mem=160G #SBATCH --time=06:30:00 #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out -# Stage LINEDET, round R5, amendment 3.3: the line block (D3 second seed of A1 and A2, D6 SR1-H06) and the four reference runs of stage REF -# (clarification H2), as concurrent processes of one driver. Stop: the earlier of 23 Nov 18:20 UTC (file) and the job start plus 6 h 10 min. CODE=/path/to/TURKIC_OCR_CODE DATA=/path/to/TURKIC_OCR_DATA unset HF_TOKEN HUGGING_FACE_HUB_TOKEN diff --git a/scripts/r5_linedet/line_ext.sbatch b/scripts/r5_linedet/line_ext.sbatch index cc29a70168140be6e244a90d650e69566a1bc17b..992ba5b011dd832f45800286257bd8bcb7524e05 100644 --- a/scripts/r5_linedet/line_ext.sbatch +++ b/scripts/r5_linedet/line_ext.sbatch @@ -7,10 +7,6 @@ #SBATCH --mem=160G #SBATCH --time=03:00:00 #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out -# Amendment 3.4 E5: A1 and A2 (seed 1) continue from their P_long checkpoints to 2 x P_long = 3,168,768 samples (frozen seed-1 sample stream, warm restart with a -# time-aware cosine, peak 2.5e-4, see status.json), then validation predictions, LM decoding and gating for the checkpoint long2x. If the target is not reached in -# the time of this job the training anneals by the clock and stops with a saved checkpoint; the samples reached are in the log and in the checkpoint file. -# Slot L chain: 50971 -> 51128 -> 52050 -> this job -> 51277. CODE=/path/to/TURKIC_OCR_CODE DATA=/path/to/TURKIC_OCR_DATA unset HF_TOKEN HUGGING_FACE_HUB_TOKEN diff --git a/scripts/r5_linedet/lineblock_post.sbatch b/scripts/r5_linedet/lineblock_post.sbatch index 088b32fefdc3a9cb3afcccac2ee2afe2848100bb..d85ac056b69a58ae06cd6f911073000d3a1c27d0 100644 --- a/scripts/r5_linedet/lineblock_post.sbatch +++ b/scripts/r5_linedet/lineblock_post.sbatch @@ -7,7 +7,6 @@ #SBATCH --mem=32G #SBATCH --time=02:00:00 #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out -# After the line block: seed voting of A1 and A2 (D7, descriptive) and the SR1-H06 report (D6, descriptive). Validation sets only. CODE=/path/to/TURKIC_OCR_CODE DATA=/path/to/TURKIC_OCR_DATA unset HF_TOKEN HUGGING_FACE_HUB_TOKEN diff --git a/scripts/r5_linedet/lineblock_vote.sbatch b/scripts/r5_linedet/lineblock_vote.sbatch index 47d5c1d4312696ab77ed378649532b5fff0ebb97..028f0c134d30d87303b036815295c35e8fd0f1c8 100644 --- a/scripts/r5_linedet/lineblock_vote.sbatch +++ b/scripts/r5_linedet/lineblock_vote.sbatch @@ -7,8 +7,6 @@ #SBATCH --mem=24G #SBATCH --time=02:00:00 #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out -# Rerun of the seed voting of job 51129 (which died of out-of-memory in linedet.seed_vote, see the fix in load_npz). Validation sets only; the H06 report of 51129 had finished. -# The same commands can run as a step inside a running job: srun --jobid= --overlap -c 2 --mem=12G bash lineblock_vote.sbatch CODE=/path/to/TURKIC_OCR_CODE DATA=/path/to/TURKIC_OCR_DATA unset HF_TOKEN HUGGING_FACE_HUB_TOKEN diff --git a/scripts/r5_linedet/lm_build.sh b/scripts/r5_linedet/lm_build.sh index 0f0d19902a37967d15974542e7e6abeaf5bdec45..ab138a92950804431a65d09abf24e352181f0c17 100644 --- a/scripts/r5_linedet/lm_build.sh +++ b/scripts/r5_linedet/lm_build.sh @@ -1,6 +1,4 @@ #!/bin/bash -# Character 6-gram, modified Kneser-Ney, built with kenlm lmplz (kenlm 0.3.0 PyPI source, sha256 c4628bb9...; static-boost build on the login node). -# Usage: lm_build.sh [folder with train_text.txt] (default DATA/outputs/r5/linedet/lm) set -eu DATA=/path/to/TURKIC_OCR_DATA LM=${1:-$DATA/outputs/r5/linedet/lm} diff --git a/scripts/r5_linedet/lm_extra.sbatch b/scripts/r5_linedet/lm_extra.sbatch index 447f140aed49dac460f5ece3f8cd64cfe6a3ae7e..46d4a3dcbe5e465aaa3512f8a79c12794702c2b8 100644 --- a/scripts/r5_linedet/lm_extra.sbatch +++ b/scripts/r5_linedet/lm_extra.sbatch @@ -7,7 +7,6 @@ #SBATCH --mem=48G #SBATCH --time=04:00:00 #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out -# After the line block: character-LM decoding (and, through the hook in lm_decode, the gated copy of clarification H9) for the seed-2 runs and A4b. CODE=/path/to/TURKIC_OCR_CODE DATA=/path/to/TURKIC_OCR_DATA unset HF_TOKEN HUGGING_FACE_HUB_TOKEN diff --git a/scripts/r5_linedet/post_chain.sbatch b/scripts/r5_linedet/post_chain.sbatch index 4710d22eff3ae2e6df98d1cd84a780ee02f3d1e6..c8b6ab9a60431b649828267c452b9079df5075a2 100644 --- a/scripts/r5_linedet/post_chain.sbatch +++ b/scripts/r5_linedet/post_chain.sbatch @@ -7,7 +7,6 @@ #SBATCH --mem=48G #SBATCH --time=04:00:00 #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out -# After the GPU job: language-model decoding of every prediction set that the GPU job did not finish, then results.json and arch.json. CODE=/path/to/TURKIC_OCR_CODE DATA=/path/to/TURKIC_OCR_DATA unset HF_TOKEN HUGGING_FACE_HUB_TOKEN diff --git a/scripts/r5_linedet/r2_cmdtest.sh b/scripts/r5_linedet/r2_cmdtest.sh index f5b301f9cda38827204d11e9057e91ab0874deef..992a3c1430501832209f5834847e25141516804d 100644 --- a/scripts/r5_linedet/r2_cmdtest.sh +++ b/scripts/r5_linedet/r2_cmdtest.sh @@ -1,6 +1,4 @@ #!/bin/bash -# Validation-only test of the edited R2 prediction command (22 Nov): the new ref_ppocr_predict.py.new with --weights /model/latest, 200 crops of a validation set, -# predictions written to a scratch folder (--pred_root), never to preds/. No locked set is named. C=/path/to/TURKIC_OCR_CODE D=/path/to/TURKIC_OCR_DATA S=$C/scripts/r5_ref diff --git a/scripts/r5_linedet/ref_finish.sbatch b/scripts/r5_linedet/ref_finish.sbatch index 6fc8bca375b3e51da8f42f9ab6e432af62ed4133..9d5ef61a10d713f2bb76e7a90e99eaa2ef88426c 100644 --- a/scripts/r5_linedet/ref_finish.sbatch +++ b/scripts/r5_linedet/ref_finish.sbatch @@ -7,9 +7,6 @@ #SBATCH --mem=160G #SBATCH --time=03:00:00 #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out -# Clarification H12: resume the reference runs (stage REF) that were cut short or never started in the line block 51128, from REF's saved state, up to the -# paper's stopping rule or the 3 h limit of this job. Exits at once when every reference run reached its stopping rule. Slot L chain: -# 50971 -> 51128 (line block) -> this job -> 51277 (leader job on slot L). CODE=/path/to/TURKIC_OCR_CODE DATA=/path/to/TURKIC_OCR_DATA unset HF_TOKEN HUGGING_FACE_HUB_TOKEN diff --git a/scripts/r5_linedet/ref_val_figs.sh b/scripts/r5_linedet/ref_val_figs.sh index 5c5c2f3e585d0f1c8ada907a7b0497924b9d70f1..d4b2ca4c2a7dc255a391a5dc0a6bdd2fdc41daae 100644 --- a/scripts/r5_linedet/ref_val_figs.sh +++ b/scripts/r5_linedet/ref_val_figs.sh @@ -1,7 +1,4 @@ #!/bin/bash -# Validation-only figures of the replication split (clarification H12): R2(ii) predictions on kohtd_rand_val (the 15 % validation part of the replication split) with the -# final-epoch weights (model/latest: the compressed 3-epoch run never reached the 2000-iteration evaluation, so PaddleOCR saved no best_accuracy), then the paper metrics for -# R1(ii) (existing predictions) and R2(ii). Runs as a small step inside job 52050 (srun --jobid=52050 --overlap). No locked set is read. CODE=/path/to/TURKIC_OCR_CODE D=/path/to/TURKIC_OCR_DATA unset HF_TOKEN HUGGING_FACE_HUB_TOKEN diff --git a/scripts/r5_linedet/smoke_cpu.sbatch b/scripts/r5_linedet/smoke_cpu.sbatch index 6ce268bea3f119d29b4b1d02ba9d5049cfc2acb9..7f7d72c1253b8ef59a4e79fc9fbf2a884a54c455 100644 --- a/scripts/r5_linedet/smoke_cpu.sbatch +++ b/scripts/r5_linedet/smoke_cpu.sbatch @@ -7,7 +7,6 @@ #SBATCH --mem=48G #SBATCH --time=01:30:00 #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out -# Smoke test on CPU: every arm trains a few steps on KOHTD train crops (kohtd_split_v1), saves, resumes-free predict on 64 validation crops. CODE=/path/to/TURKIC_OCR_CODE DATA=/path/to/TURKIC_OCR_DATA unset HF_TOKEN HUGGING_FACE_HUB_TOKEN diff --git a/scripts/r5_linedet/test_pass_commands.sh b/scripts/r5_linedet/test_pass_commands.sh index 206ad307bebb0dc6c967d470abf44ee29db998cd..79fe00d14c5d9daf6e9252826aef0085d4bb82ac 100644 --- a/scripts/r5_linedet/test_pass_commands.sh +++ b/scripts/r5_linedet/test_pass_commands.sh @@ -1,17 +1,4 @@ #!/bin/bash -# R5 LINEDET: test-set predictions of the line arms, to be run on a compute node ONLY in the scoring pass. NO CAP of any kind (clarification H10): -# every crop of every locked set, greedy and then the character-LM beam search (alpha and beta taken from each checkpoint's validation tuning) and its gated copy. -# -# Order of use: -# 1. copy records/R5/RULE/test_pass_started.txt to the cluster as /path/to/TURKIC_OCR_DATA/outputs/r5/linedet/test_pass_started.txt -# (predict.py and lm_decode.py REFUSE the test pass while that file does not exist, and refuse --limit and --max_lines). -# 2. run this script in a job, for example (GPU for the predictions; the LM decoding uses CPU workers): -# sbatch --partition=H100 --qos=nu-h100 --gres=gpu:h100:1 --cpus-per-task=32 --mem=96G --time=03:00:00 --job-name=r5_ld_testpass \ -# --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out --wrap "bash /path/to/TURKIC_OCR_CODE/scripts/r5_linedet/test_pass_commands.sh" -# (LINEDET_DEVICE=cpu runs it on CPU.) -# Writes DATA/outputs/r5/preds/