Download scripts/r5eval/build_ktrain.py from treoa/turkic-ocr-code: direct link, hf CLI and curl.
- Browser
- Download file 2.1 kB
-
https://huggingface.co/treoa/turkic-ocr-code/resolve/main/scripts/r5eval/build_ktrain.py
- Command line
-
hf download hf://treoa/turkic-ocr-code/scripts/r5eval/build_ktrain.py
-
curl -L -o build_ktrain.py https://huggingface.co/treoa/turkic-ocr-code/resolve/main/scripts/r5eval/build_ktrain.py
2.1 kB
| """Builds and hashes K_train (clarification G3) from the train manifests of the frozen mix_v1.yaml. | |
| usage: python -I build_ktrain.py --mix DATA/data/processed/r5/mix_v1.yaml --out DATA/data/processed/r5/p2 | |
| [--extra-text FILE ...] (default: DATA/data/processed/r5/pagesynth_text_split/train/*/sentences.tsv, the generator's | |
| train text; the character-LM training text is the same corpus plus the mix train labels) | |
| Reads training text only (manifest rows with split == train that match the leaf filter; sentences of the train text split). | |
| Never opens a validation or test manifest. Writes <out>/ktrain_manifest.json and three gzip key files. Run it ONCE after the | |
| freeze of mix_v1.yaml (CPU job, scripts/r5_ktrain.sbatch); score.py then loads it and records its sha256 in every score file. | |
| """ | |
| import argparse | |
| import glob | |
| import os | |
| import sys | |
| HERE = os.path.dirname(os.path.abspath(__file__)) | |
| sys.path.insert(0, os.path.normpath(os.path.join(HERE, "..", "..", "src"))) | |
| DATA = "/path/to/TURKIC_OCR_DATA" | |
| R5 = DATA + "/data/processed/r5" | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--mix", default=R5 + "/mix_v1.yaml") | |
| ap.add_argument("--out", default=R5 + "/p2") | |
| ap.add_argument("--extra-text", nargs="*", default=None) | |
| ap.add_argument("--manifest-root", default=None, help="tests only: replaces the folder of every leaf manifest") | |
| a = ap.parse_args() | |
| from r5eval import ktrain | |
| if not os.path.exists(a.mix): | |
| sys.exit("mix_v1.yaml not found at %s: K_train is built after the freeze" % a.mix) | |
| extra = a.extra_text | |
| if extra is None: | |
| extra = sorted(glob.glob(R5 + "/pagesynth_text_split/train/*/sentences.tsv")) | |
| for p in extra: | |
| if "/val/" in p or "/test/" in p: | |
| sys.exit("refusing to read validation or test text: %s" % p) | |
| man = ktrain.build(a.mix, a.out, extra, manifest_root=a.manifest_root) | |
| print("K_train written to", a.out) | |
| print("counts", man["counts"]) | |
| print("ktrain_sha256", man["ktrain_sha256"]) | |
| if __name__ == "__main__": | |
| main() | |