Noul: P(has_lesion) Choice: HF ClassLabel Score: Mass Effect Box: Lesion Coordinates

Detect MRI lesions with calibrated System One judgments.

Pulls dynamic ClassLabel choices and visual exemplars directly from Hugging Face MRI datasets, then evaluates noul, choice, score, and box via TypeSafe Jev or local OpenJev vision models.

npx is-lesion --hf Hemg/Brain-Tumor-MRI-Dataset --row 0
MRI RADIOLOGY SYSTEM ONE WORKBENCH
HF ClassLabel Choices:
Ready — Pre-computed golden evaluation loaded
HF DATASET SLICES 4 SLICES

Test custom MRI scan (PNG / JPEG)

Axial T1-Weighted — Left Parietal Glioma
Brain MRI slice
01 / LESION DETECTION NOUL + CHOICE
LESION DETECTED P = 97.0%
has_lesion.noul: 0.97 Ground truth: glioma
02 / HF DATASET CHOICE CONF: 79%
03 / SEVERITY RUBRIC SCORE: 2.97 / 3.00
Level 3: Large prominent tumor with significant mass effect or midline shift
04 / CONFIDENCE TRIAGE GATE 740 ms
HIGH_CONFIDENCE_LESION_FINDING
Gate threshold: 0.65
LIVE TYPESAFE SYSTEM ONE PAYLOAD INSPECTOR (SPECULATIVE 4-PRIMITIVE FAN-OUT) input_tokens: 1254 | output_tokens: 107
Request: POST https://api.typesafe.ai/v1/systemone

            
Response: Calibrated answers

            
FIRST PRINCIPLES

Why System One primitives instead of generative prompt-and-parse?

Medical imaging triage requires calibrated probability distributions, explicit visual exemplars, and deterministic bounding boxes—not chatty prose.

Dynamic HF Choices

Dataset-Driven Choice Criteria

Instead of hardcoding class names, is-lesion queries the Hugging Face Datasets Server API to extract the dataset's ClassLabel schema and attaches real reference MRI slices directly inside the choice criteria.

Speculative Fan-Out

4 Primitives in 1 Request

Every MRI slice is evaluated against noul (binary presence), choice (lesion subtype), score (0–3 mass effect rubric), and box (normalized lesion coordinates) in a single HTTP round-trip.

Calibrated Confidence

Radiologist Escalation Gate

When diagnosis.confidence drops below your clinical threshold or two tumor subtypes compete closely in probability, code automatically routes the scan to ESCALATE_RADIOLOGIST_REVIEW.

EMPIRICAL BENCHMARK · N = 100 STRATIFIED MRI SLICES (500 EVALUATIONS)

TypeSafe Jev vs. Local OpenJev Vision Engines

Evaluated across Hemg/Brain-Tumor-MRI-Dataset (25 glioma, 25 meningioma, 25 notumor, 25 pituitary; excluding reference exemplars) via node scripts/bench-engines.mjs. Full raw telemetry in docs/data/benchmark-results.json.

SAMPLE COHORT
N = 100 (25/class)
75 tumor · 25 normal · 5 engines
JEV GATED BINARY ACC (≥0.65)
93.0% 86.0% 4-CLS
57% auto-triaged · 74.2% error catch
BEST CALIBRATION (JEV + EX)
4.9% ECE 0.0955 Brier
2.5× better calibrated than ONNX CLIP
EXEMPLAR ABLATION GAIN
+7.0% +16% GLIOMA
1 HF exemplar/choice vs. text-only Jev
ENGINE / EVALUATION MODE BINARY ACC SENS / SPEC BIN F1 4-CLASS / MAC-F1 BRIER / ECE ↓ GATED ACC (≥0.65) · COV ERR CATCH BOX / SCORE P50 / P95
TypeSafe Jev 1.14 (+ HF Exemplars)
engine: 'jev' · 1 ref image/class
84.0% 85.3% / 80.0% 88.9% 69.0% / 69.6% 0.0955 · 4.9% 93.0% bin · 86.0% 4c (57%) 74.2% Native box+score 165 / 273 ms
TypeSafe Jev 1.14 (Text-Only Criteria)
engine: 'jev-text' · 0 ref images
81.0% 81.3% / 80.0% 86.5% 62.0% / 62.2% 0.1113 · 7.1% 89.3% bin · 80.4% 4c (56%) 71.1% Native box+score 108 / 200 ms
OpenJev Local ONNX · CLIP (+ Exemplars)
engine: 'clip-exemplar' · ViT-B/32 cosine
89.0% 85.3% / 100% 92.1% 69.0% / 69.3% 0.0966 · 12.5% 94.1% bin · 82.4% 4c (17%) 90.3% None 95 / 257 ms
OpenJev Local ONNX · CLIP (Zero-Shot Text)
engine: 'clip-zeroshot' · text prompts only
75.0% 100% / 0.0% 85.7% 25.0% / 10.0% 0.2125 · 69.0% 75.0% bin · 25.0% 4c (100%) 0.0% None 106 / 217 ms
OpenJev In-Tree Exemplar Fingerprint
engine: 'openjev' · 0-dep byte histogram
88.0% 100% / 52.0% 92.6% 73.0% / 73.3% 0.1655 · 46.4% Escalates 100% (conf=0.38) 100% Heuristic 1 / 1 ms

