Datasets:
Download src/explicit_learning/ingest/mmk12.py from sungguk/visual-answerability: direct link, hf CLI and curl.
- Browser
- Download file 2.38 kB
-
https://huggingface.co/datasets/sungguk/visual-answerability/resolve/main/src/explicit_learning/ingest/mmk12.py
- Command line
-
hf download hf://datasets/sungguk/visual-answerability/src/explicit_learning/ingest/mmk12.py
-
curl -L -o mmk12.py https://huggingface.co/datasets/sungguk/visual-answerability/resolve/main/src/explicit_learning/ingest/mmk12.py
2.38 kB
| """MMK12 importer — math-only multiple-choice training rows. | |
| All 15,616 public MMK12 ``train`` rows are ``subject=math``; the importer asserts | |
| that invariant row-by-row. A non-math row is treated as source revision drift | |
| (a hard :class:`IngestError`), never silently kept or relabeled. Only ``train`` | |
| is ingested; the 2,000-row source ``test`` split never enters training | |
| (``docs/01_RESOURCE_CATALOG.md`` §3.1). | |
| """ | |
| 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 = "mmk12" | |
| POLICY: Policy = "c2_train_candidate" | |
| LICENSE_GATE = "mmk12_license" | |
| ALLOWED_SPLIT = "train" | |
| REQUIRED_SUBJECT = "math" | |
| def normalize( | |
| row: Mapping[str, Any], | |
| images: ImageStore, | |
| resolve: ImageResolver, | |
| *, | |
| revision: str, | |
| split: str, | |
| config: str = "default", | |
| ) -> NormalizedItem: | |
| """Normalize one MMK12 native row to a :class:`NormalizedItem`.""" | |
| if split != ALLOWED_SPLIT: | |
| raise IngestError(f"mmk12: only split {ALLOWED_SPLIT!r} may be ingested, got {split!r}") | |
| subject = str(row.get("subject", "")).strip() | |
| if subject != REQUIRED_SUBJECT: | |
| raise IngestError( | |
| f"mmk12: row {row.get('index', '?')!r} subject is {subject!r}, expected " | |
| f"{REQUIRED_SUBJECT!r} — source revision drift" | |
| ) | |
| 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)) | |
| native_id = str(row.get("index", row.get("id"))) | |
| return make_item( | |
| source=NAME, | |
| source_revision=revision, | |
| source_config=config, | |
| 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, | |
| license_gate=LICENSE_GATE, | |
| ) | |