token-classification · clinical text · WASM · ~105 MB
The Stanford de-identifier is a PubMedBERT model fine-tuned on thousands of radiology reports and medical notes to detect protected health information (PHI): patient names, dates, hospital names, record IDs, phone numbers and more. Paste a note, see every PHI span highlighted — and redact it before it leaves the machine.
| Model | onnx-community/stanford-deidentifier-base-ONNX · original StanfordAIMI/stanford-deidentifier-base |
|---|---|
| Task | token-classification — per-token PHI labels over 7 categories + O |
| Architecture | PubMedBERT-base (uncased, biomedical vocabulary), fine-tuned on radiology reports + medical notes (MIDRC + i2b2-style data) |
| Params / dtype | 110M · q8 (8-bit quantized ONNX) |
| Backend | WebAssembly (CPU) — no GPU required |
| Download | ~105 MB, cached after first load |
| License | MIT (original weights) — ONNX conversion by onnx-community |
| Web APIs | Web Workers, Cache Storage (via Transformers.js), WebAssembly, CSS Custom Highlight API |
Paste a clinical note (or pick a sample). The model tags every token with one of seven PHI categories — Patient · Healthcare worker · Hospital · Date · ID · Phone · Vendor — then merges adjacent same-label tokens into spans. Switch the view to redact or hide in plain sight to see the de-identified output.
The de-identifier uses a flat per-token label scheme — no B-/I- prefixes. Each
WordPiece token gets one of seven PHI labels (or O for ordinary text), and adjacent
tokens with the same label merge into a span; single punctuation between same-label tokens
(“/”, “-”) is bridged so 1/1/2020 and 567-493-1234 stay whole. The chips below are
the real tokens the model flagged for your last run, with their confidences. Low-confidence tags
(below 0.8) are marked.
Clinical text is full of patient identifiers, and sharing or analysing it — for research, second opinions, model training, or just emailing a referral — usually requires manual redaction. Stanford's model automates the finding step, and running it in the browser means the raw text never leaves the device: no upload, no third party, no data-handling agreement.
The one-liner is the token-classification pipeline:
import { pipeline } from "@huggingface/transformers";
const tagger = await pipeline("token-classification", "onnx-community/stanford-deidentifier-base-ONNX", {
dtype: "q8",
});
const tokens = await tagger("Dr. Perez is reachable at 567-493-1234.", { aggregation_strategy: "none" });
// [{ entity: "HCW", score: 0.998, word: "dr" },
// { entity: "HCW", score: 0.995, word: "perez" },
// { entity: "PHONE", score: 0.991, word: "567" }, …]
The pipeline returns per-token labels with no character offsets, so this demo maps each token back to the original text with a case-insensitive cursor-walk (PubMedBERT lowercases), then merges flat same-label runs — bridging “/” and “-” so dates and phone numbers survive as one span. Everything runs in a Web Worker; the page never blocks.