Per-Class Subtype Recall & Confusion (N = 25 / class)

TP / TN / FP / FN
ENGINE GLIOMA MENING. NOTUMOR PITUITARY TP·TN·FP·FN
Jev 1.14 (+Ex) 76.0% 68.0% 76.0% 56.0% 64·20·5·11
Jev 1.14 (Text) 60.0% 60.0% 76.0% 52.0% 61·20·5·14
CLIP (+Ex) 52.0% 60.0% 100.0% 64.0% 64·25·0·11
CLIP (Zero-Shot) 0.0% 100.0% 0.0% 0.0% 75·0·25·0
OpenJev (0-dep) 72.0% 76.0% 52.0% 92.0% 75·13·12·0

Key Empirical & Calibration Findings

1. Multimodal Exemplar Grounding (+7.0% 4-Class, +16.0% Glioma): Passing 1 Hugging Face reference MRI asset per class into Jev's choice.criteria lifts glioma recall from 60% → 76%, lowers Expected Calibration Error from 7.1% → 4.9%, and boosts confidence-gated binary accuracy to 93.0% across 57% of scans.
2. Why Zero-Shot CLIP Collapses on Medical Scans (0% Specificity): Without visual exemplars, Xenova/clip-vit-base-patch32 predicts meningioma on all 100 slices (0% specificity, 69.0% ECE). However, switching CLIP from text prompts to visual exemplar cosine similarity (clip-exemplar) recovers 89.0% binary accuracy and 100% specificity offline in 95 ms.
3. Calibration & Spatial Grounding (Jev vs. Local Embeddings): While local exemplar embeddings match Jev on top-1 4-class choice (69.0%), only TypeSafe Jev provides calibrated epistemic confidence (4.9% ECE vs. 12.5%), continuous severity scoring (0..3), and native 2D lesion bounding boxes (box).
SYSTEM ARCHITECTURE

End-to-End Speculative Evaluation Pipeline

Hugging Face ClassLabel choices and visual reference assets flow into a single TypeSafe Jev jev-preview evaluation.

is-lesion TypeSafe System One Architecture Blueprint
PROGRAMMABLE COMMON SENSE

Three-line quick start in Node.js & CLI

Switch seamlessly between TypeSafe Jev (engine: 'jev'), local ONNX CLIP ('clip-exemplar'), local Ollama VLMs ('ollama'), or zero-dep fallback ('openjev').

Node.js / ESM src/index.js
import isLesion from 'is-lesion';

// 1. Evaluate a local MRI scan using HF dataset choices (TypeSafe Jev or local engine)
const scan = await isLesion('./brain-mri.jpg', {
  dataset: 'Hemg/Brain-Tumor-MRI-Dataset',
  engine: 'jev' // or 'clip-exemplar' | 'ollama' | 'openjev'
});

console.log(scan.lesion);        // true
console.log(scan.probability);   // 0.97
console.log(scan.choice);        // 'glioma'
console.log(scan.probabilities); // { glioma: 0.84, meningioma: 0.16, notumor: 0, pituitary: 0 }
console.log(scan.box);           // { top: 0.52, bottom: 0.8, left: 0.43, right: 0.64 }

// 2. Or evaluate any Hugging Face dataset row directly
const row = await isLesion.fromHF('Hemg/Brain-Tumor-MRI-Dataset', { row: 3000 });
console.log(row.choice, row.groundTruth); // 'meningioma', 'meningioma'
Direct HTTP API Payload POST /v1/systemone
curl https://api.typesafe.ai/v1/systemone \
  -H "Authorization: Bearer $TYPESAFE_API_KEY" \
  -H "TypeSafe-Danger-Zone-Images: true" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "jev-preview",
    "state": { "mri_scan": "mri-target-uuid" },
    "assets": {
      "mri-target-uuid": { "type": "image", "format": "jpg", "data_base64": "..." }
    },
    "questions": {
      "has_cancer": {
        "type": "noul",
        "instructions": "Does the MRI scan in `mri_scan` show a tumor or cancerous lesion?"
      },
      "diagnosis": {
        "type": "choice",
        "instructions": "Which category from the Hugging Face MRI dataset best matches `mri_scan`?",
        "criteria": {
          "glioma": "Intra-axial glioma tumor inside brain parenchyma...",
          "meningioma": "Extra-axial dural-based meningioma mass...",
          "notumor": "Healthy normal brain MRI scan with no tumor...",
          "pituitary": "Focal mass in the sellar pituitary region..."
        }
      },
      "lesion_box": {
        "type": "box",
        "instructions": "the tumor or abnormal mass in `mri_scan`"
      }
    }
  }'