Datasets:
Sedweave real train/dev/frozen data with original and unselected candidate evaluations
d96cf4e verified Download build_v2_mix.py from asterbraid/sedweave-real-data: direct link, hf CLI and curl.
- Browser
- Download file 3.61 kB
-
https://huggingface.co/datasets/asterbraid/sedweave-real-data/resolve/main/build_v2_mix.py
- Command line
-
hf download hf://datasets/asterbraid/sedweave-real-data/build_v2_mix.py
-
curl -L -o build_v2_mix.py https://huggingface.co/datasets/asterbraid/sedweave-real-data/resolve/main/build_v2_mix.py
3.61 kB
| from __future__ import annotations | |
| import argparse | |
| import collections | |
| import hashlib | |
| import json | |
| import random | |
| from pathlib import Path | |
| def main() -> None: | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--seed-data", type=Path, required=True) | |
| parser.add_argument("--real-data", type=Path, required=True) | |
| parser.add_argument("--dev-data", type=Path, required=True) | |
| parser.add_argument("--output", type=Path, required=True) | |
| parser.add_argument("--summary", type=Path, required=True) | |
| parser.add_argument("--replay-per-family", type=int, default=176) | |
| parser.add_argument("--real-repeat", type=int, default=6) | |
| parser.add_argument("--seed", type=int, default=42) | |
| args = parser.parse_args() | |
| seed_rows = [json.loads(line) for line in args.seed_data.open(encoding="utf-8")] | |
| real_rows = [json.loads(line) for line in args.real_data.open(encoding="utf-8")] | |
| dev_rows = [json.loads(line) for line in args.dev_data.open(encoding="utf-8")] | |
| if any(row["split"] != "train" for row in real_rows): | |
| raise ValueError("Real expansion contains non-training rows") | |
| real_sources = {row["question_url"] for row in real_rows} | |
| if real_sources & {row["question_url"] for row in dev_rows}: | |
| raise ValueError("Development source question leaked into training") | |
| rng = random.Random(args.seed) | |
| by_family = collections.defaultdict(list) | |
| for row in seed_rows: | |
| if row["split"] == "train" and not row.get("paraphrase_of"): | |
| by_family[row["family"]].append(row) | |
| replay = [] | |
| for family, rows in sorted(by_family.items()): | |
| rows = list(rows) | |
| rng.shuffle(rows) | |
| replay.extend(rows[:args.replay_per_family]) | |
| train = [] | |
| for row in replay: | |
| train.append(dict(row, mixture_source="synthetic-replay")) | |
| for repetition in range(args.real_repeat): | |
| for row in real_rows: | |
| repeated = dict(row) | |
| repeated["id"] = f"{row['id']}-r{repetition + 1}" | |
| repeated["mixture_source"] = "real-expansion" | |
| repeated["repetition"] = repetition + 1 | |
| train.append(repeated) | |
| rng.shuffle(train) | |
| validation = [dict(row, split="validation") for row in dev_rows] | |
| output_rows = train + validation | |
| with args.output.open("w", encoding="utf-8") as handle: | |
| for row in output_rows: | |
| handle.write(json.dumps(row, ensure_ascii=False, separators=(",", ":")) + "\n") | |
| summary = { | |
| "output": str(args.output), | |
| "sha256": hashlib.sha256(args.output.read_bytes()).hexdigest(), | |
| "train_rows": len(train), | |
| "validation_rows": len(validation), | |
| "synthetic_replay_rows": len(replay), | |
| "real_expansion_rows": len(train) - len(replay), | |
| "real_unique_rows": len(real_rows), | |
| "real_repeat": args.real_repeat, | |
| "replay_per_family": args.replay_per_family, | |
| "families": len(by_family), | |
| "seed": args.seed, | |
| "train_dev_input_overlap": len({row["input_text"] for row in train} & {row["input_text"] for row in dev_rows}), | |
| "train_dev_request_command_overlap": len( | |
| {(row["request"], row["command"]) for row in train} | |
| & {(row["request"], row["command"]) for row in dev_rows} | |
| ), | |
| } | |
| if summary["train_dev_input_overlap"] or summary["train_dev_request_command_overlap"]: | |
| raise ValueError("Development data leaked into the training mixture") | |
| args.summary.write_text(json.dumps(summary, indent=2), encoding="utf-8") | |
| print(json.dumps(summary, indent=2)) | |
| if __name__ == "__main__": | |
| main() | |