rxintent — 1.2M-param drug-query intent model + rxlookup engine
Typo-tolerant drug / medicine search for prescription (Rx) queries over RxTerms and RxNorm: free English in, structured medication products (strength, dose form, route, RXCUI) out.
⬇️ Download
⬇️ Download everything as one zip: rx-drug-lm.zip (10 MB)
— model weights, engine, index and test UI. Unzip, pip install numpy gradio, then on Windows
double-click rxintent\start.bat (anywhere else: python app.py in rxintent/).
Single files are under the Files and versions tab; the command-line route is in Quick start below.
"hey show me omeprazol capsule 20 mg thanks"
│
▼ intent model (char-level transformer encoder-decoder, 1,233,974 params, trained from scratch on CPU)
{"name": "omeprazole", "strength": "20", "form": "cap", "route": null}
│
▼ rxlookup engine (trigram + edit distance + popularity prior over RxTerms 202608)
{ "name": "Omeprazole", "packaging": [ {route, dose_form, strengths:[{strength, rxcui, brand, …}]} ], … }
The model never answers from memory. It only turns free English into a structured query; every RXCUI, strength and dose form in the output comes from the index.
This is not a transformers model — it is a custom PyTorch module (rxintent/model.py) with a
numpy-only inference port (rxintent/infer_np.py), small enough for a Raspberry Pi.
Quick start
pip install huggingface_hub numpy # torch and gradio are optional
hf download sraivante/rxintent-drug-rxterm --local-dir rx-drug-lm
cd rx-drug-lm/rxintent
python ask.py --np "i need metfromin 500 tablets" # numpy only
python ask.py "i need metfromin 500 tablets" # torch
python app.py # Gradio test UI (pip install gradio)
from ask import Ask
ask = Ask(use_numpy=True)
ask("can i get atorvastin 20mg please", limit=3)
# {"query":..., "intent": {...}, "engine_query": "atorvastin 20", "confident": true,
# "timing_ms": {...}, "matches": [ ...rxlookup match objects... ]}
Layout
| path | what |
|---|---|
rxintent/intent.pt |
trained weights (torch), 4.9 MB |
rxintent/intent.npz |
same weights for numpy inference, 4.6 MB |
rxintent/model.py, vocab.py, infer_np.py, ask.py |
model, shared vocabulary, numpy port, model+engine pipeline |
rxintent/app.py |
Gradio test UI |
rxintent/start.bat, stop.bat |
Windows: start the test UI and open it in the browser / stop it |
rx-drug-lm.zip |
everything needed to run and test, in one download (no training data) |
rxintent/gen_data.py, train.py, data.jsonl |
synthetic data (120k pairs) and training |
rxlookup/rxlookup.py, rx_index.json |
typo-tolerant lookup engine and its RxTerms index |
Details: rxintent/README.md and rxlookup/README.md.
Step-by-step testing guide: HOW_TO_TEST.md.
Results (held-out synthetic queries, n=600)
| top-1 drug correct | |
|---|---|
| engine alone on the raw sentence | 28.8 % |
| model parses → engine executes | 93.8 % |
Model alone: strength + form + route all correct 99.3 %; name slot exactly right 69.5 % (the engine recovers the rest).
Limits
- Evaluated on synthetic queries only; no real query logs.
- No "no drug" class — the model always emits a name. Use the pipeline's
confidentflag. - One drug per query. English only. No therapeutic-class queries ("bp medicine").
- RxTerms is US data; non-US brands resolve only through
rxlookup/aliases.json.
Not a medical device. This is a search/lookup aid, not a source of clinical or dosing advice.
Data
Index and training data are derived from RxTerms (release 202608), U.S. National Library of Medicine.
- Downloads last month
- 13