Datasets:
Download scripts/create_600_subsets.py from HuggingFaceBio/genomeqa: direct link, hf CLI and curl.
- Browser
- Download file 1.84 kB
-
https://huggingface.co/datasets/HuggingFaceBio/genomeqa/resolve/main/scripts/create_600_subsets.py
- Command line
-
hf download hf://datasets/HuggingFaceBio/genomeqa/scripts/create_600_subsets.py
-
curl -L -o create_600_subsets.py https://huggingface.co/datasets/HuggingFaceBio/genomeqa/resolve/main/scripts/create_600_subsets.py
1.84 kB
| """Create deterministic 600-example GenomeQA subsets balanced by subtask.""" | |
| import argparse | |
| import random | |
| from collections import Counter | |
| from pathlib import Path | |
| from datasets import load_dataset | |
| DATASET_ID = "HuggingFaceBio/genomeqa" | |
| SOURCE_REVISION = "a71ab7e0e72b8eca7acd4475744dccd0159b20be" | |
| SOURCE_CONFIGS = ("binary", "mcq") | |
| SAMPLES_PER_SUBTASK = 100 | |
| SEED = 42 | |
| def create_subset(config: str, output_dir: Path, seed: int) -> None: | |
| dataset = load_dataset(DATASET_ID, config, split="train", revision=SOURCE_REVISION) | |
| subtasks = sorted(set(dataset["subtask"])) | |
| rng = random.Random(f"{seed}:{config}") | |
| selected_indices = [] | |
| for subtask in subtasks: | |
| candidate_indices = [index for index, value in enumerate(dataset["subtask"]) if value == subtask] | |
| if len(candidate_indices) < SAMPLES_PER_SUBTASK: | |
| raise ValueError(f"{subtask} has only {len(candidate_indices)} examples") | |
| selected_indices.extend(rng.sample(candidate_indices, SAMPLES_PER_SUBTASK)) | |
| rng.shuffle(selected_indices) | |
| subset = dataset.select(selected_indices) | |
| expected_counts = dict.fromkeys(subtasks, SAMPLES_PER_SUBTASK) | |
| if Counter(subset["subtask"]) != expected_counts: | |
| raise RuntimeError("Generated subset is not balanced by subtask") | |
| config_dir = output_dir / f"{config}_600" | |
| config_dir.mkdir(parents=True, exist_ok=True) | |
| output_path = config_dir / "train-00000-of-00001.parquet" | |
| subset.to_parquet(output_path) | |
| def main() -> None: | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--output-dir", type=Path, default=Path.cwd()) | |
| parser.add_argument("--seed", type=int, default=SEED) | |
| args = parser.parse_args() | |
| for config in SOURCE_CONFIGS: | |
| create_subset(config, args.output_dir, args.seed) | |
| if __name__ == "__main__": | |
| main() | |