Where to Look for Rare Codes: Schema-Typed Clinical Notes as a Shared Attention Prior

Automatic medical coding assigns billing and diagnosis codes, drawn from the International Classification of Diseases (ICD), to a hospital discharge summary. Most of these codes are rare. On the MIMIC-IV ICD-10 benchmark, half of the 26,096 codes appear in three or fewer summaries, and the best models reach a macro F1 of only 5.42% despite a macro AUC near 97% (Mimic-IV-ICD). The high AUC with near-zero F1 suggests the models rank the right code fairly high but cannot commit to it. We argue that one reason is that a rare code has too few examples to learn where in the note its evidence lives: the discharge-medication list, a negated finding in the review of systems, or a BMI value in the physical exam. Current pipelines flatten notes into undifferentiated text, and often strip digits entirely (Edin et al.), so every rare code must rediscover this from scratch.

The proposal is to encode each note in a validated XML schema, a customization of the Text Encoding Initiative (TEI, a long-standing standard for layered text markup). Every token then carries a small discrete type: its section, its clinical entity category, its assertion status (present, absent, hypothetical), and, for measurements, a typed numeric value. We then give each code's attention a prior over these types. Crucially, the prior is shared down the ICD hierarchy, so a rare leaf code inherits "where to look" from its frequent parent and siblings. The markup matters here because it turns the note into a small, addressable space of element types. Statistics can be pooled across codes in that space, which is not possible over raw token positions.

Core Claim

Our claim is that the long-tail failure in ICD coding is partly a localization failure, and that it can be reduced by moving that burden from per-code parameters to a shared, hierarchy-inherited distribution over schema element types. Two things would be new. The first is using document structure specifically as a channel for transferring evidence-location knowledge from head to tail codes. The second is a controlled test of whether validated, typed structure outperforms cheap plain-text surrogates of the same information. We expect the gain to concentrate in the rarest frequency bins and in codes whose defining evidence is numeric or assertion-dependent. If gains are flat across frequency, the claim is wrong.

Relation to Prior Work

The closest work is Less is More. It tags entities and assertions with RoBERTa-PM, discards normal and negated findings, prefixes survivors with pseudo-XML strings such as <disorder>, and feeds them to a label-wise cross-attention transformer. This compresses notes by 78% at a small cost (58.8 vs 59.6 micro F1 on MIMIC-IV). Our proposal differs in three ways. We keep the full text and add structure as a standoff layer instead of deleting content, because negated findings are themselves evidence for some codes. We make the types an explicit prior on attention rather than extra tokens. And we evaluate by frequency bin, which that paper does not do. Its entity and assertion tagger supplies part of our encoding pipeline.

The label-attention family supplies the backbone. CAML learns a per-code attention query over convolutional features and regularizes rare-code weights with code descriptions. PLM-ICD moves this onto pretrained transformers and shows they need label-aware attention to work at all. Both learn each code's attention independently from its own examples, and that is exactly what breaks with three examples. The synonym-matching network MSMN, discussed in Mimic-IV-ICD, wins on the tail by matching text to description synonyms. This addresses what a rare code says, not where its evidence sits, so the two are complementary and we test the combination.

Edin et al. constrains the design. They show that correct macro F1, stratified splits and per-class thresholds double reported macro F1. They also show that document length is not the bottleneck and that label sparsity is. Any gain we report must survive their evaluation protocol. Their observation that digit stripping discards BMI and stroke-scale evidence motivates our numeric element type.

KREL navigates the ICD knowledge graph with beam search and has an LLM verify evidence spans, raising MDACE full-space F1 from 0.32 to 0.51. It shows that explicit evidence grounding helps rare and combination codes. However, it depends on costly multi-stage LLM calls and permanently loses codes missed early in the search. We ask whether a cheap, single-pass discriminative model can capture part of that benefit.

On the markup side, TEI's ODD customization mechanism, a way to define a validated domain subset of TEI that also generates documentation, is used for Holocaust testimonies (TEI Specifications) and historical encyclopedias (Twenty-two Historical Encyclopedias). Corpus-wide harmonization of this kind is shown in Gos 2. This body of work supplies the engineering: a schema that makes the encoding reproducible across sites and catches malformed automatic annotations. The TIMS system (Terminology-driven literature mining) and MuchMore (Cross Language Retrieval) show that XML concept layers support structured querying of biomedical text, but neither tests a skewed classifier. DiaRetDB1 shows that an XML format can carry multi-expert confidence. We keep that option open as an attribute but do not rely on it.

Research Program

The encoding stage produces, for each MIMIC-IV discharge summary, a TEI document conforming to a clinical ODD customization. Section elements are recovered from the note's headers. Entity elements carry category and assertion attributes, produced by a tagger trained on the 400-summary annotated subset used in Less is More. Measure elements carry a normalized type, value and unit extracted by rules. All three are standoff layers over the untouched text, so overlapping spans are allowed and the original tokens are preserved. Documents that fail schema validation are logged, and the failure rate is reported as a measure of annotation quality.

The model stage uses PLM-ICD with one change. Let $h_i$ be the encoder state of token $i$, $t_i$ its element type (the tuple of section, entity category, assertion and measure type, collapsed to a vocabulary of a few hundred), and $q_c$ the attention query for code $c$. The attention logit is

