Datasets:
Download src/robotics/benchmarks/erqa.py from Nabidnur/RoboRACE-Bench: direct link, hf CLI and curl.
- Browser
- Download file 2.67 kB
-
https://huggingface.co/datasets/Nabidnur/RoboRACE-Bench/resolve/main/src/robotics/benchmarks/erqa.py
- Command line
-
hf download hf://datasets/Nabidnur/RoboRACE-Bench/src/robotics/benchmarks/erqa.py
-
curl -L -o erqa.py https://huggingface.co/datasets/Nabidnur/RoboRACE-Bench/resolve/main/src/robotics/benchmarks/erqa.py
2.67 kB
| """ERQA (Embodied Reasoning QA, Gemini Robotics team, 2025): 400 multiple-choice questions over | |
| robot images (spatial, trajectory, action, state, task, multi-view reasoning, pointing). | |
| Data: HF mirror `FlagEval/ERQA` (converted from the official TFRecord). Images are interleaved | |
| into the question text at `visual_indices` (character offsets), as in the official evaluator. | |
| """ | |
| from __future__ import annotations | |
| import ast | |
| import io | |
| import re | |
| from pathlib import Path | |
| import numpy as np | |
| LETTERS = "ABCDEFGH" | |
| def load(path="data/erqa/test.parquet"): | |
| import pandas as pd | |
| from PIL import Image | |
| df = pd.read_parquet(path) | |
| items = [] | |
| for _, r in df.iterrows(): | |
| imgs = [Image.open(io.BytesIO(im["bytes"])).convert("RGB") for im in r["images"]] | |
| vis = list(r["visual_indices"]) if r["visual_indices"] is not None else [0] * len(imgs) | |
| if isinstance(vis, str): | |
| vis = ast.literal_eval(vis) | |
| opts = options(r["question"]) | |
| items.append({"id": r["question_id"], "question": r["question"], "type": r["question_type"], | |
| "answer": r["answer"].strip().upper()[:1], "images": imgs, "visual_indices": [int(v) for v in vis], | |
| "options": opts}) | |
| return items | |
| def options(question: str) -> str: | |
| """Letters offered in the question ('Choices: A. ... B. ...'); defaults to A-D.""" | |
| found = re.findall(r"(?:^|\s)([A-H])[\.\)]\s", question.split("Choices:")[-1] if "Choices:" in question else question) | |
| letters = "".join(sorted(set(found))) | |
| if len(letters) < 2: | |
| return "ABCD" | |
| return LETTERS[: LETTERS.index(letters[-1]) + 1] # fill gaps, e.g. "A. B. No. C. Yes." -> ABC(D) | |
| def interleave(item, suffix: str): | |
| """Chat content list with images inserted at their character offsets (official ERQA layout).""" | |
| q = item["question"] | |
| content, last = [], 0 | |
| for img, idx in sorted(zip(item["images"], item["visual_indices"]), key=lambda t: t[1]): | |
| idx = max(0, min(int(idx), len(q))) | |
| if q[last:idx].strip(): | |
| content.append({"type": "text", "text": q[last:idx]}) | |
| content.append({"type": "image", "image": img}) | |
| last = idx | |
| content.append({"type": "text", "text": q[last:] + suffix}) | |
| return content | |
| PROMPT_SUFFIX = "\nAnswer with the option's letter from the given choices directly." | |
| def accuracy_by_type(rows): | |
| out = {} | |
| for t in sorted({r["type"] for r in rows}): | |
| rs = [r for r in rows if r["type"] == t] | |
| out[t] = float(np.mean([r["pred"] == r["answer"] for r in rs])) | |
| out["overall"] = float(np.mean([r["pred"] == r["answer"] for r in rows])) | |
| return out | |