Repository navigation
feat: add RASCCrossEncoder model and ValueSetPairClassification task (RASC reproduction) - #1608
Open
QiWenchang wants to merge 1 commit into
Open
QiWenchang wants to merge 1 commit into
QiWenchang wants to merge 1 commit into
Conversation
…(RASC reproduction) Adds the cross-encoder of Retrieve, Then Classify (Mukherjee et al., 2026, https://arxiv.org/abs/2604.14616) as a PyHealth model, a text-pair task that feeds it from VSACDataset, and a hybrid SapBERT + BM25 retrieval index builder, with tests, API docs and a reproduction and ablation example.
Test CoverageTotal: 86.42% (46568 / 53887 lines)
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contributor: Wenchang Qi (qi14@illinois.edu, NetID: qi14)
Contribution Type: New Model + Task (reproduction, CS 598 DL4H Option 4: model and task)
Paper: Mukherjee et al., 2026. Retrieve, Then Classify: Corpus-Grounded Automation of Clinical Value Set Authoring. https://arxiv.org/abs/2604.14616 (code: https://github.com/mukhes3/RASC)
Description: Adds the paper's best classifier, the cross-encoder, and the task that feeds it. PyHealth already has the VSAC dataset and the embedding form of the task for the paper's MLP (#1418). The paper's headline result comes from the cross-encoder, which reads the value set title and a candidate code's display name together as one sentence pair. PyHealth had no model for that and no task that emits the two texts.
RASCCrossEncoder(BaseModel) tokenizes the two text inputs as[CLS] title [SEP] display [SEP], runs a BERT encoder (SapBERT by default, as in the paper) and scores the pair with a linear head. It followsmodel_training/train_cross_encoder.pyin the authors' repository and loads their released weights (RELEASED_WEIGHTS), head included. The loss is BCE with the label processor'spos_weight, the paper's class-balanced BCE.mixed_precision=Trueruns the encoder under bfloat16 autocast on a GPU.gradient_checkpointinganddropoutare passed to the encoder as in the authors' script.ValueSetPairClassification(BaseTask) emits one sample per (target value set, candidate code):title_text,candidate_text, a binary label, and on requestscoreandcode_systemfor fusion. Candidate pooling, the 1,000-code cap and the labels matchValueSetCompletion; a test checks that both tasks produce the same pool, labels and scores. It reads only the index's text and neighbor tables, so workers load no embedding matrix.build_hybrid_retrieval_index(not in the paper) merges the title-embedding ranking with a BM25 ranking of the titles by reciprocal rank fusion, at the same K. The paper names retrieval coverage as its binding constraint; this tests whether lexical matching helps.How the new code relates to existing components (no existing component is changed; the only edits to existing files are two exports and two docs index lines):
value_set_pair_classification.pyimportsCODE_SYSTEM_VOCAB,normalize_code_systemand theEncodertype fromvalue_set_completion.py, on purpose: thecode_systemone-hot must use the same vocabulary and URI mapping as the existing task and asVSACDataset, which imports the same function.build_retrieval_index, andbuild_hybrid_retrieval_indexwrites the same files, so one task reads both. This is a shared file layout, not shared code: the hybrid builder is self-contained, andvalue_set_completion.pystays as merged.ValueSetCompletion, so that the existing task and its cache keys are untouched.build_retrieval_indexandsapbert_encoderto build the paper's dense index.tests/core/test_value_set_pair_classification.pyimports the synthetic VSAC fixture (write_fixture,stub_encoder,ICD10,_THREADED_DASK) fromtests/core/test_vsac.py, so both tasks are tested on the same five value sets, andwrite_tiny_bertfromtests/core/test_rasc.py.scikit-learn'sCountVectorizerandscipy.sparse; the encoder loads throughtransformers.Reproduction (real VSAC: 11,799 of the release manifest's 11,803 value sets were still downloadable; first 1,000 codes each as in the paper; K=10; 4.00M training, 0.92M validation and 2.25M test pairs; one A100, about 3 hours; single runs):
Trainer(main)Ablations (
examples/vsac_value_set_completion_rasc.py; 20% of the value sets of every split, hashed by OID, 755 test value sets, 0.81M training pairs; none of these are in the paper):mainreaches AUROC 0.731 on 20% of the training value sets and 0.850 on all of them.len64is below bothlen32andmain). Treat smaller differences as nothing.A finding about data loading:
get_dataloader(shuffle=True)on a patient-level split shuffles only within each value set's run of samples. A batch of 64 held 1.3 value sets on average, and with that loader the cross-encoder stayed at validation AUROC 0.500 for three epochs. The example therefore reads the training split once and permutes it in memory (shuffled_dataloader); with that change alone it reaches the numbers above. This PR does not change the shared loader.Differences from the authors' training script: batch size 64 replaces 16 with 4 accumulation steps; bfloat16 autocast replaces fp16 with a gradient scaler; the linear warmup (6%) and decay run inside an optimizer subclass in the example (
WarmupAdamW), becauseTrainertakes no scheduler; early stopping watches validation PR-AUC instead of validation loss.Limitations:
VSACDataset.download_expansions). Tests use synthetic value sets only.Files to Review:
pyhealth/models/rasc.py:RASCCrossEncoderpyhealth/tasks/value_set_pair_classification.py:ValueSetPairClassification,build_hybrid_retrieval_indextests/core/test_rasc.py: 19 model tests on a random two-layer BERT built in a temporary directory and four in-memory pairs (no network, no download); module setup about 0.1 stests/core/test_value_set_pair_classification.py: 16 task and retrieval tests on five synthetic value sets with stub encoders, including task-to-model end to end; one shared module setup of about 1.5 s (PyHealth's dataset cache build), each test under 0.3 sexamples/vsac_value_set_completion_rasc.py: reproduction and ablations;--syntheticruns all eight trained configurations on CPU in about a minutedocs/api/models/pyhealth.models.RASCCrossEncoder.rst,docs/api/tasks/pyhealth.tasks.ValueSetPairClassification.rst,docs/api/models.rst,docs/api/tasks.rst: API docspyhealth/models/__init__.py,pyhealth/tasks/__init__.py: exportsTest coverage of the two new modules is 98% (
rasc.py99%,value_set_pair_classification.py98%).