Automated clinical coding means assigning billing diagnosis codes (ICD codes) to a hospital discharge summary. It is a problem dominated by rare labels. In MIMIC-IV, half of all ICD-10 codes appear in three or fewer summaries. The best reported systems rank codes well (macro AUC up to 97.07%) but almost never commit to the right rare code (macro F1 of 5.42%) (Mimic-IV-ICD). A model cannot learn what a rare disease looks like from three examples. It could, however, learn where in the note diagnostic evidence tends to sit, and that knowledge comes from abundant examples. Discharge summaries are formatted documents: colon-terminated headers, numbered diagnosis lists, indented medication schedules, lab blocks. The location of evidence for a code is largely determined by what kind of code it is, not by which specific code it is.
We propose to make that knowledge explicit and shared. Each note is parsed into a structural descriptor per token: which section it belongs to, whether it sits in a list, its indentation depth, and whether the line looks like a header. The attention head for each code then receives a bonus for structural locations, and that bonus is predicted from the code's position in the ICD hierarchy rather than learned separately per code. Frequent codes teach the model that, say, chronic comorbidities are attested in the past-medical-history list and acute diagnoses in the discharge-diagnosis list. A rare code in the same ICD chapter inherits that prior for free. The testable prediction is sharp: if structure acts as a channel for transfer between classes, its benefit should grow as class frequency falls, and it should vanish when the structural prior is learned per code.
Core Claim
Structural document cues are shared across classes, whereas lexical cues are specific to each class. Under extreme imbalance, a model gains most from structure when structure is used to share "where to look" across the label hierarchy. Feeding structure in as just more input features is not enough. Concretely, a label-attention coder with a hierarchy-shared structural prior should improve macro F1 on codes with at most ten training examples. It should do so by more than it improves frequent codes, and by more than two cheaper alternatives achieve: a text model that simply keeps the note's whitespace, and hard filtering to the diagnosis section.
The structural document classification literature motivates the premise that formatting carries meaning independent of content. Macro layout signatures classify document genre about as well as text does (Caragea et al.), and cheap formatting statistics such as symbol ratios and words per line scale document harvesting (Wu et al.). Headings and lists can be recovered from font size and indentation alone (Weber), and elements with identical formatting belong to the same logical tier (Fauconnier et al.). Most tellingly, layout cues let models transfer across languages (Lincker et al.). We read that result as layout generalizing across one axis of variation, and we ask whether it also generalizes across another: from head classes to tail classes.
Two results constrain the design. First, Lincker et al.'s imbalanced textbook study combined LayoutLMv2, LiLT and CamemBERT and reached 80.2% overall accuracy, but only 58.3% on the 11 rarest classes. Focal loss and undersampling gave limited help. So simply adding layout features and reweighting the loss does not rescue the tail, which is why we put structure into the mechanism for sharing information across labels rather than into the input or the loss. Second, the replicability study of MIMIC coding showed that document length is not the bottleneck and label sparsity is. That argues against yet another long-context architecture and for a method aimed directly at sparsity. The same study also found that common preprocessing, such as stripping digits, destroys evidence. The widespread practice of lowercasing and collapsing whitespace similarly destroys the very structure we want to use.
One honest clarification: MIMIC notes are plain text, not scanned pages. "Layout" here means the formatting that survives in the characters: line breaks, indentation, capitalization, list markers and colons. This is the plain-text analogue of the typographic cues that Weber and Fauconnier exploit. We deliberately do not render notes into images.
Research Program
The first component is a structural parser for clinical notes. We train a section tagger on MedSecId, which has 2,002 physician-annotated MIMIC-III notes with 50 section types. We give it format features in addition to text: whether a line is header-like, indentation depth, list-marker type, line length, and numeric density. Because MedSecId itself is heavily imbalanced (BiLSTM-CRF reaches 0.955 micro F1 but only 0.787 macro F1), this component is also a small first test of the core claim. Formatting features are identical across section types, so they should help rare section types more than frequent ones. The parser outputs, for every token $t$, a descriptor $s_t$ combining predicted section type with the format features.
The second component is the coder. We start from PLM-ICD (Huang et al.), a pretrained clinical language model that splits long notes into segments and uses one attention head per code. PLM-ICD computes code $c$'s attention over token representations $h_t$ from a code query $q_c$. We add a structural term:
$$ \alpha_{c,t} \propto \exp\big(q_c^\top h_t + g(s_t, z_c)\big), $$
where $\alpha_{c,t}$ is the attention weight of code $c$ on token $t$ and $z_c$ is an embedding of code $c$ built only from its ancestors in the ICD hierarchy (chapter, block and three-character category). The function $g$ is a small network shared across all codes. Because $g$ never sees a per-code parameter, a code seen three times gets the structural prior of its hierarchical neighbours. Digits are retained throughout, following the replicability study.
The third component is analysis. We report every metric stratified by training frequency of the code. We also check whether attention mass for correctly predicted rare codes falls in the sections a coder would consult; the MIMIC-III notes overlapping MedSecId give gold section boundaries for this check.
Baselines
The naive reference point is PLM-ICD run under the standard flattened preprocessing, with a single global decision threshold. This is how most published numbers were produced. For the strongest existing model we use PLM-ICD with per-code thresholds tuned on validation data, evaluated with the corrected macro F1 definition from the replicability study. That study reports that such tuning roughly doubled macro F1 for earlier models, but the file gives no exact figure for PLM-ICD on MIMIC-IV-ICD10. The anchors we can cite are PLM-ICD's 59.8% micro F1 on MIMIC-III full (Huang et al.) and the 5.42% best macro F1 and 97.07% best macro AUC on MIMIC-IV-ICD10 (Nguyen et al.); the file does not name the model behind the latter. We also run MSMN, which Nguyen et al. report as stronger than PLM-ICD on rare codes because it matches note text to code synonyms. MSMN is the most direct competitor on exactly the regime we target.
Three baselines isolate the ingredients of our method. The first is whitespace-preserving PLM-ICD, which receives raw text with newlines and indentation intact but no parser and no prior. It tests whether the transformer discovers structure unaided. The second is hard section filtering: PLM-ICD sees only the sections our parser labels as diagnostic. The third is a per-code structural prior, in which $g$ takes a free embedding for each code instead of $z_c$. This last ablation is the key one, because it adds exactly the same information to the model while removing the sharing across classes.
For fairness, all systems use the same backbone, segment length, training steps, validation-tuned per-code thresholds and hyperparameter search budget, on the official MIMIC-IV-ICD10 and ICD-9 splits and on MIMIC-III clean. Beating the strongest baseline means a statistically significant gain in macro F1 on codes with at most ten training examples over thresholded PLM-ICD and over MSMN, without losing micro F1. It also means clearly outperforming the per-code-prior ablation on those same codes, using paired bootstrap resampling over documents.
Why not just…?
Why not just keep the whitespace and let the transformer learn structure? This is the most serious threat. Pretrained models can learn that a newline followed by "DISCHARGE DIAGNOSES:" means something. Our argument is that such a model learns structure-to-code associations separately for each code, which does nothing for codes with three examples. The whitespace-preserving baseline tests this directly. If it closes most of the tail gap, the claim fails, and the honest conclusion is that preprocessing, not architecture, was the problem. That would still be a useful finding, extending the replicability study's point about digit stripping.
Why not just feed the model only the discharge-diagnosis section? Hard filtering is the crude version of our prior, and it may capture much of the gain. It fails when evidence for a code lives elsewhere: procedures described in the hospital course, history codes in past medical history, or social-history codes. It also inherits parser errors without any soft fallback, and regex section detection agrees with physicians at only α = 0.54 (Landes et al.). If filtering matches our method overall but loses on chapters whose evidence is not in the diagnosis list, that supports the learned, hierarchy-specific prior. If it matches everywhere, we will report that the simpler system suffices.
Why not just tune thresholds and use synonym matching? Threshold tuning fixes miscalibration but cannot create a representation for a code the model barely attends to. The 97.07% macro AUC versus 5.42% macro F1 gap on MIMIC-IV-ICD10 (Nguyen et al.) suggests ranking is not the whole story. Synonym matching (MSMN) and our prior act on different things: MSMN addresses what a code is called, while our prior addresses where the evidence appears. So we also test MSMN with the structural term added. Complementary gains would be the more interesting outcome.
Why not just use two-phase training or synthetic minority data? Agarwal et al. show that balanced pretraining followed by full fine-tuning, plus text generated by a language model, lifts minority recall on three-way clinical context labels. With tens of thousands of codes and half of them seen three or fewer times, a balanced phase and credible synthetic notes for every rare code are much harder to build. The layout result of Lincker et al. also warns that reweighting schemes do little on small, noisy tails. We include class-balanced two-phase training as an additional baseline on MIMIC-III clean, where it is tractable.
Proposed Experiments
The main experiment trains all systems on MIMIC-IV-ICD10, MIMIC-IV-ICD9 and MIMIC-III clean. It reports corrected macro F1, micro F1 and macro AUC, each broken down by training-frequency bins of 1–3, 4–10, 11–100 and more than 100 examples. The decisive signature is an interaction: the gap between our method and thresholded PLM-ICD should widen from the head bin to the 1–3 bin, and the per-code-prior ablation should show little or no tail gain. A uniform gain across bins would mean structure helps, but not through sharing across classes. That would refute the specific claim even if overall numbers improve.
A second check shuffles structural descriptors across documents while keeping their marginal frequencies; any benefit should disappear. A third check replaces the learned section tagger with regex sections, to measure how much parse quality matters. A fourth tests whether the prior's value tracks hierarchy: we train with the chapter level of $z_c$ removed, and we evaluate on held-out codes that never appear in training but whose siblings do. There, only a shared prior can contribute anything beyond the code description.
On MedSecId, we compare the text-only BiLSTM-CRF (0.787 macro F1) against the same model with format features, stratified by section frequency. The same interaction should appear: format features help rare sections disproportionately. Finally, the attention analysis on the overlapping MIMIC-III notes asks whether rare-code attention lands in plausible sections more often under the shared prior. This checks that the gain comes from looking in the right place rather than from incidental regularization.
References
- Mimic-IV-ICD: A new benchmark for eXtreme MultiLabel Classification
- Document Type Classification in Online Digital Libraries
- CiteSeerX: AI in a Digital Library Search Engine
- WordScape: a Pipeline to extract multilingual, visually rich Documents with Layout Annotations from Web Crawl Data
- Automatic Detection of Document Organizational Structure from Visual and Lexical Markers (Détection automatique de la structure organisationnelle de documents à partir de marqueurs visuels et lexicaux) [in French]
- Classification automatique de données déséquilibrées et bruitées : application aux exercices de manuels scolaires
- Automated Medical Coding on MIMIC-III and MIMIC-IV: A Critical Review and Replicability Study
- A New Public Corpus for Clinical Section Identification: MedSecId
- PLM-ICD: Automatic ICD Coding with Pretrained Language Models
- A Framework for Flexible Extraction of Clinical Event Contextual Properties from Electronic Health Records