Letting ICD's Own Coding Rules Constrain Zero-Shot Label Matching

Automatic medical coding assigns billing and diagnosis codes to hospital notes, choosing from thousands of options. A popular way to handle rare and never-seen codes is to compare the note against each code's written description, so a code with no training examples can still be matched by meaning. These matchers score every code independently. That lets them output sets no human coder could submit, such as two codes the coding manual says cannot appear together, or a code that the manual says must come with a companion code. The ICD-9-CM tabular list already contains these rules as "Excludes," "Use additional code," and "Code first" notes, along with an implicit rule that each category takes at most one specific code. Read carefully, these notes form a small formal logic. It has mutual exclusions, if-then requirements, at-least-one-of requirements, and at-most-one limits. Each of these is a known step up in how hard logical reasoning becomes.

This note proposes compiling those notes into constraints and decoding the matcher's scores into the best-scoring code set that obeys them. Decoding is split by logical difficulty. The simple rules are applied by fast forward propagation. The hard rules, the "at least one of" and "at most one" requirements, are solved exactly, but only on the small cluster of candidate codes where fast upper and lower bounds disagree. The central claim is that these rules help most on exactly the codes where description matching is weakest. Rare and unseen codes have no co-occurrence statistics to learn from, but they do inherit rules from the manual. So the manual's logic is the only structural signal available for them.

Core Claim and What Is New

The closest work propagates information over the ICD tree. Few-Shot and Zero-Shot Multi-Label Learning for Structured Label Spaces (ZAGCNN) builds code vectors from descriptions and smooths them over the ICD-9 hierarchy with a graph network. Generalized Zero-shot ICD Coding (AGMC-HTS) generates synthetic features for unseen codes, conditioned on descriptions and sibling codes. Both use the taxonomy as a similarity prior. Neither can represent exclusion, requirement, or cardinality, and both output independently thresholded scores. Our proposal leaves the representation side largely alone. It changes what counts as a legal output and how that output is found.

The logic side supplies the method. PAGOdA answers queries over expressive ontologies by computing a cheap sound lower bound and a cheap complete upper bound. It then runs a full reasoner only on the small fragment where the two disagree. We reuse that pattern for decoding a set of labels rather than for answering queries.

Two further papers motivate the choice of difficulty levels to separate. Consequence-Based Reasoning beyond Horn Ontologies and Restricted Chase (Non)Termination for Existential Rules with Disjunctions both show that disjunctions are what destroy deterministic forward reasoning. That is why we treat "Use additional code" (an at-least-one-of rule) differently from "Excludes" (a pairwise ban).

Formally, let $s_c$ be the matcher's score for code $c$, let $y_c \in \{0,1\}$ indicate whether $c$ is predicted, and let $\mathcal{T}$ be the compiled rules. Decoding solves

$$\hat{y} = \arg\max_{y \,\models\, \mathcal{T}} \sum_c (s_c - \tau)\, y_c ,$$

where $\tau$ is the usual decision threshold and $y \models \mathcal{T}$ means the predicted set violates no hard rule. Without $\mathcal{T}$ this reduces to independent thresholding. Pairwise exclusions alone already make the problem a weighted independent-set problem, which is hard in general. The bet is that clinical notes make it cheap in practice, because only a handful of high-scoring candidates ever conflict.

Research Program

The work has three parts, and the first decides whether the other two are worth doing.

The first part compiles the tabular notes into typed rules and audits them against real data. Each "Excludes" note becomes a disjointness rule. Each "Code first" or "Use additional code" note with a single target becomes an implication. Notes that name a range become at-least-one-of rules. The at-most-one rule within a category is added. We then measure how often the gold code sets in MIMIC-III already violate each rule type.

This audit is essential, because gold annotations contain coding errors and billing conventions that ignore some notes. The audit decides which rule types are treated as hard and which as soft penalties with a weight tuned on validation data. If gold sets violate "Excludes" rules often, the premise weakens. We would report that as a finding rather than bury it.

The second part is the decoder. The simple rules (exclusions and single-target implications) form a Horn theory, meaning each rule has at most one conclusion, so they can be applied by forward propagation. The decoder computes a lower bound: high-confidence codes plus everything they force, pruned of what they exclude. It also computes an upper bound: every code that stays legal under some choice of the disjunctive rules. Candidates in the gap between the two are grouped into connected conflict clusters, and each cluster is solved exactly with a small integer program. We report cluster sizes, because the claim that clinical notes produce small conflicts is itself an empirical question.

The third part trains with the decoder in the loop. We use a structured hinge loss that penalizes the score margin between the decoded set and the gold set. This lets the rules shape the vectors of unseen codes through their logical neighbors, not only their tree neighbors. The description matcher itself is a dual encoder, meaning one network embeds the note, a second embeds each code's description, and their similarity is the score. It uses label-wise attention in the style of ZAGCNN, so we inherit a known-good representation. We deliberately avoid the two-way cross-attention of Description-Enhanced Label Embedding Contrastive Learning for Text Classification, whose authors note it does not scale to thousands of labels. The same bound-then-fragment idea could later spend expensive cross-attention only on gap candidates, but that is secondary.

