Replace with Croissant-friendly questions table
Browse files- data/questions.jsonl +0 -0
- scripts/export_hf_questions.py +7 -11
- scripts/upload_hf_dataset.py +57 -0
data/questions.jsonl
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
scripts/export_hf_questions.py
CHANGED
|
@@ -2,7 +2,6 @@
|
|
| 2 |
from __future__ import annotations
|
| 3 |
|
| 4 |
import argparse
|
| 5 |
-
import hashlib
|
| 6 |
import json
|
| 7 |
from pathlib import Path
|
| 8 |
from typing import Any
|
|
@@ -84,12 +83,6 @@ def as_list(value: Any) -> list[Any]:
|
|
| 84 |
return [value]
|
| 85 |
|
| 86 |
|
| 87 |
-
def stable_id(source_rel: str) -> str:
|
| 88 |
-
digest = hashlib.sha1(source_rel.encode("utf-8")).hexdigest()[:12]
|
| 89 |
-
readable = source_rel.removesuffix(".json").replace("/", "__").replace(" ", "_").replace("&", "and")
|
| 90 |
-
return f"{readable}__{digest}"
|
| 91 |
-
|
| 92 |
-
|
| 93 |
def normalize_answer(raw: Any) -> str | int | float | bool | list[Any] | dict[str, Any] | None:
|
| 94 |
if raw is None:
|
| 95 |
return None
|
|
@@ -233,7 +226,7 @@ def compact_metadata(payload: dict[str, Any]) -> dict[str, Any]:
|
|
| 233 |
return metadata
|
| 234 |
|
| 235 |
|
| 236 |
-
def record_for_file(path: Path, json_root: Path) -> dict[str, Any]:
|
| 237 |
rel = path.relative_to(json_root)
|
| 238 |
parts = rel.parts
|
| 239 |
if len(parts) < 5:
|
|
@@ -242,12 +235,11 @@ def record_for_file(path: Path, json_root: Path) -> dict[str, Any]:
|
|
| 242 |
big_task, small_task, scene_from_path, room_from_path = parts[:4]
|
| 243 |
payload = json.loads(path.read_text(encoding="utf-8"))
|
| 244 |
question, answer, options = extract_question_answer(payload)
|
| 245 |
-
source_rel = rel.as_posix()
|
| 246 |
scene = text(payload.get("scene")) or scene_from_path
|
| 247 |
room = text(payload.get("room")) or room_from_path
|
| 248 |
|
| 249 |
return {
|
| 250 |
-
"id":
|
| 251 |
"big_task": big_task,
|
| 252 |
"small_task": small_task,
|
| 253 |
"runner_task": RUNNER_TASK_BY_SMALL.get(small_task),
|
|
@@ -270,7 +262,11 @@ def main() -> int:
|
|
| 270 |
|
| 271 |
json_root = args.json_root
|
| 272 |
question_files = sorted(p for p in json_root.rglob("*.json") if p.parent != json_root)
|
| 273 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
|
| 275 |
args.output.parent.mkdir(parents=True, exist_ok=True)
|
| 276 |
with args.output.open("w", encoding="utf-8") as f:
|
|
|
|
| 2 |
from __future__ import annotations
|
| 3 |
|
| 4 |
import argparse
|
|
|
|
| 5 |
import json
|
| 6 |
from pathlib import Path
|
| 7 |
from typing import Any
|
|
|
|
| 83 |
return [value]
|
| 84 |
|
| 85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
def normalize_answer(raw: Any) -> str | int | float | bool | list[Any] | dict[str, Any] | None:
|
| 87 |
if raw is None:
|
| 88 |
return None
|
|
|
|
| 226 |
return metadata
|
| 227 |
|
| 228 |
|
| 229 |
+
def record_for_file(path: Path, json_root: Path, row_id: str) -> dict[str, Any]:
|
| 230 |
rel = path.relative_to(json_root)
|
| 231 |
parts = rel.parts
|
| 232 |
if len(parts) < 5:
|
|
|
|
| 235 |
big_task, small_task, scene_from_path, room_from_path = parts[:4]
|
| 236 |
payload = json.loads(path.read_text(encoding="utf-8"))
|
| 237 |
question, answer, options = extract_question_answer(payload)
|
|
|
|
| 238 |
scene = text(payload.get("scene")) or scene_from_path
|
| 239 |
room = text(payload.get("room")) or room_from_path
|
| 240 |
|
| 241 |
return {
|
| 242 |
+
"id": row_id,
|
| 243 |
"big_task": big_task,
|
| 244 |
"small_task": small_task,
|
| 245 |
"runner_task": RUNNER_TASK_BY_SMALL.get(small_task),
|
|
|
|
| 262 |
|
| 263 |
json_root = args.json_root
|
| 264 |
question_files = sorted(p for p in json_root.rglob("*.json") if p.parent != json_root)
|
| 265 |
+
id_width = max(4, len(str(len(question_files))))
|
| 266 |
+
records = [
|
| 267 |
+
record_for_file(path, json_root, f"{index:0{id_width}d}")
|
| 268 |
+
for index, path in enumerate(question_files, start=1)
|
| 269 |
+
]
|
| 270 |
|
| 271 |
args.output.parent.mkdir(parents=True, exist_ok=True)
|
| 272 |
with args.output.open("w", encoding="utf-8") as f:
|
scripts/upload_hf_dataset.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import argparse
|
| 5 |
+
import subprocess
|
| 6 |
+
import sys
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
from huggingface_hub import HfApi
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def run_export(repo_root: Path) -> None:
|
| 13 |
+
subprocess.run(
|
| 14 |
+
[sys.executable, "scripts/export_hf_questions.py"],
|
| 15 |
+
cwd=repo_root,
|
| 16 |
+
check=True,
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def main() -> int:
|
| 21 |
+
parser = argparse.ArgumentParser(description="Upload the Croissant-friendly ESI-Bench table to Hugging Face.")
|
| 22 |
+
parser.add_argument("--repo-id", default="ESI-Bench/esi-bench")
|
| 23 |
+
parser.add_argument("--repo-root", type=Path, default=Path(__file__).resolve().parents[1])
|
| 24 |
+
parser.add_argument("--private", action="store_true", help="Create the dataset repo as private if it does not exist.")
|
| 25 |
+
parser.add_argument("--skip-export", action="store_true", help="Upload existing data/questions.jsonl without regenerating it.")
|
| 26 |
+
parser.add_argument("--commit-message", default="Replace with Croissant-friendly questions table")
|
| 27 |
+
args = parser.parse_args()
|
| 28 |
+
|
| 29 |
+
repo_root = args.repo_root.resolve()
|
| 30 |
+
if not args.skip_export:
|
| 31 |
+
run_export(repo_root)
|
| 32 |
+
|
| 33 |
+
api = HfApi()
|
| 34 |
+
api.create_repo(repo_id=args.repo_id, repo_type="dataset", private=args.private, exist_ok=True)
|
| 35 |
+
api.upload_folder(
|
| 36 |
+
folder_path=repo_root,
|
| 37 |
+
repo_id=args.repo_id,
|
| 38 |
+
repo_type="dataset",
|
| 39 |
+
allow_patterns=[
|
| 40 |
+
"README.md",
|
| 41 |
+
"data/questions.jsonl",
|
| 42 |
+
"scripts/export_hf_questions.py",
|
| 43 |
+
"scripts/upload_hf_dataset.py",
|
| 44 |
+
],
|
| 45 |
+
delete_patterns=[
|
| 46 |
+
"data/**",
|
| 47 |
+
"dataset/**",
|
| 48 |
+
"scripts/**",
|
| 49 |
+
],
|
| 50 |
+
commit_message=args.commit_message,
|
| 51 |
+
)
|
| 52 |
+
print(f"Uploaded {repo_root} to https://huggingface.co/datasets/{args.repo_id}")
|
| 53 |
+
return 0
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
if __name__ == "__main__":
|
| 57 |
+
raise SystemExit(main())
|