← geetpurohit.com

Route a Clinical Note

A free-text medical note comes in. This model reads it and does three things a clinical-NLP pipeline actually has to do: routes it to the right specialty, extracts the clinical entities (with negation, so denies chest pain is not the same as chest pain), and answers questions grounded in the text. Trained on the public MTSamples transcriptions and running entirely in your browser. No server, and the note never leaves this page.

Python TF-IDF Logistic Regression NER NegEx Retrieval / RAG scikit-learn
-

How good is the routing?

Held-out 25% test set. The model is deliberately linear and inspectable, and its mistakes are clinically sensible.

-
Top-1 accuracy correct specialty first
-
Top-3 accuracy correct in top 3 suggestions
-
Macro-F1 averaged over specialties
-
Random baseline 12 classes
Per-specialty F1. Where the model is confident vs. where specialties blur together.
Confusion matrix (row-normalized). A bright diagonal is good; off-diagonal heat shows which specialties get mistaken for each other.

How it works

  1. Scope. MTSamples has 40 buckets, but many are document types (Discharge Summary, Progress Notes) or catch-alls (Surgery, General Medicine), not routable specialties. Keeping genuine specialties with at least 80 notes leaves 12 classes.
  2. Route. TF-IDF over the note, trimmed to the 1,200 most discriminative terms by chi-squared, then multinomial logistic regression. Small enough to ship the whole model to the browser, which reproduces the training math exactly.
  3. Extract. A gazetteer tagger for problems, medications, tests, and anatomy, with NegEx-style negation so asserted and denied findings are told apart. Everything it highlights is traceable to a term and a rule.
  4. Ground. Each sentence is vectorized in the same TF-IDF space; a question is matched by cosine similarity, boosted when a sentence carries the entity type the question is about. This is the retrieval half of a RAG system, done client-side.
  5. Generate (production). In production the retrieved passages become the context for an LLM. That prompt is the one honest server-side step, and it looks like this:
You are a clinical assistant. Answer the question using ONLY the
passages below. If the answer is not in them, say you do not know.
Do not infer beyond the text.

Question: {question}

Passages:
{top_retrieved_sentences}

Answer (cite the passage number):

MTSamples is public-domain, de-identified sample documentation. This is a demonstration of clinical-NLP technique, not a medical device.