Skip to main content

medeval-framework

PyPI version License: Apache 2.0 Python Support CI Pipeline

A rigorous, open-source Python evaluation framework designed to benchmark medical Large Language Models (LLMs) and PEFT/LoRA adapters for clinical accuracy, hallucination rates, model calibration, and safety.


📖 Table of Contents


🌟 Key Features

  • Multi-Dataset Benchmarks: Out-of-the-box loaders for standard medical datasets (MedQA, PubMedQA, MedMCQA, MMLU-Medical).
  • Dynamic Topic Filtering: Filter any benchmark dataset by medical domain or disease keyword on the fly (e.g. --topic "sickle", --topic "cardiac", --topic "renal").
  • Universal SOTA Connectors: Query local PyTorch weights, PEFT/LoRA adapters, OpenAI APIs (gpt-4o), or SOTA routers (OpenRouter) driving Claude 3.5 Sonnet, Llama 3.1 70B/405B, DeepSeek, and Gemini.
  • Dual Clinical Safety Audit:
    • Deterministic Checker: Pure-Python regex engine detecting explicit contraindications in Sickle Cell Disease and Cardiology.
    • Semantic Safety Net: Cross-encoder NLI hazard verification (SemanticSafetyChecker) flagging context-dependent medical risks.
  • NLI Hallucination Detection: Cross-encoder Natural Language Inference (NLIHallucinationDetector) evaluating prediction hypotheses against ground-truth clinical facts.
  • Advanced Calibration Suite: Vectorized Expected Calibration Error (ECE), Maximum Calibration Error (MCE), and Brier Score.
  • Multi-Format Export & Comparison: Export structured reports to JSON, Markdown tables (.md), or interactive HTML dashboards (.html), with built-in side-by-side model comparison tools (compare_reports).

⚙️ Installation

medeval-framework is available on PyPI:

# Core lightweight installation (NumPy & pure-Python engines)
pip install medeval-framework

# Full ML & NLP stack (Transformers, PyTorch, Datasets, PEFT, BERTScore)
pip install medeval-framework[nlp]

# Complete installation including development and test suites
pip install medeval-framework[all]

2. Install from Source

For development or contributing:

git clone https://github.com/TeslaInch/medeval-framework.git
cd medeval-framework
pip install -e ".[all]"

🚀 Quickstart

1. Command Line Interface (CLI)

Run evaluations directly from your terminal:

# Check version and available flags
medeval --version
medeval --help

# Evaluate OpenAI GPT-4o on MedQA
export OPENAI_API_KEY="your-api-key"
medeval --model gpt-4o --dataset medqa --limit 20 --output report.json

# Evaluate Claude 3.5 Sonnet or Llama 3.1 via AgentRouter with custom API flags
medeval \
  --model "agentrouter:claude-3-5-sonnet" \
  --api-key "your_agentrouter_key" \
  --api-base-url "https://agentrouter.ai/v1" \
  --dataset medqa \
  --output report_claude.html

# Evaluate a specialized PEFT adapter filtered specifically for Sickle Cell questions
medeval \
  --model "TeslaInch/scd-phi35-adapter-v8" \
  --dataset medqa \
  --topic "sickle" \
  --output sickle_cell_report.md

CLI Options Reference

