Datasets:
Download scripts/build_strict_release.py from Medical-Doctors-Last-Exam/mdle: direct link, hf CLI and curl.
- Browser
- Download file 16.7 kB
-
https://huggingface.co/datasets/Medical-Doctors-Last-Exam/mdle/resolve/main/scripts/build_strict_release.py
- Command line
-
hf download hf://datasets/Medical-Doctors-Last-Exam/mdle/scripts/build_strict_release.py
-
curl -L -o build_strict_release.py https://huggingface.co/datasets/Medical-Doctors-Last-Exam/mdle/resolve/main/scripts/build_strict_release.py
16.7 kB
| #!/usr/bin/env python3 | |
| """Build v1.3.0 from the pinned v1.2.1 release, without regrading questions.""" | |
| from __future__ import annotations | |
| import argparse | |
| import copy | |
| import hashlib | |
| import json | |
| import math | |
| import shutil | |
| from collections import Counter | |
| from datetime import datetime, timezone | |
| from pathlib import Path | |
| import pyarrow as pa | |
| from datasets import Dataset, Features, Image, List as HFList | |
| PROJECT = Path(__file__).resolve().parent | |
| SOURCE_REPO = "Medical-Doctors-Last-Exam/mdle" | |
| SOURCE_REVISION = "de82a49729ee38215493d6e268468702406fa1bb" | |
| SOURCE_SHA256 = "2d5b170bad1c65f772e384a5abd7b06994e4152ae572fbfb3c72373b615b8e2d" | |
| VERSION = "1.3.0" | |
| JSONL = "data/challenge_2026_03_07.jsonl" | |
| PARQUET = "data/test-00000-of-00001.parquet" | |
| RULE = "gemini_closed_book_score < 6 AND opus_closed_book_score < 6" | |
| MODELS = ["gemini-3.1-pro-preview", "anthropic.claude-opus-5"] | |
| def digest(path: Path) -> str: | |
| return hashlib.sha256(path.read_bytes()).hexdigest() | |
| def write_json(path: Path, value: object) -> None: | |
| path.parent.mkdir(parents=True, exist_ok=True) | |
| path.write_text(json.dumps(value, indent=2, ensure_ascii=False) + "\n") | |
| def scores(row: dict) -> tuple[float, float]: | |
| evaluation = row["evaluation"] | |
| values = (evaluation["closed_book"]["score"], evaluation["opus_closed_book_recheck"]["score"]) | |
| if any(isinstance(v, bool) or not isinstance(v, (int, float)) or not math.isfinite(v) or not 0 <= v <= 10 for v in values): | |
| raise ValueError(f"Missing or invalid score for {row['item_key']}") | |
| return values | |
| def eligible(row: dict) -> bool: | |
| return all(value < 6 for value in scores(row)) | |
| def write_parquet(rows: list[dict], root: Path) -> None: | |
| # Merge every row's schema so the sparse March grading fields survive. | |
| schema = pa.unify_schemas([pa.Table.from_pylist([row]).schema for row in rows], promote_options="permissive") | |
| features = dict(Features.from_arrow_schema(schema)) | |
| features["images"] = HFList(Image()) | |
| viewer_rows = [] | |
| for row in rows: | |
| viewer_rows.append({**row, "images": [{"path": path, "bytes": (root / path).read_bytes()} for path in row["input_assets"]]}) | |
| Dataset.from_list(viewer_rows, features=Features(features)).to_parquet(root / PARQUET) | |
| def build(source: Path, assets: Path, output: Path, repo_id: str) -> dict: | |
| if output.exists(): | |
| raise FileExistsError(f"Refusing to overwrite release: {output}") | |
| if digest(source / JSONL) != SOURCE_SHA256: | |
| raise ValueError("Source JSONL is not the pinned v1.2.1 release") | |
| checksums = {} | |
| for line in (source / "metadata/checksums.sha256").read_text().splitlines(): | |
| sha, path = line.split(maxsplit=1) | |
| checksums[path] = sha | |
| for name in [JSONL, "LICENSE.md", "metadata/selection_manifest.json", "metadata/source_catalog.json"]: | |
| if digest(source / name) != checksums[name]: | |
| raise ValueError(f"Source checksum mismatch: {name}") | |
| original = [json.loads(line) for line in (source / JSONL).read_text().splitlines() if line] | |
| if len(original) != 489 or len({r["item_key"] for r in original}) != 489: | |
| raise ValueError("Expected 489 unique parent records") | |
| rows = copy.deepcopy([row for row in original if eligible(row)]) | |
| if len(rows) != 357: | |
| raise ValueError(f"Expected 357 strict records, got {len(rows)}") | |
| keys = {r["item_key"] for r in rows} | |
| source_ids = {r["source"]["source_id"] for r in rows} | |
| dois = {r["source"]["doi"] for r in rows} | |
| asset_paths = sorted({p for r in rows for p in r["input_assets"]}) | |
| for row in rows: | |
| row["selection"] = { | |
| "split": "challenge_2026_03_07", "dataset_version": VERSION, | |
| "label": "dual_model_failure", "inclusion_reason": "all_evaluated_models_strictly_below_6", | |
| "is_primary_dual_model_failure": True, | |
| "linked_dual_model_failure_item_keys": [], "primary_rule": RULE, | |
| "linked_q1_rule": "disabled; Q1 must independently satisfy the strict score rule", | |
| "threshold": 6, "comparison_operator": "<", "threshold_inclusive": False, | |
| "max_score": 10, "required_models": MODELS, | |
| "score_scope": "closed_book", "scores_question_version": "1.1.0", | |
| "source_dataset_version": "1.2.1", "source_revision": SOURCE_REVISION, | |
| } | |
| output.mkdir(parents=True) | |
| (output / "data").mkdir() | |
| (output / "metadata").mkdir() | |
| for path in asset_paths: | |
| if Path(path).is_absolute() or ".." in Path(path).parts or not path.startswith("assets/"): | |
| raise ValueError(f"Unsafe asset path: {path}") | |
| if digest(assets / path) != checksums[path]: | |
| raise ValueError(f"Asset checksum mismatch: {path}") | |
| target = output / path | |
| target.parent.mkdir(parents=True, exist_ok=True) | |
| shutil.copy2(assets / path, target) | |
| for name in ["LICENSE.md", ".gitattributes"]: | |
| shutil.copy2(source / name, output / name) | |
| (output / JSONL).write_text("".join(json.dumps(row, ensure_ascii=False) + "\n" for row in rows)) | |
| write_parquet(rows, output) | |
| manifest = json.loads((source / "metadata/selection_manifest.json").read_text()) | |
| manifest["dataset_version"] = VERSION | |
| manifest["created_at"] = datetime.now(timezone.utc).isoformat() | |
| manifest["parent_release"] = { | |
| "repo_id": SOURCE_REPO, "version": "1.2.1", "revision": SOURCE_REVISION, | |
| "jsonl_sha256": SOURCE_SHA256, "questions": 489, | |
| "source_corpora_note": "Inherited upstream acquisition and scoring metadata; current inclusion is defined in selection.", | |
| } | |
| manifest["question_simplification"]["questions_rewritten_in_parent_release"] = manifest["question_simplification"]["questions_rewritten"] | |
| manifest["question_simplification"]["questions_rewritten"] = len(rows) | |
| manifest["question_simplification"]["note"] = "Retained v1.2.1 prompts and rewrite audits unchanged; this release only filters records and changes selection metadata." | |
| manifest["selection"] = { | |
| "primary_rule": RULE, "threshold": 6, "comparison_operator": "<", "threshold_inclusive": False, | |
| "required_models": MODELS, "score_scope": "closed_book", "max_score": 10, | |
| "linked_q1_rule": "disabled; no contextual inclusion exceptions", | |
| "questions": len(rows), "primary_dual_model_failures": len(rows), "linked_q1_context_questions": 0, | |
| "unique_source_articles": len(source_ids), "questions_with_images": sum(bool(r["input_assets"]) for r in rows), | |
| "text_only_questions": sum(not r["input_assets"] for r in rows), "assets": len(asset_paths), | |
| "by_month": dict(sorted(Counter(r["month"] for r in rows).items())), | |
| "correctness_counts": {"gemini_right": 0, "gemini_wrong": len(rows), "opus_right": 0, "opus_wrong": len(rows)}, | |
| "historical_correctness_passing_score": 7, | |
| "scores_question_version": "1.1.0", "models_rerun": False, | |
| "excluded_from_parent": len(original) - len(rows), | |
| "excluded_primary_questions": 113, "excluded_linked_q1_context_questions": 19, | |
| } | |
| manifest["items"] = [item for item in manifest["items"] if item["item_key"] in keys] | |
| for item in manifest["items"]: | |
| item["selection_label"] = "dual_model_failure" | |
| item["linked_dual_model_failure_item_keys"] = [] | |
| item["selection_threshold"] = 6 | |
| item["selection_comparison_operator"] = "<" | |
| write_json(output / "metadata/selection_manifest.json", manifest) | |
| catalog = json.loads((source / "metadata/source_catalog.json").read_text()) | |
| write_json(output / "metadata/source_catalog.json", {doi: catalog[doi] for doi in sorted(dois)}) | |
| excluded = [{"item_key": r["item_key"], "gemini_closed_book_score": scores(r)[0], "opus_closed_book_score": scores(r)[1], | |
| "parent_selection_label": r["selection"]["label"], "reason": "at_least_one_closed_book_score_is_6_or_higher"} | |
| for r in original if r["item_key"] not in keys] | |
| write_json(output / "metadata/selection_changes.json", { | |
| "version": VERSION, "parent_version": "1.2.1", "parent_revision": SOURCE_REVISION, | |
| "rule": RULE, "retained_item_keys": [r["item_key"] for r in rows], "excluded_items": excluded, | |
| "retained_content_changes": "Only selection fields changed; questions, answers, rubrics, evaluations, correctness and rewrite audits are identical to the parent release.", | |
| }) | |
| readme = f'''--- | |
| language: | |
| - en | |
| license: other | |
| pretty_name: "MDLE: Case-Report Challenge Set" | |
| task_categories: | |
| - question-answering | |
| size_categories: | |
| - n<1K | |
| tags: | |
| - medical | |
| - clinical-reasoning | |
| - multimodal | |
| - benchmark | |
| - evaluation | |
| configs: | |
| - config_name: default | |
| data_files: | |
| - split: test | |
| path: {PARQUET} | |
| --- | |
| # MDLE: Case-Report Challenge Set — v{VERSION} | |
| **357 questions · strict closed-book score < 6/10 for every evaluated solver model · no score of 6 included.** | |
| This research challenge set is part of [Medical Doctor's Last Exam](https://www.medlastexam.org), an independent clinical-reasoning benchmark maintained by the [MDLE organization](https://huggingface.co/Medical-Doctors-Last-Exam). It contains 357 English questions from 350 case-report articles in the March–July 2026 collection: 194 questions use images and 163 are text-only. The release bundles 235 original image crops. Collection months are inherited source-group labels, not a guarantee that every article's publication date falls in that month. | |
| ## Selection | |
| Every included question satisfies both conditions: | |
| ```text | |
| {RULE} | |
| ``` | |
| The evaluated solvers are **Gemini 3.1 Pro Preview** (`gemini-3.1-pro-preview`) and **Claude Opus 5** (`anthropic.claude-opus-5`). “Every model” means these two existing closed-book evaluations. Source-assisted scores and judge models are not additional solver evaluations for this rule. Both scores must be present and valid. A score of **6 is excluded**; there is no rounding, averaging, or less-than-or-equal comparison. The highest retained score for either model is 5.5/10. | |
| There are **no linked-Q1 exceptions**. A Q1 is included only if its own two scores satisfy the strict rule. Compared with v1.2.1, this release retains 357 of 489 questions and removes 132: 113 former primary questions and all 19 supplemental Q1 context questions. The full retained/excluded item audit is in [selection_changes.json](metadata/selection_changes.json). | |
| | Collection month | Questions | | |
| | --- | ---: | | |
| | 2026-03 | 42 | | |
| | 2026-04 | 101 | | |
| | 2026-05 | 90 | | |
| | 2026-06 | 90 | | |
| | 2026-07 | 34 | | |
| ## Score and prompt versions | |
| The selection threshold is **6**, using a strict `<` comparison. Historical `evaluation` and `correctness` fields are preserved from v1.2.1, including their original **passing score of 7**. That historical grading threshold is distinct from this release's inclusion threshold, recorded in `selection.threshold`. Scores are out of 10. | |
| The model scores were produced on the original **v1.1.0 prompts**. They were not rerun for v1.2.x or v1.3.0. This release preserves the **v1.2.1 active prompts, reference answers, rubrics, original prompts and rewrite audits unchanged**. For `q02-fae0fd6e965a8cff`, it retains the expert-reviewed injury-depth target and single-target rubric; the stored 0/10 scores still describe the earlier v1.1.0 two-target question. | |
| The March source includes the Opus answer and detailed grading. The April–July Opus artifact contains only its scalar score, without the raw answer or detailed judge rationale. All retained rows carry historical `wrong` labels for both models; these are rubric-threshold labels, not claims that every statement in an answer is false. | |
| ## Files and use | |
| - [{PARQUET}]({PARQUET}): the `default` configuration and `test` split, with native Hugging Face `List[Image]` features and embedded image bytes. | |
| - [{JSONL}]({JSONL}): the same 357 records as nested JSON Lines, without embedded image bytes. | |
| - `assets/`: the 235 required image crops; each row retains their repository-relative paths in `input_assets`. | |
| - [selection_manifest.json](metadata/selection_manifest.json): current selection rule, counts, model identities, historical source metadata and per-item provenance. | |
| - [selection_changes.json](metadata/selection_changes.json): retained IDs and all 132 exclusions with the two scores. | |
| - [source_catalog.json](metadata/source_catalog.json): the 350 retained sources, citations, DOIs and article/PDF links. | |
| - [checksums.sha256](metadata/checksums.sha256): SHA-256 checksums for every release file except the checksum file itself. | |
| - [build_strict_release.py](scripts/build_strict_release.py): reproducible builder, including the pinned parent revision and strict predicate. | |
| ```python | |
| from datasets import load_dataset | |
| dataset = load_dataset( | |
| "{repo_id}", | |
| revision="v{VERSION}", | |
| split="test", | |
| ) | |
| ``` | |
| Each record includes the question, golden answer, reasoning, rubric, evidence, taxonomy, source identity, historical evaluations, correctness labels, current selection provenance, and the v1.2.x rewrite audit. The historical `question_text_original` is kept beside the active `question_text`. | |
| ## Rebuild | |
| Download the complete parent snapshot at revision `{SOURCE_REVISION}` to `parent-v1.2.1/`, including its image assets. After downloading this release, run from its root directory: | |
| ```bash | |
| python -m pip install -r scripts/requirements.txt | |
| python scripts/build_strict_release.py \\ | |
| --source ../parent-v1.2.1 \\ | |
| --assets ../parent-v1.2.1 \\ | |
| --output ../rebuilt-v1.3.0 \\ | |
| --repo-id {repo_id} | |
| ``` | |
| The builder verifies parent and image checksums and refuses to overwrite the output directory. Record content and item membership are deterministic; the manifest creation timestamp and its checksum change on each rebuild. | |
| ## Version history | |
| - **v{VERSION}**: strict two-model `<6/10` subset; 357 questions; no linked-Q1 exceptions; no rewording or reevaluation. | |
| - **v1.2.1**: 489 questions; expert correction of the injury-depth target and rubric for `q02-fae0fd6e965a8cff`. | |
| - **v1.2.0**: clearer active wording for all 489 questions, with original wording and audits retained. | |
| - **v1.1.0**: 470 questions with both closed-book scores `<7/10`, plus 19 linked Q1 context questions. | |
| Parent dataset: [{SOURCE_REPO}](https://huggingface.co/datasets/{SOURCE_REPO}/tree/{SOURCE_REVISION}), revision `{SOURCE_REVISION}`. The parent JSONL SHA-256 is `{SOURCE_SHA256}`. Historical version tags remain available; pin a tag or full commit for reproducibility. | |
| ## Limitations and rights | |
| This is a deliberately difficult, model-selected set derived from case reports, not a representative sample of clinical questions or a licensing examination. Gemini 3.1 Pro Preview served as both an original solver and judge, including judging the Opus answers; selection may therefore reflect judge-specific bias. The historical scores are not current performance measurements or a general model ranking. | |
| Original article PDFs are not redistributed. Source articles and images retain their authors' and publishers' rights; article licenses vary. The dataset retains source hashes and official links. See [LICENSE.md](LICENSE.md). This benchmark is for research evaluation, not patient-care decisions. | |
| ## Citation | |
| Until the accompanying Medical Doctor's Last Exam paper is available, cite the dataset repository URL with version **v{VERSION}** and the resolved commit. | |
| ''' | |
| (output / "README.md").write_text(readme) | |
| (output / "scripts").mkdir() | |
| shutil.copy2(Path(__file__), output / "scripts/build_strict_release.py") | |
| (output / "scripts/requirements.txt").write_text("datasets==4.8.5\npyarrow==25.0.1\npillow==12.3.0\n") | |
| files = sorted(p for p in output.rglob("*") if p.is_file()) | |
| (output / "metadata/checksums.sha256").write_text("".join(f"{digest(p)} {p.relative_to(output).as_posix()}\n" for p in files)) | |
| return {"version": VERSION, "repo_id": repo_id, "questions": len(rows), "source_articles": len(source_ids), | |
| "assets": len(asset_paths), "with_images": 194, "text_only": 163, "excluded": len(excluded), | |
| "jsonl_sha256": digest(output / JSONL), "parquet_sha256": digest(output / PARQUET), "output": str(output)} | |
| if __name__ == "__main__": | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("--source", type=Path, default=PROJECT / "releases/source-v1.2.1") | |
| parser.add_argument("--assets", type=Path, default=PROJECT / "release") | |
| parser.add_argument("--output", type=Path, default=PROJECT / "releases/v1.3.0") | |
| parser.add_argument("--repo-id", default=SOURCE_REPO) | |
| args = parser.parse_args() | |
| print(json.dumps(build(args.source, args.assets, args.output, args.repo_id), indent=2)) | |