NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Does the Magic of BERT Apply to Medical Code Assignment? A Quantitative Study

Shaoxiong Ji, Matti Hölttä, Pekka Marttinen · DOI

Abstract

Unsupervised pretraining is an integral part of many natural language processing systems, and transfer learning with language models has achieved remarkable results in many downstream tasks. In the clinical application of medical code assignment, diagnosis and procedure codes are inferred from lengthy clinical notes such as hospital discharge summaries. However, it is not clear if pretrained models are useful for medical code prediction without further architecture engineering. This paper conducts a comprehensive quantitative analysis of various contextualized language models' performance, pretrained in different domains, for medical code assignment from clinical notes. We propose a hierarchical fine-tuning architecture to capture interactions between distant words and adopt label-wise attention to exploit label information. Contrary to current trends, we demonstrate that a carefully trained classical CNN outperforms attention-based models on a MIMIC-III subset with frequent codes. Our empirical findings suggest directions for improving the medical code assignment application.

Introduction

Medical code assignment is the process of assigning standardized International Classification of Diseases (ICD) codes to clinical narratives, such as discharge summaries. This task is critical for billing, clinical research, and hospital management. However, it presents a significant challenge in natural language processing (NLP) due to the "extreme multi-label classification" nature of the problem—notes can be thousands of words long, and the label space encompasses nearly 9,000 codes.

While BERT-based models have revolutionized general NLP, their "magic" is not automatically transferable to the clinical domain. This study investigates whether the contextual representations learned by BERT actually improve performance over classical architectures like Convolutional Neural Networks (CNNs) in this specialized task.

Methodology

The researchers evaluated several strategies to adapt BERT for the nuances of medical coding, focusing on pre-training domains and architectural modifications.

Pre-training and Fine-tuning Pipeline

The study compared models pre-trained on diverse datasets, ranging from general-domain text (Wikipedia, Books) to domain-specific corpora like PubMed abstracts, PMC full-text articles, and clinical notes from the MIMIC-III database.

Overview of the pre-training domains and the fine-tuning pipeline for ICD coding.

To address the 512-token limitation of standard BERT models, a hierarchical fine-tuning (BERT-hier) approach was implemented. Long clinical notes were divided into chunks, encoded individually, and then aggregated using a Transformer layer to capture document-wide dependencies. Furthermore, a Label-wise Attention (LAN) mechanism was integrated, allowing the model to attend to specific segments of the text relevant to each individual ICD code.

Experimental Setup

The models were evaluated using the MIMIC-III (Medical Information Mart for Intensive Care) dataset. Two primary subsets were used:

  • MIMIC-III top-50: Focused on the 50 most frequent codes.
  • MIMIC-III full: Included the complete set of 8,921 codes, highlighting the challenges of the "long tail" of rare codes.

Key Results and Discussion

The quantitative analysis yielded several surprising insights that challenge the current trend of assuming Transformer-based models are always superior.

The CNN Comeback

The most notable finding was that a vanilla CNN, when retrained with modern optimization techniques (e.g., specific learning rates and dropout), outperformed all BERT variants on the top-50 dataset. The CNN achieved a Macro AUC-ROC of 90.8, surpassing the best-performing BERT model (PubMedBERT). This suggests that for clinical coding, local feature extraction—a strength of CNNs—may be more critical than the global self-attention of Transformers.

Performance of BERT Variants

Among the Transformer models, those pre-trained from scratch on biomedical text (like PubMedBERT) generally outperformed those that were merely continued from general-domain BERT. This underscores the importance of domain-specific vocabulary and context.

Performance metrics for various BERT variants on MIMIC-III Top-50 and Full code sets.

As shown in the results table, PubMedBERT (using the hierarchical structure and LAN) was the top Transformer performer, particularly in Micro F1 (68.1) on the top-50 set. However, all models struggled significantly with the "Full Codes" set, where the extreme sparsity of rare labels remains a major hurdle.

Conclusion

This study demonstrates that BERT is not a "magic bullet" for medical code assignment. While hierarchical architectures and domain-specific pre-training improve performance, classical CNNs remain highly competitive and even superior for frequent codes. Future research should explore more efficient architectures for long-range dependencies, such as Longformer or Big Bird, and focus on improving "few-shot" learning for the thousands of rare medical codes that currently limit the utility of automated systems.

Summary updated

BibTeX
@article{ji2021does,
  author = {Shaoxiong Ji and Matti Hölttä and Pekka Marttinen},
  title = {{Does the Magic of BERT Apply to Medical Code Assignment? A Quantitative Study}},
  journal = {Computers in Biology and Medicine},
  year = {2021},
  doi = {10.1016/j.compbiomed.2021.104998},
}
Figure