Download analysis/scripts/compare_runs.py from Urdatorn/Makron-code: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/Urdatorn/Makron-code/resolve/main/analysis/scripts/compare_runs.py
- Command line
-
hf download hf://Urdatorn/Makron-code/analysis/scripts/compare_runs.py
-
curl -L -o compare_runs.py https://huggingface.co/Urdatorn/Makron-code/resolve/main/analysis/scripts/compare_runs.py
1.3 kB
| """Compare two macronize_oga_corpus.py runs line by line (same input, same chunking). | |
| Usage: python3 compare_runs.py OLD_OUT_DIR NEW_OUT_DIR | |
| """ | |
| import collections, glob, json, os, sys | |
| old, new = sys.argv[1:3] | |
| strip = lambda s: s.replace("^", "").replace("_", "") | |
| n = same = text_diff = marks_only = count_mismatch = 0 | |
| ex = collections.defaultdict(list) | |
| for f in sorted(glob.glob(os.path.join(new, "parts", "*.txt"))): | |
| a = open(os.path.join(old, "parts", os.path.basename(f)), encoding="utf-8").read().splitlines() | |
| b = open(f, encoding="utf-8").read().splitlines() | |
| if len(a) != len(b): | |
| count_mismatch += 1; ex["count_mismatch"].append((os.path.basename(f), len(a), len(b))); continue | |
| for x, y in zip(a, b): | |
| n += 1 | |
| if x == y: same += 1 | |
| elif strip(x) != strip(y): | |
| text_diff += 1 | |
| if len(ex["text"]) < 40: ex["text"].append((x, y)) | |
| else: | |
| marks_only += 1 | |
| if len(ex["marks"]) < 40: ex["marks"].append((x, y)) | |
| s = dict(lines=n, identical=same, text_differs=text_diff, marks_only_differ=marks_only, files_with_line_count_mismatch=count_mismatch) | |
| print(json.dumps(s, indent=2)) | |
| json.dump(dict(summary=s, examples=ex), open(os.path.join(new, "compare_to_previous.json"), "w"), ensure_ascii=False, indent=1) | |