Enhancing medical coding efficiency through domain-specific fine-tuned large language models

Zhen Hou, Hao Liu, Jiang Bian, Xing He, Yan ZhuangNpj 2025

Abstract: Medical coding is essential for healthcare operations yet remains predominantly manual, error-prone (up to 20%), and costly (up to $18.2 billion annually). Although large language models (LLMs) have shown promise in natural language processing, their application to medical coding has produced limited accuracy. In this study, we evaluated whether fine-tuning LLMs with specialized ICD-10 knowledge can automate code generation across clinical documentation. We adopted a two-phase approach: initial fine-tuning using 74,260 ICD-10 code-description pairs, followed by enhanced training to address linguistic and lexical variations. Evaluations using a proprietary model (GPT-4o mini) on a cloud platform and an open-source model (Llama) on local GPUs demonstrated that initial fine-tuning increased exact matching from <1% to 97%, while enhanced fine-tuning further improved performance in complex scenarios, with real-world clinical notes achieving 69.20% exact match and 87.16% category match. These findings indicate that domain-specific fine-tuned LLMs can reduce manual burdens and improve reliability.

Introduction

Medical coding—the process of translating physician notes into standardized ICD-10 codes—is the backbone of healthcare billing, research, and policy. However, it is currently a manual, labor-intensive process prone to error rates as high as 20%. In the US alone, this inefficiency costs approximately $18.2 billion annually. While Large Language Models (LLMs) like GPT-4 show promise in general reasoning, they struggle with medical coding due to three main factors:

  1. The "Long Tail" Problem: There are over 74,000 unique ICD-10 codes; general models often hallucinate non-existent codes or struggle with rare ones.
  2. Linguistic Variability: Clinical notes are filled with shorthand (e.g., "HTN" for hypertension), typos ("malignnt"), and complex, multi-condition sentences.
  3. Token Limits: The entire ICD-10 codebook exceeds the context window of most models, making simple prompting ineffective.

Methodology

To address these challenges, we proposed a two-stage fine-tuning approach to embed domain knowledge directly into the models' parameters. This strategy moves beyond simple prompting or Retrieval-Augmented Generation (RAG) by teaching the model the "dictionary" of medical codes.

  • Phase 1: Knowledge Integration. The models were first trained on 74,260 pairs of ICD-10 codes and their official descriptions. This established a "ground truth" dictionary within the model.
  • Phase 2: Enhanced Clinical Variation Training. To handle the "messiness" of real medicine, we used a pipeline (leveraging the Claude model) to generate 20,000 synthetic training samples. These samples mimicked five common clinical variations: reordered expressions, typographical errors, medical abbreviations, multiple concurrent conditions, and embedded diagnostic details.
Workflow of the two-phase fine-tuning process for medical coding LLMs.

The study evaluated both proprietary models (GPT-4o mini) and open-source models (Llama-3.2-1B, 3B, and Llama-3.1-8B) to compare performance across different scales and architectures. Evaluation was conducted using the ICD-10-CM set, a synthetic variation dataset, and the MIMIC-IV dataset, which contains 2,211 real-world discharge summaries.

Results and Error Analysis

The results demonstrate that domain-specific fine-tuning is the key to unlocking LLM utility in healthcare. Initial fine-tuning increased exact match rates from <1% to 97% for both GPT-4o mini and Llama models on standardized tasks. For complex scenarios involving "Multiple Concurrent Conditions," accuracy jumped from a dismal ~4-10% after initial fine-tuning to 94-98% after the second phase of enhanced training.

On the MIMIC-IV clinical notes, the enhanced Llama-3.2-1B model achieved a 69.20% Exact Match (Top-1 accuracy) and an 87.16% Category Match (matching the first three characters of the code).

Comparison of error distributions across GPT-4o-mini and Llama model variants.

Error analysis revealed that fine-tuning significantly reduced "Non-existence Errors" (hallucinating fake codes), which is a critical requirement for deployment in healthcare. While models became highly proficient at exact matches, they occasionally struggled with "Hierarchy-Level Errors"—picking a code that was close but slightly too specific or too broad. This highlights the need for models to understand the tree-like structure of medical taxonomies.

Discussion and Conclusion

This study confirms that LLM failures in medical coding are often due to a lack of specific "knowledge" rather than a lack of reasoning ability. Interestingly, after enhanced fine-tuning, the smallest model (Llama-3.2-1B) performed remarkably well, often rivaling much larger models. This suggests that for specific tasks, a "small but specialized" model is more efficient than a "large and general" one.

Despite this success, manual review remains essential for nuanced cases where clinical reasoning is required. Future work will focus on evaluating "truly rare" codes and integrating these models with healthcare standards like FHIR to allow for seamless data flow across hospital systems. Ultimately, these findings indicate that domain-specific fine-tuned LLMs can significantly reduce manual burdens and improve the reliability of healthcare operations.

Summary updated

BibTeX
@inproceedings{hou2025enhancing,
  author = {Zhen Hou and Hao Liu and Jiang Bian and Xing He and Yan Zhuang},
  title = {{Enhancing medical coding efficiency through domain-specific fine-tuned large language models}},
  booktitle = {Npj},
  year = {2025},
  doi = {10.1038/s44401-025-00018-3},
}
Figure