$$a_{c,i} = q_c^\top h_i + \log \pi_c(t_i), \qquad \pi_c = \mathrm{softmax}\Big(\sum_{g \in \mathrm{anc}(c)} w_g\Big),$$

where $\mathrm{anc}(c)$ is the set of ICD ancestors of $c$ including itself, and each $w_g$ is a learned vector of scores over element types. A rare leaf has almost no data to move its own $w_c$, so its prior is dominated by the chapter and category nodes above it, which frequent codes train. Numeric measures additionally inject their normalized value, through a small embedding added to $h_i$, so a threshold-defined code can use magnitude directly. The prior adds only a few hundred parameters per ICD node, so a capacity advantage is not the explanation for any gain.

The analysis stage asks where attention lands. On MDACE, which aligns codes to human-marked evidence spans, we measure the fraction of each code's attention mass that falls on its annotated evidence, stratified by training frequency.

Baselines

The naive reference point is PLM-ICD trained on flattened text under the Edin et al. protocol. That means digits stripped as in their standard preprocessing, stratified splits, arithmetic-mean macro F1 and per-code tuned thresholds. PLM-ICD reports 59.8% micro F1 on MIMIC-III (PLM-ICD). On MIMIC-IV-ICD10 the best reported macro F1 is 5.42% (Mimic-IV-ICD); this is the headline number to beat. We rerun it ourselves rather than quoting it, since Edin et al. show published macro F1 figures are unreliable. Their per-model corrected values are not itemized in the material, so we have no reported result on Lacuna for tuned PLM-ICD macro F1 on MIMIC-IV-ICD10.

The strongest tail-specific competitor is MSMN. It is reported to beat PLMs on tail codes in Mimic-IV-ICD, but there is no reported per-bin number on Lacuna for MSMN.

The strongest structured-input competitor is the entity-only PLM-CA of Less is More, at 58.8 micro F1 on MIMIC-IV.

The strongest evidence-grounded system is KREL, at 0.51 F1 on MDACE full-space (KREL). It is an LLM pipeline with very different compute, so we compare against it only on MDACE and report cost alongside accuracy.

Three ablations isolate the key ingredient. The first removes hierarchy sharing, so each code learns its own $w_c$. The second replaces the validated schema types with plain-text surrogates, feeding section headers and bracketed entity prefixes as tokens with digits kept, and no attention prior. The third removes only the numeric measure channel.

All systems share the same encoder checkpoint, splits, thresholding procedure, maximum sequence length and a matched hyperparameter search budget in GPU-hours. Beating the baselines means a statistically reliable macro F1 gain, measured by paired bootstrap over documents, in the bins with at most 10 training occurrences, with head-bin micro F1 no worse than the naive reference.

Why not just…?

Why not just keep the digits and section headers as plain text? This is the most serious threat. A modern tokenizer sees "BMI 42.1" and "Discharge Medications:" perfectly well. Our answer is that it sees them as tokens, but a code with three examples still has to learn to attend to them, and nothing ties its attention to its siblings'. The plain-text surrogate ablation settles this directly. If it matches the full model in the tail bins, the conclusion is that the schema is unnecessary and the gain came from undoing digit stripping. We would report that as the finding.

Why not just reweight the loss or oversample rare codes? Oversampling a code with three positives replays the same three notes. That tends toward memorization, as noted in Mitigating Class Imbalance in Clinical Machine Learning. Reweighting shifts decision thresholds, which per-code threshold tuning in Edin et al. already captures, and tail performance remained poor after it. We nonetheless run class-weighted and two-phase training in the style of Agarwal et al. on top of both the baseline and our model. This checks whether the effects add or merely substitute.

Why not just use an LLM with evidence verification, as KREL does? KREL is genuinely strong on MDACE. It also shows that plain LLM prompting collapses on combination codes (0.077 recall), and Agarwal et al. show LLMs reaching 0.03 recall on minority assertion classes. Our aim is not to beat KREL outright but to measure how much of its tail benefit a single-pass model recovers at a small fraction of the cost. We report F1 per unit of inference compute on MDACE.

Why not just add MSMN-style synonyms? Synonyms address vocabulary mismatch, not evidence location, so we expect them to complement our method. We test MSMN alone, our model alone, and the two combined. If the combination is not additive in the tail, the two methods are fixing the same errors.

Decisive Checks

The central check is the frequency-binned macro F1 curve on MIMIC-IV-ICD10, with bins of 1–3, 4–10, 11–50 and more than 50 training occurrences. The hypothesis predicts the largest gain in the 1–3 bin and a gain that shrinks with frequency. It also predicts that removing hierarchy sharing erases most of the tail gain while leaving head codes unchanged. A second check restricts evaluation to codes whose definition depends on a threshold or an assertion, such as BMI-range codes and stroke-severity codes. Here the numeric channel ablation should show a gap larger than on other codes. A third check uses MDACE: attention mass on gold evidence spans for rare codes should rise under the shared prior, which would show that the mechanism works through localization rather than through some incidental regularization. Finally, we report the schema-validation failure rate of the automatic encoder and the correlation between per-document validation errors and coding errors. This tests whether the value of a validated schema shows up as catching tagging mistakes before they reach the classifier.