sungguk's picture
Release visual answerability benchmark v1.0.0
e1ced61 verified
Raw History Blame Contribute Delete
5.52 kB
"""Evaluation-source importers for the Stage 0 registry freeze.
These import the *evaluation* sources (``docs/01`` §4) to the registry before
any training source is touched. MMMU-Pro, MathVision, and MathVista are visual
and produce :class:`NormalizedItem` rows; text MMLU-Pro is an image-free
``untouched`` retention probe and is recorded directly as a text registry row
(``docs/02`` §3).
MathVista is strictly evaluation-only. It is imported here under the
``untouched_evaluation_only`` policy; the train ingest driver separately
hard-refuses any attempt to ingest it as a training source.
"""
from __future__ import annotations
from collections.abc import Mapping
from typing import Any
from .base import (
AnswerType,
Choice,
ImageResolver,
ImageStore,
IngestError,
NormalizedItem,
canonicalize_mc_answer,
infer_open_answer_type,
make_item,
mc_choices,
text_registry_row,
)
# --- MMMU-Pro (10-option multiple choice, visual) ---------------------------
def normalize_mmmu_pro(
row: Mapping[str, Any],
images: ImageStore,
resolve: ImageResolver,
*,
revision: str,
split: str,
config: str = "standard (10 options)",
) -> NormalizedItem:
if split != "test":
raise IngestError(f"mmmu_pro: only split 'test' may be frozen, got {split!r}")
question = str(row["question"])
choices: list[Choice] = mc_choices([str(o) for o in row["options"]])
answer_raw = str(row["answer"])
answer_canonical = canonicalize_mc_answer(answer_raw, choices)
image_ref = str(row["image"])
rel, digest = images.store(resolve(image_ref))
return make_item(
source="mmmu_pro",
source_revision=revision,
source_config=config,
source_split=split,
source_native_id=str(row["id"]),
question=question,
choices=choices,
answer_raw=answer_raw,
answer_canonical=answer_canonical,
answer_type="multiple_choice",
image_paths=(rel,),
image_sha256=(digest,),
policy="untouched_evaluation_only",
native_row=row,
subject=str(row.get("subject", "")) or None,
)
# --- MathVision (open-ended, visual) ----------------------------------------
def normalize_mathvision(
row: Mapping[str, Any],
images: ImageStore,
resolve: ImageResolver,
*,
revision: str,
split: str,
config: str = "default",
) -> NormalizedItem:
if split != "testmini":
raise IngestError(f"mathvision: only split 'testmini' may be frozen, got {split!r}")
question = str(row["question"])
answer_raw = str(row["answer"])
rel, digest = images.store(resolve(str(row["image"])))
return make_item(
source="mathvision",
source_revision=revision,
source_config=config,
source_split=split,
source_native_id=str(row["id"]),
question=question,
choices=(),
answer_raw=answer_raw,
answer_canonical=answer_raw,
answer_type=infer_open_answer_type(answer_raw),
image_paths=(rel,),
image_sha256=(digest,),
policy="untouched_evaluation_only",
native_row=row,
)
# --- MathVista (mixed MC/open, visual, evaluation-only) ---------------------
def normalize_mathvista(
row: Mapping[str, Any],
images: ImageStore,
resolve: ImageResolver,
*,
revision: str,
split: str,
config: str = "default",
) -> NormalizedItem:
if split != "testmini":
raise IngestError(f"mathvista: only split 'testmini' may be frozen, got {split!r}")
question = str(row["question"])
answer_raw = str(row["answer"])
image_ref = str(row["image"])
rel, digest = images.store(resolve(image_ref))
raw_choices = row.get("choices")
choices: tuple[Choice, ...]
answer_canonical: str | int | bool
answer_type: AnswerType
if raw_choices:
choices = tuple(mc_choices([str(c) for c in raw_choices]))
answer_canonical = canonicalize_mc_answer(answer_raw, choices)
answer_type = "multiple_choice"
else:
choices = ()
answer_canonical = answer_raw
answer_type = infer_open_answer_type(answer_raw)
return make_item(
source="mathvista",
source_revision=revision,
source_config=config,
source_split=split,
source_native_id=str(row["id"]),
question=question,
choices=choices,
answer_raw=answer_raw,
answer_canonical=answer_canonical,
answer_type=answer_type,
image_paths=(rel,),
image_sha256=(digest,),
policy="untouched_evaluation_only",
native_row=row,
)
# --- text MMLU-Pro (image-free, untouched retention probe) ------------------
def registry_row_mmlu_pro_text(
row: Mapping[str, Any],
*,
revision: str,
split: str = "test",
config: str = "default",
) -> dict[str, Any]:
if split != "test":
raise IngestError(f"mmlu_pro_text: only split 'test' may be frozen, got {split!r}")
choices = mc_choices([str(o) for o in row["options"]])
answer = str(row["answer"])
answer_canonical = canonicalize_mc_answer(answer, choices)
return text_registry_row(
source="mmlu_pro_text",
source_revision=revision,
config=config,
split=split,
native_id=str(row["id"]),
question=str(row["question"]),
choices=choices,
answer_canonical=answer_canonical,
policy="untouched_evaluation_only",
)