Flat-MLP with PubMedBERT-enriched self-distillation for clinical next-event prediction
Project description
Cadence
Clinical next-event prediction: a flat-MLP with PubMedBERT-enriched features and self-knowledge distillation, trained on EHR event sequences.
Install
pip install cadence-core
Quickstart
Inference with a pretrained model
from cadence import Cadence
model = Cadence.from_pretrained("amirrouh/cadence-mimic-100k")
next_event, days_until = model.predict(patient_events)
Training on your own data
from cadence import Cadence
model = Cadence()
model.fit(events_df)
model.save("my-model/")
Input data format
events_df is a pandas DataFrame with the following columns:
patient_id— patient identifier (any hashable type)timestamp— event time (datetime or ISO string; coerced viapd.to_datetime)event_text— free-text event description (e.g. "Patient admitted with chest pain")cluster_id— integer event cluster (optional; auto-assigned via sentence-transformers + KMeans if omitted)
Example:
| patient_id | timestamp | event_text | cluster_id |
|---|---|---|---|
| P001 | 2024-01-15 09:30 | Patient admitted with chest pain | 3 |
| P001 | 2024-01-15 11:45 | ECG performed, ST elevation | 7 |
| P002 | 2024-02-03 14:20 | Routine check-up, vitals normal | 1 |
.predict(patient_events) returns (next_event_label, days_until) for top_k=1, or a dict of top-k predictions with confidences when top_k > 1.
Architecture
Cadence implements the NVC-Clean v14 champion model:
- Feature engineering: 884-d handcrafted features (population anomaly scores, narrative velocity, temporal-gap statistics, cluster bag-of-words)
- Optional: PubMedBERT embeddings (mean + last token, 1536-d) appended → 2420-d total input
- Backbone: flat-MLP with BatchNorm (Linear 884→1024→1024→512 with residual skip)
- Classification head: Asymmetric Loss (ASL, Ridnik et al. 2021)
- Regression head: quantile-bin softmax expectation for time-to-next-event
- Training: Phase 1 (frozen) + Phase 2 (full), MixUp augmentation, Stochastic Weight Averaging, self-knowledge distillation
Citation
Manuscript in preparation; citation forthcoming.
License
MIT. Copyright 2026 Amir Rouhollahi.
Links
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cadence_core-0.1.0.tar.gz.
File metadata
- Download URL: cadence_core-0.1.0.tar.gz
- Upload date:
- Size: 26.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce3e73a9edc8c2cb4327ecfebf615cbbb1f5a9b7900f8b6ddd0abf7890ab1f68
|
|
| MD5 |
b65e0f6416caab8966376ba6beb86fc4
|
|
| BLAKE2b-256 |
512522694348fd518cac0d63581ffc7d8e7537289e1b947a05449bc160a62bdb
|
File details
Details for the file cadence_core-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cadence_core-0.1.0-py3-none-any.whl
- Upload date:
- Size: 28.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17d55db7bf6425b4b750fda68c2c3b630e2462c09e7b5f84fb5ca584e9b58b67
|
|
| MD5 |
0f6a143b522ff9472567072ffc815c57
|
|
| BLAKE2b-256 |
fdc7e078d216b5601bd4dc96f131156de567c5dae4b53544467594c41ed37ab3
|