Skip to content

Commit ef48918

Browse files
authored
Add missing citations in PyHealth code (#1181)
* Add missing citations for TFMTokenizer, EHRMambaCEHR, CEHR embeddings, comprehensiveness/sufficiency metrics, MLE, and NNAAR * to pass the pr checks
1 parent 132c9fb commit ef48918

9 files changed

Lines changed: 86 additions & 4 deletions

File tree

docs/api/metrics/pyhealth.metrics.generative.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ pyhealth.metrics.generative
22
===================================
33

44
Evaluation metrics for synthetic (generative) EHR data, covering privacy,
5-
utility, and statistical fidelity.
5+
utility, and statistical fidelity. See each function's docstring for the
6+
paper it implements.
67

78
.. currentmodule:: pyhealth.metrics.generative
89

examples/conformal_eeg/test_tfm_tuev_inference.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
present in this repo. No training — pure inference to verify weights and
66
normalization are correct.
77
8+
Model: TFMTokenizer, see pyhealth.models.tfm_tokenizer for the paper citation.
9+
810
Usage:
911
python examples/conformal_eeg/test_tfm_tuev_inference.py
1012
python examples/conformal_eeg/test_tfm_tuev_inference.py --gpu_id 1

pyhealth/metrics/generative/privacy.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ def calc_nnaar(
5555
) -> Dict[str, Tuple[float, float]]:
5656
"""Computes the Nearest Neighbor Adversarial Accuracy Risk (NNAAR).
5757
58+
Paper:
59+
Yale, Andrew, Saloni Dash, Ritik Dutta, Isabelle Guyon, Adrien Pavao,
60+
and Kristin P. Bennett. "Generation and Evaluation of Privacy
61+
Preserving Synthetic Health Data." Neurocomputing 416 (2020):
62+
244-255. https://doi.org/10.1016/j.neucom.2019.12.136
63+
5864
NNAAR measures whether the synthetic data sits closer to the real training
5965
data than to held-out test data, which would indicate memorization::
6066

pyhealth/metrics/generative/utility.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ def compute_mle(
5353
(Train-Synthetic-Test-Real, TSTR). Both are evaluated on the same real test
5454
set. Synthetic accuracy/F1 close to real accuracy/F1 indicates high utility.
5555
56+
Paper:
57+
Esteban, Cristobal, Stephanie L. Hyland, and Gunnar Ratsch.
58+
"Real-valued (Medical) Time Series Generation with Recurrent
59+
Conditional GANs." arXiv:1706.02633 (2017). Introduces and names
60+
the "Train on Synthetic, Test on Real" (TSTR) evaluation protocol
61+
this function implements.
62+
5663
Note:
5764
The current implementation hard-codes the downstream task to
5865
next-visit prediction (built via

pyhealth/metrics/interpretability/comprehensiveness.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ class ComprehensivenessMetric(RemovalBasedMetric):
1818
are REMOVED (ablated). Higher scores indicate more faithful
1919
interpretations.
2020
21+
Paper:
22+
DeYoung, Jay, Sarthak Jain, Nazneen Fatema Rajani, Eric Lehman,
23+
Caiming Xiong, Richard Socher, and Byron C. Wallace.
24+
"ERASER: A Benchmark to Evaluate Rationalized NLP Models." ACL 2020.
25+
2126
The metric is computed as:
2227
COMP = (1/|B|) × Σ[p_c(x)(x) - p_c(x)(x \\ x:q%)]
2328
q∈B

pyhealth/metrics/interpretability/sufficiency.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ class SufficiencyMetric(RemovalBasedMetric):
1818
features are KEPT (all others removed). Lower scores indicate more
1919
faithful interpretations.
2020
21+
Paper:
22+
DeYoung, Jay, Sarthak Jain, Nazneen Fatema Rajani, Eric Lehman,
23+
Caiming Xiong, Richard Socher, and Byron C. Wallace.
24+
"ERASER: A Benchmark to Evaluate Rationalized NLP Models." ACL 2020.
25+
2126
The metric is computed as:
2227
SUFF = (1/|B|) × Σ[p_c(x)(x) - p_c(x)(x:q%)]
2328
q∈B

pyhealth/models/cehr_embeddings.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,32 @@ def forward(self, visit_segments: torch.Tensor) -> torch.Tensor:
4848

4949

5050
class MambaEmbeddingsForCEHR(nn.Module):
51-
"""CEHR-style combined embeddings for Mamba (concept + type + time + age + visit)."""
51+
"""CEHR-style combined embeddings for Mamba (concept + type + time + age + visit).
52+
53+
Paper: Same paper as :class:`~pyhealth.models.ehrmamba.EHRMamba` --
54+
EHRMAMBA: Towards Generalizable and Scalable Foundation Models for
55+
Electronic Health Records (arxiv 2405.14567). This embedding scheme is
56+
part of that paper's own Odyssey toolkit (see module header for the
57+
code source).
58+
59+
Examples:
60+
>>> import torch
61+
>>> from pyhealth.models.cehr_embeddings import MambaEmbeddingsForCEHR
62+
>>> embeddings = MambaEmbeddingsForCEHR(vocab_size=100, hidden_size=32)
63+
>>> batch_size, seq_len = 2, 5
64+
>>> input_ids = torch.randint(0, 100, (batch_size, seq_len))
65+
>>> token_type_ids = torch.zeros(batch_size, seq_len, dtype=torch.long)
66+
>>> time_stamps = torch.zeros(batch_size, seq_len)
67+
>>> ages = torch.zeros(batch_size, seq_len)
68+
>>> visit_orders = torch.zeros(batch_size, seq_len, dtype=torch.long)
69+
>>> visit_segments = torch.zeros(batch_size, seq_len, dtype=torch.long)
70+
>>> out = embeddings(
71+
... input_ids, token_type_ids, time_stamps, ages,
72+
... visit_orders, visit_segments,
73+
... )
74+
>>> out.shape
75+
torch.Size([2, 5, 32])
76+
"""
5277

5378
def __init__(
5479
self,

pyhealth/models/ehrmamba_cehr.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
class EHRMambaCEHR(BaseModel):
1919
"""Mamba backbone over CEHR embeddings (FHIR / MPF pipeline).
2020
21+
Paper: Same paper as :class:`~pyhealth.models.ehrmamba.EHRMamba` --
22+
EHRMAMBA: Towards Generalizable and Scalable Foundation Models for
23+
Electronic Health Records (arxiv 2405.14567). This class combines that
24+
paper's Mamba backbone (:class:`~pyhealth.models.ehrmamba.MambaBlock`)
25+
with CEHR-style embeddings (see
26+
:class:`~pyhealth.models.cehr_embeddings.MambaEmbeddingsForCEHR`).
27+
2128
Args:
2229
dataset: Fitted :class:`~pyhealth.datasets.SampleDataset` with MPF task schema.
2330
vocab_size: Concept embedding vocabulary size (typically ``task.vocab.vocab_size``).
@@ -27,6 +34,24 @@ class EHRMambaCEHR(BaseModel):
2734
state_size: SSM state size per channel.
2835
conv_kernel: Causal conv kernel in each block.
2936
dropout: Dropout before classifier.
37+
38+
Examples:
39+
>>> from pyhealth.datasets import MIMIC4FHIR, split_by_patient
40+
>>> from pyhealth.tasks.mpf_clinical_prediction import (
41+
... MPFClinicalPredictionTask,
42+
... )
43+
>>> from pyhealth.models import EHRMambaCEHR
44+
>>> dataset = MIMIC4FHIR(root="/path/to/mimic-iv-fhir-demo")
45+
>>> sample_dataset = dataset.set_task(MPFClinicalPredictionTask())
46+
>>> train_ds, val_ds, test_ds = split_by_patient(
47+
... sample_dataset, [0.7, 0.1, 0.2]
48+
... )
49+
>>> vocab_size = (
50+
... sample_dataset.input_processors["concept_ids"].vocab.vocab_size
51+
... )
52+
>>> model = EHRMambaCEHR(
53+
... dataset=sample_dataset, vocab_size=vocab_size, embedding_dim=32
54+
... )
3055
"""
3156

3257
def __init__(

pyhealth/models/tfm_tokenizer.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,10 +714,16 @@ def load_embedding_weights(source_model, target_model):
714714

715715
class TFMTokenizer(BaseModel):
716716
"""TFM-Tokenizer model.
717-
717+
718718
This model uses VQ-VAE with transformers to tokenize EEG signals. It can
719719
extract discrete tokens and continuous embeddings for downstream tasks.
720-
720+
721+
Paper:
722+
Pradeepkumar, Jathurshan, Xihao Piao, Zheng Chen, and Jimeng Sun.
723+
"Tokenizing Single-Channel EEG with Time-Frequency Motif Learning."
724+
ICLR 2026. https://arxiv.org/abs/2502.16060
725+
Code: https://github.com/Jathurshan0330/TFM-Tokenizer
726+
721727
The model expects two inputs:
722728
- STFT spectrogram: shape (batch, n_freq, n_time)
723729
- Raw temporal signal: shape (batch, n_samples)

0 commit comments

Comments
 (0)