Skip to content

Add KeyClass weakly-supervised clinical text classifier - #1751

Open
ayangaur26 wants to merge 1 commit into
sunlabuiuc:masterfrom
ayangaur26:feat/keyclass-model
Open

ayangaur26 wants to merge 1 commit into
sunlabuiuc:masterfrom
ayangaur26:feat/keyclass-model

Conversation

@ayangaur26

Copy link
Copy Markdown

Contributor

Type of Contribution

  • Model: KeyClass (pyhealth.models.KeyClass)

Paper Reference

High-Level Description

Implements KeyClass(BaseModel) for weakly-supervised clinical text classification:

  1. Keyword Extraction & Ranking: Extracts candidate n-grams from unlabeled clinical notes and ranks them against class descriptions via cosine similarity.
  2. Heuristic Labeling Functions (LFs): Top-ranked keywords act as automated LFs, with an optional NegEx-style clinical negation/uncertainty filter (use_negation_filter).
  3. Label Aggregation: Aggregates noisy LF votes using EM generative data programming (aggregation="generative") or unweighted majority vote (aggregation="majority_vote").
  4. End Classifier Training & Inference: Fine-tunes the neural text classifier on soft pseudo-labels via fit_weak_supervision() and supports standard PyHealth forward() / Trainer workflows.

Includes synthetic unit tests (tests/core/test_keyclass.py) and an ablation study on MIMIC3ICD9CategoryClassification (examples/mimic3_icd9_category_classification_keyclass.py) comparing roberta-base vs. Bio_ClinicalBERT, majority vote vs. generative aggregation, and NegEx negation filtering.

File Guide

  • pyhealth/models/keyclass.py: KeyClass model and weak-supervision utilities
  • pyhealth/models/__init__.py: Export KeyClass
  • tests/core/test_keyclass.py: Fast synthetic unit tests
  • docs/api/models/pyhealth.models.KeyClass.rst & docs/api/models.rst: API documentation
  • examples/mimic3_icd9_category_classification_keyclass.py: MIMIC-III ablation study script

@solarsys solarsys added the status: manual Pending maintainer's review label Nov 30, 2026
@solarsys

Copy link
Copy Markdown
Collaborator

Why this PR has status: manual: overlap. Two other open PRs also add a KeyClass model: #1408 (opened earlier) and #1713. #1663 (merged) also added the MIMIC-III ICD-9 category task from the same paper. PyHealth keeps one implementation per component, so a maintainer has to pick one KeyClass. This is tracked in #1668.

Please comment here with what your PR does that the others don't. Whichever isn't picked can contribute its unique parts on top of the chosen one, using the merged MIMIC3ICD9CategoryClassification task.

@github-actions

Copy link
Copy Markdown

Test Coverage

Total: 88.33% (58564 / 66301 lines)

Modified file Coverage Lines
pyhealth/models/__init__.py 100.00% 124 / 124
pyhealth/models/keyclass.py 87.27% 281 / 322

Workflow run · bc09653

@jhnwu3

jhnwu3 commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Duplicate: KeyClass is also added by #1408, which was opened earlier and is still under review.

We're still running an AI review on this PR so you get feedback on your code, but we're unlikely to merge a second implementation. If your version fixes or adds something the existing one lacks, a focused follow-up PR that extends it is very welcome; please link this PR from it. Before opening a PR, please check master and open PRs for the same component.

@jhnwu3 jhnwu3 added the duplicate Duplicates an existing PR or a component already on master label Dec 1, 2026
@jhnwu3

jhnwu3 commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

/review

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate Duplicates an existing PR or a component already on master status: manual Pending maintainer's review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants