Datasets:
Download source/tools/make_dataset.py from Syndicate604/science-desk: direct link, hf CLI and curl.
- Browser
- Download file 3.12 kB
-
https://huggingface.co/datasets/Syndicate604/science-desk/resolve/main/source/tools/make_dataset.py
- Command line
-
hf download hf://datasets/Syndicate604/science-desk/source/tools/make_dataset.py
-
curl -L -o make_dataset.py https://huggingface.co/datasets/Syndicate604/science-desk/resolve/main/source/tools/make_dataset.py
3.12 kB
| """Assemble the public Hugging Face dataset folder. | |
| Writes OUT/tasks.jsonl (one task per line: id, family, domain, level, an example instruction, the calibration screen stats and whether the task is in the submission), and | |
| OUT/source/ (the environment, tools, tests, Dockerfile). The README card is kept by hand. | |
| Usage: python tools/make_dataset.py --screen runs/a.jsonl runs/b.jsonl --selected runs/selected.txt --out dataset | |
| """ | |
| import argparse | |
| import json | |
| import os | |
| import random | |
| import shutil | |
| import sys | |
| from collections import defaultdict | |
| sys.path.insert(0, ".") | |
| from terminal_desk.families import FAMILIES, all_task_ids, instance_seed, parse_task_id # noqa: E402 | |
| SOURCE = ["terminal_desk", "tools", "tests", "Dockerfile", "openenv.yaml", "README.md", "LICENSE", "NOTICE", | |
| ".dockerignore", "vendor"] | |
| def main() -> None: | |
| p = argparse.ArgumentParser() | |
| p.add_argument("--screen", required=True, nargs="+") | |
| p.add_argument("--selected", required=True) | |
| p.add_argument("--out", required=True) | |
| a = p.parse_args() | |
| stats = defaultdict(list) | |
| for path in a.screen: | |
| for line in open(path): | |
| r = json.loads(line) | |
| if "error" not in r: | |
| stats[r["task_id"]].append(r) | |
| selected = {ln.strip() for ln in open(a.selected) if ln.strip() and not ln.startswith("#")} | |
| with open(os.path.join(a.out, "tasks.jsonl"), "w") as fh: | |
| for tid in all_task_ids(): | |
| fid, level, _ = parse_task_id(tid) | |
| fam = FAMILIES[fid] | |
| built = fam.build(level, random.Random(instance_seed(tid))) # the fixed instance reset serves | |
| rs = stats.get(tid, []) | |
| rewards = [r["reward"] for r in rs] | |
| fh.write(json.dumps({ | |
| "task_id": tid, | |
| "family": fid, | |
| "domain": fam.domain, | |
| "level": level, | |
| "title": fam.title, | |
| "in_submission": tid in selected, | |
| "screen_episodes": len(rs), | |
| "screen_mean_reward": round(sum(rewards) / len(rewards), 3) if rewards else None, | |
| "screen_full_solves": sum(1 for x in rewards if x == 1.0), | |
| "screen_non_json_endings": sum(1 for r in rs if r["ended"] in ("invalid_reply", "truncated", "invalid_action")), | |
| "screen_budget_endings": sum(1 for r in rs if r["ended"] in ("budget", "context")), | |
| "screen_mean_steps": round(sum(r["steps"] for r in rs) / len(rs), 2) if rs else None, | |
| "artifact_path": "/app/" + built.artifact.path, | |
| "artifact_kind": built.artifact.kind, | |
| "example_instruction": built.instruction, | |
| }) + "\n") | |
| src = os.path.join(a.out, "source") | |
| shutil.rmtree(src, ignore_errors=True) | |
| for name in SOURCE: | |
| if os.path.isdir(name): | |
| shutil.copytree(name, os.path.join(src, name), ignore=shutil.ignore_patterns("__pycache__", "qwen_tok")) | |
| else: | |
| shutil.copy(name, os.path.join(src, name)) | |
| print("dataset folder ready:", a.out) | |
| if __name__ == "__main__": | |
| main() | |