Repository navigation
Add MIMIC-III ICD-9 category classification task (KeyClass, Gao et al. MLHC 2022) - #1663
Conversation
Test CoverageTotal: 87.44% (52377 / 59900 lines)
|
|
/review |
| ) | ||
|
|
||
|
|
||
| def icd9_to_category(code: Any) -> str | None: |
There was a problem hiding this comment.
[medium] icd9_to_category duplicates the existing ICD9CHAPTER grouper
PyHealth already provides the 19-way ICD-9 chapter grouping as CrossMap.load("ICD9CM", "ICD9CHAPTER") (pyhealth/medcode/codes/icd_groupers.py:101, mapped in pyhealth/medcode/icd_mappings.py:51). icd9_to_category reimplements the same grouping with hard-coded ranges. The description does not say why the existing grouper cannot be used. Fix: build the category labels on ICD9CHAPTER, or state in the description and docstring what the existing grouper gets wrong for the paper's Table 4 categories and why the ranges here differ.
| samples = dataset.set_task(MIMIC3ICD9CategoryClassification()) | ||
|
|
||
| Codes in the ICD-9 symptoms range (780-799) belong to none of the 19 | ||
| categories and give no label. The category ranges are the standard ICD-9 |
There was a problem hiding this comment.
[medium] Docstring says the ranges are the standard ICD-9 chapters, but the code differs
The module docstring says "The category ranges are the standard ICD-9 chapters". The table in ICD9_CATEGORY_RANGES (lines 67-85) does not match the standard layout. It splits 320-389 into "Nervous system" (320-359) and "Sense organs" (360-389), where the standard chapter is one group, and it omits the 780-799 symptoms chapter. Fix: correct the claim, and name the source of the split (for example FasTag's Table, with a link) if the split is intentional.
| raise ValueError("min_words must be non-negative.") | ||
| if max_words is not None and max_words <= 0: | ||
| raise ValueError("max_words must be positive or None.") | ||
| self.note_categories = tuple(c.strip().lower() for c in note_categories) |
There was a problem hiding this comment.
[low] A bare string for note_categories silently matches no notes
note_categories is typed as a Sequence, so a str is accepted. note_categories="Discharge summary" becomes a tuple of single characters, and every admission is then skipped without an error. Fix: reject a str in the validation at lines 208-209, or wrap it as a one-element tuple.
| ) | ||
|
|
||
|
|
||
| class FakePatient: |
There was a problem hiding this comment.
[low] Tests never run the task through MIMIC3Dataset.set_task
All 21 tests call the task on FakePatient objects, which stand in for Patient. Nothing checks the real event attributes or the set_task path on a MIMIC3Dataset built from a small folder. Comparable tasks such as test_clinvar and test_lndb_texture do run set_task on synthetic data. Fix: add one test that writes a few synthetic CSV tables and calls dataset.set_task on the task.
There was a problem hiding this comment.
AI Review
suggestion: approve
decision: approve
Thank you for this contribution. It adds a MIMIC-III task that maps discharge summaries to the 19 top-level ICD-9 categories from Gao et al. (MLHC 2022). It also adds the icd9_to_category helper, API docs, an ablation example and 21 synthetic-data tests. It looks ready to merge.
The task is self-contained. It builds only on BaseTask and the existing processors, and the changes to pyhealth/tasks/__init__.py are registration only. The task is also distinct from MIMIC3ICD9Coding, because it predicts categories and not raw codes. Coverage meets the bar. The new task file is at 100%, pyhealth/tasks/__init__.py is at 98.4%, and the whole repository is at 87.4%.
Optional suggestions:
- The module docstring calls the category ranges "the standard ICD-9 chapters". The table splits 320-389 into Nervous system and Sense organs, and it leaves out 780-799. It would be clearer to say the ranges are chapter-based and follow the paper's 19 category names, with those two differences noted.
- A bare string passed as
note_categories, such as"Discharge summary", is iterated character by character and silently matches nothing. You could wrap astrinto a tuple, or raise an error. - You could add one test that runs
set_taskon a smallMIMIC3Datasetbuilt from the example's synthetic generator. The tests currently use fake patient objects only. - The example's results table comes from a Colab run, and the docstring already says the numbers are only a pipeline check. That is fine as it stands.
Reviewed commit f9560f6
Contributors: Hekili Jordan (hekilij2), Nishanth Manjunath (nm89), Esther Hwang (inseoh2)
Contribution Type: Standalone Task (for the existing MIMIC3Dataset)
Paper: Chufan Gao, Mononito Goswami, Jieshi Chen, Artur Dubrawski.
"Classifying Unstructured Clinical Notes via Automatic Weak Supervision." MLHC 2022.
https://proceedings.mlr.press/v182/gao22a.html
Description:
Adds
MIMIC3ICD9CategoryClassification, the ground-truth label generation component of the KeyClass clinical experiment: it turns MIMIC-III discharge summaries into a 19-label multilabel problem over the top-level ICD-9 diagnosis categories (following FasTag).Each admission with a discharge note and at least one diagnosis mapped to a supported category becomes one sample (note text in, 19-dim multi-hot categories out). I
Includes
icd9_to_categorymapping function and a separate transformers-based ablation example exploring the effects of note length and note source.Files to Review:
pyhealth/tasks/mimic3_icd9_category_classification.py- the task + icd9_to_categorytests/core/test_mimic3_icd9_category_classification.py- tests on synthetic data (no MIMIC)examples/mimic3_icd9_category_classification_transformers.py- ablation exampledocs/api/tasks/pyhealth.tasks.MIMIC3ICD9CategoryClassification.rst- API docsdocs/api/tasks.rst- toctree entrypyhealth/tasks/__init__.py- exportsTesting:
python -m unittest tests.core.test_mimic3_icd9_category_classificationruns 21 tests on synthetic data in ~2ms; 10 module doctests pass;ruffclean.Data note: The tests and the example's
--syntheticpath use synthetic MIMIC-III-shaped data, so no credentialed access is needed to review them. Real reproduction uses the full MIMIC-III v1.4.Results (synthetic notes):
--synthetic --epochs 3 --seeds 0 1 2, Colab T4 GPU,Bio_ClinicalBERT, 80 patients and 122 admissions. The notes are synthetic, so this only shows that the pipeline trains end to end; it says nothing about the real task.Mean ± standard deviation over 3 seeds. The test split has only about 18 admissions, and the differences between settings are no larger than the spread across seeds, so no setting is better than another here. Real MIMIC-III notes have not been run.