fix(tasks): standardize tokenizer to Bio_ClinicalBERT across all task classes#31
Merged
Conversation
… classes ClinicalNotesMIMIC4 and ClinicalNotesICDLabsMIMIC4 were using bert-base-uncased while the runtime encoder loaded Bio_ClinicalBERT, causing a silent token-ID mismatch on clinical terminology. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
I resolved some merge conflicts @Rian354, can you double check and merge to main if it looks good to you? |
Rian354
commented
May 25, 2026
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.
PR: Standardize Tokenizer to Bio_ClinicalBERT Across All Task Classes
Problem
PR #28 introduced
NotesLabsMIMIC4w/ the correct tokenizer ("emilyalsentzer/Bio_ClinicalBERT"), but the older task classes retainedbert-base-uncasedin theirinput_schema:ClinicalNotesMIMIC4discharge_note_timesbert-base-uncasedClinicalNotesMIMIC4radiology_note_timesbert-base-uncasedClinicalNotesICDLabsMIMIC4discharge_note_timesbert-base-uncasedClinicalNotesICDLabsMIMIC4radiology_note_timesbert-base-uncasedNotesLabsMIMIC4admission_note_timesemilyalsentzer/Bio_ClinicalBERT(correct)This is a silent correctness bug. The preprocessing schema tokenizes text using
bert-base-uncasedvocabulary IDs, but the runtimeTextEmbeddingModelcallsAutoModel.from_pretrained(processor.tokenizer_model). Iftokenizer_model = "bert-base-uncased", it loads a general-domain BERT. The two tokenizers share most of BERT's 30,522-token vocab but differ for clinical and chemical terms.This was identified as one of the three root causes of the 0.07 PR-AUC failure in PR #28. The fix was applied to
NotesLabsMIMIC4but not backported to the older classes.Why Standardize Now
ClinicalNotesMIMIC4andClinicalNotesICDLabsMIMIC4are used in the legacy comparison baseline (--task clinical_notes_icd_labs). Running them w/bert-base-uncasedmakes comparisons unfair.NotesLabsMIMIC4. Using the same model for all tasks avoids loading two BERT models simultaneously.Full-Scale Tokenizer Comparison (full MIMIC-IV, MLP + Transformer, 50 epochs, seed=42)
emilyalsentzer/Bio_ClinicalBERTmicrosoft/BiomedNLP-BiomedBERT-base-uncased-abstract-fulltextmedicalai/ClinicalBERTyikuan8/Clinical-Longformeritalic = still running (ep16, best ep16, still improving). † = converged (peaked ep11, stale 7 epochs).
Bio_ClinicalBERT and PubMedBERT transformers peaked at ep1 and degraded. ClinicalBERT transformer held 0.302 through ep11.
medicalai/ClinicalBERTis the most stable encoder across architectures. It is the only encoder where the transformer does not collapse (0.302 vs 0.180 for Bio_ClinicalBERT transformer). Recommendation: switch default tomedicalai/ClinicalBERT.To swap the tokenizer for an experiment, set
tokenizer_modelin the task'sinput_schema:This changes the task cache UUID, so caches for different tokenizers are isolated.
Changes
pyhealth/tasks/multimodal_mimic4.pyReplaced all 4 occurrences of
"bert-base-uncased"w/"emilyalsentzer/Bio_ClinicalBERT"inClinicalNotesMIMIC4andClinicalNotesICDLabsMIMIC4input schemas.Cache impact: the task cache UUID for these classes changes (tokenizer_model is in
input_schemawhich is invars(task)viaset_task). Any existing task-level caches built w/bert-base-uncasedwill not be reused. The baseglobal_event_df.parquetis unaffected.Files Changed
pyhealth/tasks/multimodal_mimic4.pybert-base-uncased->Bio_ClinicalBERT