og2_small / scripts /check_rates.py
AutomatedScientist's picture
Add files using upload-large-folder tool
6f32cc3 verified
Raw History Blame Contribute Delete
1.37 kB
"""Check uniformity: realized inclusion rate (kept bases / characters streamed) per subset and split, vs the target.
python check_rates.py [--root .] [--split train]
A per-base uniform sample keeps rate * (sequence characters) per subset; characters streamed also count tag and
separator characters, so a subset with many tags or separators shows a slightly lower realized rate.
"""
from __future__ import annotations
import argparse
import json
from collections import defaultdict
from pathlib import Path
def main() -> None:
ap = argparse.ArgumentParser()
ap.add_argument("--root", type=Path, default=Path("."))
ap.add_argument("--split", default="train")
a = ap.parse_args()
agg = defaultdict(lambda: [0, 0, 0, 0.0])
for done in sorted((a.root / a.split).glob("*/*.done")):
st = json.loads(done.read_text())
g = agg[done.parent.name]
g[0] += st["kept_bases"]
g[1] += st["chars_seen"]
g[2] += st["records"]
g[3] = st["rate"]
print(f"{'subset':<28} {'records':>12} {'chars/record':>13} {'kept/chars':>11} {'ratio to rate':>14}")
for k, (kept, chars, recs, rate) in sorted(agg.items(), key=lambda kv: -kv[1][1]):
r = kept / max(chars, 1)
print(f"{k:<28} {recs:12d} {chars / max(recs, 1):13.0f} {r:11.3e} {r / rate:14.3f}")
if __name__ == "__main__":
main()