Towards Semi-Structured Automatic ICD Coding via Tree-based Contrastive Learning

Chang Lu, Chandan K. Reddy, Ping Wang, Yue Ning

Introduction

The International Classification of Diseases (ICD) serves as the bedrock for hospital billing, clinical research, and health statistics. However, the process of assigning these codes to clinical notes—a task known as automatic ICD coding—remains a significant challenge for machine learning. While deep learning models have improved significantly, they often struggle with the "long-tail" distribution of rare diseases and the inherent variability of clinical documentation.

This research introduces a novel framework that shifts the paradigm from treating clinical notes as flat text sequences to viewing them as semi-structured documents. By leveraging the hierarchical nature of medical knowledge and the internal structure of clinical notes, the proposed method significantly enhances model performance, particularly for rare medical conditions.

The Problem: Beyond Flat Text

Current state-of-the-art models for ICD coding typically process clinical notes as a single, continuous string of words. This approach ignores three critical realities of medical documentation:

  1. Structural Neglect: Clinical notes are organized into functional sections (e.g., "History of Present Illness," "Physical Exam," "Social History"). Each section contains specific types of evidence that models often fail to isolate.
  2. Data Scarcity and the Long Tail: Many ICD codes appear very infrequently in training data. Models struggle to learn these "rare" codes because they lack sufficient examples to generalize.
  3. High Variability: Doctors exhibit diverse writing styles, often shuffling section orders or omitting certain sections entirely, which can confuse models trained on rigid sequences.

Methodology: A Three-Pronged Approach

To address these issues, the researchers developed a framework consisting of three integrated strategies designed to be applied to existing "backbone" ICD coding models.

1. Automatic Segmentation (DF-IAPF)

The first step involves transforming unstructured text into a semi-structured format. The authors introduced the Document Frequency-Inverse Average Phrase Frequency (DF-IAPF) algorithm. This method identifies section headers by looking for phrases that appear across many different documents but typically occur only once per document—a statistical signature of a section title. This allows the model to segment a note into its constituent parts automatically without manual labeling.

2. Tree-based Contrastive Learning

To combat the long-tail problem, the framework utilizes the hierarchical structure of the ICD taxonomy. Unlike standard contrastive learning, which treats labels as either "same" or "different," this approach uses Tree Edit Distance. Because ICD codes are organized in a tree (where similar diseases share parent nodes), the model is trained to ensure that notes with closely related codes have more similar vector representations than notes with unrelated codes. This "soft similarity" provides the model with a richer signal, helping it understand rare codes by their proximity to more common, related ones.

3. Masked Section Training (CM)

To ensure the model is robust to variations in writing style, the researchers implemented a data augmentation technique called Masked Section Training. During the training phase, the model randomly shuffles the order of sections and masks (removes) certain sections entirely. This forces the model to search for diagnostic evidence across the entire document rather than over-relying on a single, predictable section, making it more resilient to incomplete or disorganized notes.

Experimental Results

The framework was evaluated using the MIMIC-III dataset, a standard benchmark in electronic health record research. The researchers tested their methods across three tasks: MIMIC-50 (frequent codes), MIMIC-rare-50 (rare codes), and MIMIC-full (the complete set of over 8,000 codes).

The results demonstrated consistent improvements across various baseline architectures, such as MultiResCNN and MSMN. The most significant impact was observed in the "long-tail" scenarios:

  • Massive Gains for Rare Codes: On the MIMIC-rare-50 task, the average Macro $F_1$ score improved by a staggering 55.8%. This suggests that structural awareness and hierarchical learning are most effective when data is scarce.
  • General Accuracy: For the MIMIC-50 task, the models saw a stable improvement in Macro $F_1$ (approx. 1.5%), with high statistical significance ($p < 0.01$).
  • Qualitative Evidence: Case studies revealed that the new training strategy allowed models to identify codes like "Personal history of tobacco use" by correctly attending to the "Social History" section—evidence that baseline models frequently overlooked.

Conclusion and Future Directions

By treating clinical notes as semi-structured entities and incorporating the hierarchical logic of medical classification, this framework provides a powerful tool for improving automatic ICD coding. The massive gains in rare code prediction suggest that "structural knowledge" can effectively compensate for "data scarcity."

While the method currently depends on the quality of the underlying text encoder, it sets the stage for "section-native" architectures. Future work will focus on addressing other forms of variability, such as medical abbreviations and typos, and extending these semi-structured learning techniques to other complex document types in the healthcare domain.

Summary updated

BibTeX
@inproceedings{lu2023towards,
  author = {Chang Lu and Chandan K. Reddy and Ping Wang and Yue Ning},
  title = {{Towards Semi-Structured Automatic ICD Coding via Tree-based Contrastive Learning}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=Wff6DWFY2W},
}
Figure