sungguk's picture
Release visual answerability benchmark v1.0.0
e1ced61 verified
Raw History Blame Contribute Delete
2.56 kB
"""MMR1-RL importer — composite multi-image rows with inferred provenance.
MMR1-RL aggregates several public benchmarks but does not expose trustworthy
row-level source IDs (``docs/01`` §3.2). Any source hint found on a row is
recorded as ``provenance.inferred_source`` and is never treated as a definitive
ID. Rows may carry multiple images; their order is preserved exactly and each
image is content-addressed separately (``docs/02`` §2).
Decontamination is required for every MMR1 row; that is enforced in P3, but the
importer records the composite approval gate so the policy is visible downstream.
"""
from __future__ import annotations
from collections.abc import Mapping
from typing import Any
from .base import (
ImageResolver,
ImageStore,
IngestError,
NormalizedItem,
Policy,
infer_open_answer_type,
make_item,
)
NAME = "mmr1_rl"
POLICY: Policy = "c2_train_candidate"
LICENSE_GATE = "mmr1_composite_terms"
ALLOWED_SPLIT = "train"
def normalize(
row: Mapping[str, Any],
images: ImageStore,
resolve: ImageResolver,
*,
revision: str,
split: str,
config: str = "default",
) -> NormalizedItem:
"""Normalize one MMR1-RL native row to a :class:`NormalizedItem`."""
if split != ALLOWED_SPLIT:
raise IngestError(f"mmr1_rl: only split {ALLOWED_SPLIT!r} may be ingested, got {split!r}")
question = str(row["problem"])
answer_raw = str(row["answer"])
answer_type = infer_open_answer_type(answer_raw)
image_refs = [str(r) for r in row["images"]]
if not image_refs:
raise IngestError(f"mmr1_rl: row {row.get('id', '?')!r} has no images")
image_paths: list[str] = []
image_sha: list[str] = []
for ref in image_refs:
rel, digest = images.store(resolve(ref))
image_paths.append(rel)
image_sha.append(digest)
inferred = row.get("source") or row.get("inferred_source")
extra = {"inferred_source": str(inferred) if inferred is not None else None}
native_id = str(row.get("id", row.get("index")))
return make_item(
source=NAME,
source_revision=revision,
source_config=config,
source_split=split,
source_native_id=native_id,
question=question,
choices=(),
answer_raw=answer_raw,
answer_canonical=answer_raw,
answer_type=answer_type,
image_paths=tuple(image_paths),
image_sha256=tuple(image_sha),
policy=POLICY,
native_row=row,
license_gate=LICENSE_GATE,
extra_provenance=extra,
)