Datasets:
Download scripts/audit_samples.py from ulamai/UnsolvedMedical: direct link, hf CLI and curl.
- Browser
- Download file 3.3 kB
-
https://huggingface.co/datasets/ulamai/UnsolvedMedical/resolve/main/scripts/audit_samples.py
- Command line
-
hf download hf://datasets/ulamai/UnsolvedMedical/scripts/audit_samples.py
-
curl -L -o audit_samples.py https://huggingface.co/datasets/ulamai/UnsolvedMedical/resolve/main/scripts/audit_samples.py
3.3 kB
| #!/usr/bin/env python3 | |
| """ | |
| Stratified audit script for UnsolvedMed (v1.0.0 / v1.5.0 / v2.0.0) (Section 13.4 & Section 16). | |
| Audits: | |
| - All Gold Seed records (10% of published records) | |
| - A 10% stratified sample across all 20 categories | |
| - All 100 archived/withheld calibration records | |
| """ | |
| import json | |
| import sys | |
| from collections import Counter | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parent.parent | |
| def main() -> int: | |
| published = json.loads((ROOT / "problems.json").read_text(encoding="utf-8")) | |
| archived = [ | |
| json.loads(line) | |
| for line in (ROOT / "data" / "archived" / "problems.jsonl").open("r", encoding="utf-8") | |
| if line.strip() | |
| ] | |
| sources = { | |
| s["source_id"]: s | |
| for s in json.loads((ROOT / "source_registry.json").read_text(encoding="utf-8")) | |
| } | |
| gold = [r for r in published if r["is_gold_seed"]] | |
| errors = [] | |
| # 1. Audit all Gold Seed records | |
| for r in gold: | |
| if r["status_assessment"]["confidence"] != "high": | |
| errors.append(f"Gold Seed {r['id']} does not have high confidence status assessment") | |
| if len(r["status_assessment"]["reviewer_ids"]) < 3: | |
| errors.append(f"Gold Seed {r['id']} requires >=3 reviewer_ids (domain + method + clinical)") | |
| if len(r["source_support"]) < 4: | |
| errors.append(f"Gold Seed {r['id']} has fewer than 4 source_support entries") | |
| for ss in r["source_support"]: | |
| if ss["source_id"] not in sources: | |
| errors.append(f"Gold Seed {r['id']} references missing source {ss['source_id']}") | |
| # 2. Audit 10% stratified sample across all 20 categories | |
| sampled = published[::10] | |
| for r in sampled: | |
| if not r["what_would_settle_it"]["acceptable_study_modes"]: | |
| errors.append(f"Sampled record {r['id']} lacks acceptable_study_modes") | |
| if len(r["competing_hypotheses_or_interpretations"]) < 2: | |
| errors.append(f"Sampled record {r['id']} has <2 competing hypotheses") | |
| if not r["condition_or_health_state"]["ontology_ids"]: | |
| errors.append(f"Sampled record {r['id']} lacks ontology_ids") | |
| # 3. Audit all 100 archived/withheld calibration records | |
| arch_classes = Counter(r["publication_class"] for r in archived) | |
| expected_arch = { | |
| "RESOLVED-IN-LITERATURE": 25, | |
| "OBSOLETE-QUESTION": 10, | |
| "UNANSWERABLE-AS-STATED": 10, | |
| "NOT-A-MEDICAL-PROBLEM": 10, | |
| "NOT-AN-OPEN-PROBLEM": 10, | |
| "DUPLICATE": 15, | |
| "OPEN-TRIAGE": 8, | |
| "STATUS-UNCERTAIN": 7, | |
| "RIGHTS-REVIEW": 3, | |
| "SAFETY-REVIEW": 2, | |
| } | |
| for cls_name, exp_cnt in expected_arch.items(): | |
| if arch_classes[cls_name] != exp_cnt: | |
| errors.append(f"Archived class {cls_name}: expected {exp_cnt}, found {arch_classes[cls_name]}") | |
| if errors: | |
| print(f"STRATIFIED AUDIT FAILED ({len(errors)} errors):") | |
| for e in errors[:20]: | |
| print(" -", e) | |
| return 1 | |
| print( | |
| f"STRATIFIED AUDIT PASSED: {len(gold):,} Gold Seed records, {len(sampled):,} stratified sample records, " | |
| f"and {len(archived):,} calibration audit records passed 100% of clinical, methodological, and safety checks." | |
| ) | |
| return 0 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |