Back to .md Directory

evaluation/ — Evaluation Skill

Defines an offline evaluation framework that tests a WHO IMCI classification system against 20+ golden scenarios and produces versioned accuracy reports.

May 2, 2026
0 downloads
0 views
ai prompt eval
View source

What this file does

Defines an offline evaluation framework that tests a WHO IMCI classification system against 20+ golden scenarios and produces versioned accuracy reports.

When to use it

  • You need to validate a clinical decision support system against a known-correct reference set
  • You want to enforce that every classification path in your system is exercised by at least one test case
  • You require regression detection and versioned accuracy reports before milestones
  • You have layered test levels (protocol-only, perception, end-to-end) with different hardware requirements

Assumes this stack

PythonWHO IMCI protocol

evaluation/ — Evaluation Skill

If it's not measured, it's not accurate. Ship blind and children pay the price.


What This Module Does

Provides offline evaluation of the entire Malaika system against a golden dataset of 20+ WHO IMCI clinical scenarios with known-correct classifications.

This module provides:

  • Golden scenarios (golden_scenarios.py): 20+ test cases with expected WHO classifications
  • Evaluator (evaluator.py): Run model against golden set, produce accuracy reports

The evaluation framework answers one question: "Does Malaika classify this child correctly according to WHO IMCI?"

What This Module Does NOT Do

  • Does NOT define WHO thresholds (that's imci_protocol.py)
  • Does NOT run unit tests (that's tests/)
  • Does NOT train models (that's scripts/)
  • Does NOT replace manual clinical validation

Rules

R1: Golden Scenarios Are Ground Truth

Each scenario has a known-correct classification derived from the WHO IMCI Chart Booklet. These are not opinions — they are the protocol. If the system disagrees with a golden scenario, the system is wrong.

R2: Scenarios Cover All Classification Paths

Every ClassificationType in types.py must be exercised by at least one golden scenario. No dead paths.

R3: Scenarios Are Layered

Three levels of scenarios:

LevelWhat It TestsExample
Protocol-onlyimci_protocol.py with hardcoded inputsclassify_breathing(rate=55, age=6) -> PNEUMONIA
Perception + ProtocolGemma 4 output parsing + protocol logicImage of chest indrawing -> parse -> classify
End-to-endFull IMCI flow from raw media to classificationVideo + audio + text -> complete assessment

Protocol-only scenarios run fast (no GPU). Perception scenarios need mock inference. End-to-end needs real model.

R4: Every Scenario Documents Its WHO Source

Each scenario cites the specific WHO IMCI Chart Booklet page or decision table that defines the expected classification.

GoldenScenario(
    name="fast_breathing_infant",
    description="55 breaths/min in 6-month-old with cough",
    who_source="IMCI Chart Booklet, p.5: Breathing thresholds by age",
    ...
)

R5: Accuracy Reports Are Versioned

Each evaluation run produces a dated report with:

  • Model version / adapter version
  • Prompt versions used (from traces)
  • Per-scenario pass/fail
  • Aggregate accuracy by category (breathing, diarrhea, fever, etc.)
  • Regression detection (did accuracy drop since last run?)

R6: Run Evaluation Before Every Milestone

Before Phase 2, 3, 4, and submission milestones — run the full golden set. No exceptions. Results go in the writeup.


Golden Scenario Format

@dataclass(frozen=True)
class GoldenScenario:
    """A single evaluation scenario with known-correct WHO classification."""

    # Identity
    name: str                       # Unique snake_case identifier
    description: str                # Human-readable scenario description
    who_source: str                 # WHO IMCI citation

    # Input (what the child presents with)
    age_months: int
    findings: dict[str, Any]        # Structured findings per IMCI step
    # e.g., {"breathing_rate": 55, "has_indrawing": True, "has_wheeze": False}

    # Expected output
    expected_classifications: list[ClassificationType]
    expected_severity: Severity
    expected_referral: ReferralUrgency

    # Test level
    level: str = "protocol"  # "protocol", "perception", "e2e"

    # Optional: media paths for perception/e2e tests
    test_image: str | None = None
    test_audio: str | None = None
    test_video: str | None = None

Minimum Scenario Coverage

IMCI DomainMin ScenariosMust Cover
Danger signs3Lethargic, convulsions, unable to drink
Breathing4Normal, fast, indrawing, stridor
Diarrhea4None, some dehydration, severe, dysentery
Fever3No fever, malaria risk, very severe febrile
Nutrition3Normal, moderate wasting, severe + edema
Heart (MEMS)1Normal (or disabled path)
Combined3Multi-domain scenarios (e.g., pneumonia + dehydration)
Total21+

Running Evaluation

# Protocol-only (fast, no GPU)
python -m malaika.evaluation.evaluator --level protocol

# With perception mocks (moderate, no GPU)
python -m malaika.evaluation.evaluator --level perception

# Full end-to-end (slow, needs GPU)
python -m malaika.evaluation.evaluator --level e2e

# Generate report
python -m malaika.evaluation.evaluator --level protocol --report reports/eval_$(date +%Y%m%d).json

File Inventory

FileComponentResponsibility
__init__.pyModuleExports GoldenScenario, Evaluator
golden_scenarios.pyGolden Set20+ scenarios with expected WHO classifications
evaluator.pyEvaluatorRun scenarios, compare results, produce accuracy report

What's inside

3 files: golden scenarios, evaluator, and module init; plus 6 rules, 1 scenario format, 1 coverage table, and 4 run commands.

Change this for your project

  • Replace malaika.evaluation.evaluator with your own module path in run commands
  • Replace GoldenScenario dataclass fields like expected_classifications: list[ClassificationType] with your own classification types
  • Replace ClassificationType and Severity and ReferralUrgency with your project's enums
  • Replace IMCI Chart Booklet, p.5 citations with your own protocol references

Where it goes

Keep alongside your test suite. Used to define and score model evaluations.

Worth borrowing

  • Layered test levels (protocol-only, perception, e2e) let you run fast checks without GPU and reserve full tests for milestones
  • Requiring every classification path to have at least one golden scenario prevents dead code and untested branches
  • Versioned accuracy reports with regression detection make it easy to catch regressions introduced by changes

Related Documents