Download src/pagesynth/scripts/make_chunks.py from treoa/turkic-ocr-code: direct link, hf CLI and curl.
- Browser
- Download file 1.6 kB
-
https://huggingface.co/treoa/turkic-ocr-code/resolve/main/src/pagesynth/scripts/make_chunks.py
- Command line
-
hf download hf://treoa/turkic-ocr-code/src/pagesynth/scripts/make_chunks.py
-
curl -L -o make_chunks.py https://huggingface.co/treoa/turkic-ocr-code/resolve/main/src/pagesynth/scripts/make_chunks.py
1.6 kB
| """R5: chunk list of a production stage. | |
| usage: python make_chunks.py OUT_TSV H_TRAIN T_TRAIN H_VAL H_TEST T_VAL T_TEST [FIRST_TRAIN_H FIRST_TRAIN_T] [chunk size] | |
| Pages per language and population (counts), first page index of a later stage (default 0), chunk size (default 400). | |
| Page counts are chosen from the lines per page of the pilot (hand about 5.5 of 6 requested, typed about 5.7 of 6) plus a margin.""" | |
| import sys | |
| out = sys.argv[1] | |
| nh_tr, nt_tr, nh_va, nh_te, nt_va, nt_te = [int(x) for x in sys.argv[2:8]] | |
| fh = int(sys.argv[8]) if len(sys.argv) > 8 else 0 | |
| ft = int(sys.argv[9]) if len(sys.argv) > 9 else 0 | |
| cs = int(sys.argv[10]) if len(sys.argv) > 10 else 400 | |
| LANGS = ["kk", "ky", "uz_cyrl", "uz_latn", "tr", "az", "tt", "ba", "tk", "sah"] | |
| rows = [] | |
| def add(lang, split, pop, first, count, psave_total): | |
| s = first | |
| while s < first + count: | |
| n = min(cs, first + count - s) | |
| ps = max(0, min(n, psave_total - s)) if first == 0 else 0 | |
| rows.append((lang, split, pop, s, n, ps)) | |
| s += n | |
| # order: val and test first (small, needed for every check), then train | |
| for lang in LANGS: | |
| if nh_va: | |
| add(lang, "val", "H", 0, nh_va, 30) | |
| add(lang, "test", "H", 0, nh_te, 30) | |
| add(lang, "val", "T", 0, nt_va, 0) | |
| add(lang, "test", "T", 0, nt_te, 0) | |
| for lang in LANGS: | |
| add(lang, "train", "H", fh, nh_tr, 400) | |
| add(lang, "train", "T", ft, nt_tr, 0) | |
| with open(out, "w", encoding="utf-8") as f: | |
| for r in rows: | |
| f.write("\t".join(str(x) for x in r) + "\n") | |
| print(len(rows), "chunks,", sum(r[4] for r in rows), "pages") | |