Download subset_build.py from Tonic/challenge5-acoustic-code: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/Tonic/challenge5-acoustic-code/resolve/main/subset_build.py
- Command line
-
hf download hf://Tonic/challenge5-acoustic-code/subset_build.py
-
curl -L -o subset_build.py https://huggingface.co/Tonic/challenge5-acoustic-code/resolve/main/subset_build.py
1.39 kB
| # /// script | |
| # requires-python = ">=3.11" | |
| # dependencies = ["datasets>=4.0", "huggingface_hub>=0.30", "pillow"] | |
| # /// | |
| """Build Tonic/challenge5-train-subset: stratified 60k-row windows_5s subset of | |
| Tonic/unified-drone-acoustic-cuas, always keeping every challenge5 row. | |
| Run as an HF Job (cpu-basic): uv run subset_build.py | |
| """ | |
| import os | |
| from datasets import load_dataset, DatasetDict | |
| SRC = "Tonic/unified-drone-acoustic-cuas" | |
| DST = "Tonic/challenge5-train-subset" | |
| TRAIN_N, VALID_N = 60_000, 4_000 | |
| ds = load_dataset(SRC, "windows_5s", token=os.environ["HF_TOKEN"]) | |
| out = {} | |
| for split, n in (("train", TRAIN_N), ("validation", VALID_N)): | |
| d = ds[split] | |
| c5 = d.filter(lambda r: r["source"] == "challenge5", num_proc=8) | |
| rest = d.filter(lambda r: r["source"] != "challenge5", num_proc=8) | |
| rest = rest.shuffle(seed=42).select(range(min(n - len(c5), len(rest)))) | |
| from datasets import concatenate_datasets | |
| out[split] = concatenate_datasets([c5, rest]) | |
| print(f"{split}: {len(out[split])} rows (challenge5: {len(c5)})", flush=True) | |
| # test: keep only challenge5 (held-out labels) -> tiny | |
| c5t = ds["test"].filter(lambda r: r["source"] == "challenge5", num_proc=8) | |
| out["test"] = c5t | |
| print(f"test: {len(c5t)} rows (challenge5 only)", flush=True) | |
| DatasetDict(out).push_to_hub(DST, config_name="windows_5s", token=os.environ["HF_TOKEN"]) | |
| print("PUSHED", DST, flush=True) | |