Flag Description Default
--model (required) Model ID (HuggingFace repo, PEFT adapter, gpt-4o, agentrouter:..., openrouter:..., mock-...). -
--dataset (required) Benchmark dataset: medqa, pubmedqa, medmcqa, or mmlu_medical. -
--output (required) Target report filepath (.json, .md, or .html). -
--topic Filter dataset by topic keyword (e.g. sickle, cardiac, renal, diabetes). All
--api-key API Key override for OpenAI, AgentRouter, or OpenRouter models. Env var
--api-base-url Base URL override (e.g. https://agentrouter.ai/v1). Env var
--safety Safety audit checker: sickle_cell (default) or none. sickle_cell
--device PyTorch execution device (cpu, cuda:0, etc.). cpu
--limit Maximum number of samples to evaluate. All
--trust-remote-code Enable trust_remote_code=True for Hugging Face models. False

2. Python Orchestration API

Build custom evaluation pipelines in Python:

from medeval.benchmark import BenchmarkLoader
from medeval.models.openai_connector import OpenAIConnector
from medeval.runner import BenchmarkRunner
from medeval.safety import SickleCellSafetyChecker
from medeval.report import export_report_to_html, export_report_to_markdown

# 1. Load dataset with topic filtering (e.g. Cardiology questions)
loader = BenchmarkLoader(split="test", max_samples=20, topic="cardiac")
samples = loader.load_medqa()

# 2. Instantiate Model Connector (API Router or HuggingFace model)
model = OpenAIConnector(model_name="claude-3-5-sonnet", base_url="https://agentrouter.ai/v1")

# 3. Configure Safety Checker & Execute Benchmark
runner = BenchmarkRunner(model=model, safety_checker=SickleCellSafetyChecker(), ignore_errors=True)
report = runner.run(samples)

# 4. Export report as styled Markdown or HTML dashboard
export_report_to_markdown(report, "cardiology_report.md")
export_report_to_html(report, "cardiology_report.html")

3. Multi-Model Side-by-Side Comparison

Compare base models, fine-tuned adapters, and SOTA models in Python:

from medeval.comparison import export_comparison_to_markdown, load_reports_from_files

# Load evaluation reports
reports = load_reports_from_files(
    ["base_model_report.json", "sickle_cell_adapter_report.json", "sota_claude_report.json"]
)

# Export side-by-side comparative Markdown matrix
export_comparison_to_markdown(reports, "model_comparison_matrix.md")

📁 Repository Structure

medeval/
├── medeval/
│   ├── models/               # Model Connectors (HF, PEFT, OpenAI, AgentRouter, Mock)
│   ├── safety/               # Safety Checkers (SickleCell, Cardiology, Semantic, SafetySuite)
│   ├── accuracy.py           # Scorers (Exact Match, BERTScore F1)
│   ├── benchmark.py          # Loaders (MedQA, PubMedQA, MedMCQA, MMLU-Medical)
│   ├── calibration.py        # Calibration Suite (ECE, MCE, Brier Score)
│   ├── comparison.py         # Multi-Model Side-by-Side Comparison Engine
│   ├── hallucination.py      # NLI Cross-Encoder Hallucination Engine
│   ├── report.py             # Metric aggregation (JSON, Markdown, HTML exporters)
│   ├── runner.py             # BenchmarkRunner pipeline orchestrator
│   └── structures.py         # Data contracts (MedicalEvalSample & EvaluationReport)
├── tests/                    # 46 Unit & Integration Tests
├── pyproject.toml            # Ruff & Mypy configurations
├── setup.py                  # PyPI Packaging configuration
└── requirements.txt          # Package dependencies

🧪 Development & Testing

Ensure style alignment and type safety before submitting pull requests:

# Run full pytest test suite
pytest

# Run Ruff style & linting check
ruff check .

# Run Mypy static type verification
mypy medeval/

📄 License

This project is licensed under the Apache License 2.0. See the LICENSE file for details.

Metadata

Release files for medeval-framework 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for medeval-framework 0.1.8
File Size Uploaded Provenance
medeval_framework-0.1.8.tar.gz 72.2 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for medeval-framework 0.1.8
File Interpreter ABI Platform
medeval_framework-0.1.8-py3-none-any.whl Python 3 none any Details

Total release size: 131.3 kB

Release files / medeval_framework-0.1.8.tar.gz

Download URL medeval_framework-0.1.8.tar.gz
Size 72.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2bdc5100f5a4f477b72aff6e0fa501b5f3713328a4c28405dce192a769bb3b96
BLAKE2b-256 checksum
How to use checksums
12852627ef80f4df14027a1cf2e91dbfe0c36e82ac088f489f6cb082f334667c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 26, 2026.

Transparency log

Release files / medeval_framework-0.1.8-py3-none-any.whl

Download URL medeval_framework-0.1.8-py3-none-any.whl
Size 59.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fa9227066df9ac7c015122f976973504d9024a087a40f9e2992fe0c3e6b55326
BLAKE2b-256 checksum
How to use checksums
59eff7e54042fd15676ae79961a3d831dde9a6e7409adb028ca9895f92a886c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 26, 2026.

Transparency log

Security for medeval-framework 0.1.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for medeval_framework-0.1.8.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 26, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page