Datasets:
Download src/explicit_learning/ingest/mmmu.py from sungguk/visual-answerability: direct link, hf CLI and curl.
- Browser
- Download file 2.39 kB
-
https://huggingface.co/datasets/sungguk/visual-answerability/resolve/main/src/explicit_learning/ingest/mmmu.py
- Command line
-
hf download hf://datasets/sungguk/visual-answerability/src/explicit_learning/ingest/mmmu.py
-
curl -L -o mmmu.py https://huggingface.co/datasets/sungguk/visual-answerability/resolve/main/src/explicit_learning/ingest/mmmu.py
2.39 kB
| """MMMU importer — dev/validation rows, one config per subject. | |
| MMMU ships 30 subjects, each with a 5-row ``dev`` and 30-row ``validation`` | |
| split (``docs/01`` §3.3). The subject is the Hugging Face config name, recorded | |
| as ``source_config``. ``base_id`` is content-addressed (``docs/02`` §3.1) and | |
| therefore excludes ``source_config``: two MMMU rows share an ID only when their | |
| question, choices, and image family match — subject is metadata, not identity. | |
| Only ``dev`` and ``validation`` are ingested; these are *limited* train | |
| candidates that may enter silver training only after the full evaluation | |
| registry is frozen and an explicit allowlist clears them of eval collisions | |
| (enforced in P3). | |
| """ | |
| from __future__ import annotations | |
| from collections.abc import Mapping | |
| from typing import Any | |
| from .base import ( | |
| Choice, | |
| ImageResolver, | |
| ImageStore, | |
| IngestError, | |
| NormalizedItem, | |
| Policy, | |
| canonicalize_mc_answer, | |
| make_item, | |
| mc_choices, | |
| ) | |
| NAME = "mmmu" | |
| POLICY: Policy = "c2_train_candidate" | |
| ALLOWED_SPLITS = ("dev", "validation") | |
| def normalize( | |
| row: Mapping[str, Any], | |
| images: ImageStore, | |
| resolve: ImageResolver, | |
| *, | |
| revision: str, | |
| split: str, | |
| config: str = "default", | |
| ) -> NormalizedItem: | |
| """Normalize one MMMU native row to a :class:`NormalizedItem`.""" | |
| if split not in ALLOWED_SPLITS: | |
| raise IngestError(f"mmmu: only splits {ALLOWED_SPLITS} may be ingested, got {split!r}") | |
| question = str(row["question"]) | |
| option_texts = [str(o) for o in row["options"]] | |
| choices: list[Choice] = mc_choices(option_texts) | |
| 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)) | |
| subject = str(row.get("subject", config)) | |
| native_id = str(row.get("id", row.get("index"))) | |
| return make_item( | |
| source=NAME, | |
| source_revision=revision, | |
| source_config=subject, # MMMU config == subject | |
| source_split=split, | |
| source_native_id=native_id, | |
| question=question, | |
| choices=choices, | |
| answer_raw=answer_raw, | |
| answer_canonical=answer_canonical, | |
| answer_type="multiple_choice", | |
| image_paths=(rel,), | |
| image_sha256=(digest,), | |
| policy=POLICY, | |
| native_row=row, | |
| subject=subject, | |
| ) | |