Datasets:
File size: 5,523 Bytes
e1ced61 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | """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",
)
|