Datasets:
Download code/scripts_seqroute/fix_splits.py from divy123/sequential-router-v2: direct link, hf CLI and curl.
- Browser
- Download file 2.58 kB
-
https://huggingface.co/datasets/divy123/sequential-router-v2/resolve/main/code/scripts_seqroute/fix_splits.py
- Command line
-
hf download hf://datasets/divy123/sequential-router-v2/code/scripts_seqroute/fix_splits.py
-
curl -L -o fix_splits.py https://huggingface.co/datasets/divy123/sequential-router-v2/resolve/main/code/scripts_seqroute/fix_splits.py
2.58 kB
| """Re-derive `split` / `scale_order` on the shipped query tables with the group-consistent rule (in_20k and all prompts untouched) and rewrite split manifests.""" | |
| import json, os, sys | |
| sys.path.insert(0, "scripts/seqroute") | |
| import pandas as pd | |
| from build_queries import assign_splits, hh, SEED | |
| ROOT = "/mnt/localssd/seqroute1m" | |
| df = pd.read_parquet(f"{ROOT}/queries/master_queries.parquet") | |
| old = df.split.copy() | |
| df = assign_splits(df.drop(columns=["split", "legacy_split"], errors="ignore")) | |
| assert (df.legacy_split == old).all(), "legacy split no longer reproduces the shipped one" | |
| df["scale_rank"], df["scale_order"] = -1.0, -1 | |
| tr = df[(df.split == "train") & df.in_20k] | |
| for _, g in tr.groupby(["task_family", "source_dataset"]): | |
| idx = sorted(g.index, key=lambda i: hh("scale", SEED, df.at[i, "query_id"])) | |
| for r, i in enumerate(idx): | |
| df.at[i, "scale_rank"] = (r + 0.5) / len(idx) | |
| order = sorted(tr.index, key=lambda i: (df.at[i, "scale_rank"], hh("tie", df.at[i, "query_id"]))) | |
| for pos, i in enumerate(order): | |
| df.at[i, "scale_order"] = pos | |
| df.to_parquet(f"{ROOT}/queries/master_queries.parquet.tmp"); os.replace(f"{ROOT}/queries/master_queries.parquet.tmp", f"{ROOT}/queries/master_queries.parquet") | |
| g = df[df.in_20k].reset_index(drop=True); g.to_parquet(f"{ROOT}/queries/queries_20k.parquet.tmp"); os.replace(f"{ROOT}/queries/queries_20k.parquet.tmp", f"{ROOT}/queries/queries_20k.parquet") | |
| M = f"{ROOT}/manifests" | |
| for f in os.listdir(M): | |
| if f.startswith("scaling_train_"): os.remove(f"{M}/{f}") | |
| for sp in ("train", "val", "test"): | |
| json.dump(sorted(df[df.split == sp].query_id), open(f"{M}/master_{sp}_ids.json", "w")); json.dump(sorted(df[(df.split == sp) & df.in_20k].query_id), open(f"{M}/gen20k_{sp}_ids.json", "w")) | |
| trn = df[(df.split == "train") & df.in_20k].sort_values("scale_order") | |
| for n in (1000, 2000, 5000, 10000, len(trn)): | |
| json.dump(list(trn.query_id[:n]), open(f"{M}/scaling_train_{n}_ids.json", "w")) | |
| man = json.load(open(f"{M}/queries_manifest.json")); man["split_master"] = df.split.value_counts().to_dict(); man["split_20k"] = g.split.value_counts().to_dict() | |
| man["split_rule"] = "group-level (group_id) 70/15/15 within (task_family, source_dataset); groups spanning several strata (HumanEval/-Fix, MBPP/mutants) are assigned by hash to one split; 20k subset drawn proportionally within (family, source, legacy per-stratum split)" | |
| json.dump(man, open(f"{M}/queries_manifest.json", "w"), indent=1) | |
| print("groups in >1 split:", int((df.groupby("group_id").split.nunique() > 1).sum()), man["split_master"], man["split_20k"]) | |