Baselines

The naive reference is the same dual encoder with independent per-code thresholding and no rules. This isolates everything the rules add.

The strongest existing representation baselines are ZAGCNN and AGMC-HTS, which are the strongest published zero-shot ICD systems in the file. On MIMIC-III, ZAGCNN reports a 19% Recall@10 improvement on zero-shot codes and 4.8% on few-shot codes over the earlier ACNN model. AGMC-HTS reports zero-shot F1 rising from near 0% to 20.91% and a 3% absolute AUC gain. These numbers come from different splits and metrics, so we will re-run both on one shared frequent/few-shot/zero-shot split of MIMIC-III, and on MIMIC-II for ZAGCNN. Every system gets the same text preprocessing, the same number of tuning trials, and the same GPU budget.

We then place our decoder on top of each of these baselines as well as our own encoder. Beating them means improving zero-shot and few-shot macro F1 and Recall@10 over the same encoder without the rules, beyond seed variance. It also means reducing the rate of rule-violating predicted sets, without losing more than about half a point of micro F1 on frequent codes. The file itself notes a known trade-off on frequent codes in ZAGCNN.

Three ablations isolate the key ingredient. The first is a greedy post-hoc filter, which walks down the score ranking and drops any code that conflicts with one already accepted. The second is a decoder restricted to Horn rules only, which drops the at-least-one-of and at-most-one rules. The third replaces manual rules with the same number of pairwise constraints mined from training co-occurrence, which tests whether the manual carries information the data does not. As a quality ceiling we also run a global integer program over all candidates, which measures both how much exact search gains and what it costs in time.

Why not just…?

Why not just filter predictions greedily with the exclusion list? This is the real threat. For pairwise exclusions alone, greedy filtering may recover most of the benefit. The greedy ablation measures this directly. Greedy filtering cannot satisfy an at-least-one-of requirement, because it only removes codes and never adds a missing companion code. It also cannot trade off two moderately scored conflicting codes against a third. We therefore predict that any advantage over greedy filtering appears specifically on notes that trigger "Use additional code" rules. If the gap to greedy is negligible there too, the exact-fragment decoder is not worth its complexity. In that case we would recommend greedy filtering plus rule-aware training, and we would say so.

Why not just learn label dependencies from co-occurrence, or rely on the hierarchy graph? Co-occurrence statistics do not exist for codes with no training examples, and the tree-smoothing in ZAGCNN encodes similarity, not exclusion. The mined-constraint ablation tests this. We expect it to match manual rules on frequent codes and fall behind on zero-shot codes. If it matches everywhere, the manual adds nothing and the claim fails.

Why not just give a large language model the coding rules in its prompt? TheoremQA found that adding explicit theorem statements to the prompt "did not provide a significant boost," because models struggle to apply rules rather than recall them. Semantic Contracts found that unchecked program execution silently accepted all 21 of its unit-mismatch traces, which a typed checker flagged. Both suggest that stating rules is not the same as enforcing them. Thousands of codes with their notes also exceed practical prompt budgets. We include a prompted model as a secondary reference on a subsample and report its rule-violation rate, but we do not treat it as the main competitor.

Why not just use a complete OWL reasoner or one global integer program? Complete reasoners time out on biomedical ontologies. Pellet failed after an hour on Fly Anatomy, where PAGOdA took 0.2 seconds (PAGOdA). FaCT++ needed 2,324.1 seconds on SCT-SEP, where ConDOR took 88.9 seconds (Consequence-Based Reasoning beyond Horn Ontologies). Our constraint set is much smaller than SNOMED CT, however, so a global integer program may be affordable. We run it as the quality ceiling. If it is fast enough, the fragment decoder's contribution shrinks to a latency result, and we report it as such.

Decisive Checks

The first check is the gold-violation audit. If MIMIC-III gold sets violate "Excludes" rules in a large fraction of admissions, hard decoding is miscalibrated to the labels, and the project pivots to soft penalties or ends.

The second check is the split by frequency. The central prediction is that the gain from rule-aware decoding and training, over the same encoder without rules, is larger on zero-shot and few-shot codes than on frequent ones, and larger with manual rules than with mined ones. A uniform gain across frequency bins would mean the rules act as generic regularization rather than as a substitute for missing data.

The third check is the expressivity ladder. Going from no rules, to Horn-only rules, to Horn plus disjunctive and cardinality rules should show where the value lies. Each step is reported together with conflict-cluster sizes and decoding latency next to the global integer program.

Taken together, these checks answer a question neither community has posed. The question is whether the logical difficulty of a label space's rules predicts how much those rules help a description-based classifier on its rarest labels.