From Documents to Spans: Span-Centric Learning for LLM-based Explainable Medical Coding
Authors: Xu Zhang, Wenxin Ma, Chenxu Wu, Rongsheng Wang, Zhiyang He, Xiaodong Tao, Kun Zhang, S. Kevin Zhou
Organizations: School of Biomedical Engineering, Division of Life Sciences and Medicine, USTC · MIRACLE Center, Suzhou Institute for Advance Research, USTC · iFlyHealth · Jiangsu Provincial Key Laboratory of Multimodal Digital Twin Technology · State Key Laboratory of Precision and Intelligent Chemistry, USTC
Medical coding, which assigns standardized ICD codes to clinical documents, is a fundamental yet challenging task in modern healthcare. It requires extensive knowledge of a large code space and the ability to identify and interpret sparse supporting evidence in long, noisy clinical documents. Most existing methods rely on document-level supervision, which provides limited guidance on supporting evidence and insufficient training signals for rare codes. To address these limitations, we propose Span-Centric Learning (SCL), which separates coding knowledge acquisition from its application in full documents. SCL first learns coding knowledge from short spans, then learns to use this knowledge in full documents from a small set of annotated data. Experiments show that, our approach enables an 8B LLM to surpass state-of-the-art methods using only 248 complete documents for training. It also provides explicit supporting evidence for each predicted code, with strong alignment to human annotations. Further analysis shows that the model can learn knowledge of codes absent from documents through spans and apply that knowledge to full documents.
Figures & tables
Figure 1: Motivation. Human coders assign medical codes by identifying supporting evidence in clinical documents. Motivated by this process, our method first learns broad coding knowledge from span data, and then transfers learned knowledge to document-level explainable medical coding.
Figure 2: Overview of SCL framework. Span Data Construction (Sec 3.2 ) constructs, expands and refines a span library from public medical coding datasets. Span-Centric Staged Learning (Sec 3.3 ) first learns broad coding knowledge from the span library, then learns to apply knowledge to document-level medical coding from a small set of high-quality CoT data, with mixed-batch replay of a randomly sampled fraction of the span library. At inference, the model identifies evidence spans in unseen documents and assigns corresponding codes.
Method
Venue
ACI
MDACE
Avg
F1
P
R
F1
P
R
F1
Full codes (complete ICD-10-CM code space, ∼ 70k codes)
PLM-ICD
NAACL 22 WS
21.0
12.5
65.2
54.8
52.4
57.5
37.9
GKI-ICD
ACL’25
42.6
31.8
64.4
54.5
53.5
55.5
48.6
MedCodER-GPT5
NAACL’25
62.0
57.0
68.0
40.0
37.0
42.0
51.0
CLH-GPT5
EMNLP’25
57.2
58.5
56.0
46.0
40.0
55.0
51.6
Table 1: Performance comparison with state-of-the-art methods. F1, P, and R denote micro-averaged F1, precision, and recall; Avg is the mean F1 over the two benchmarks. Bold : best in each setting; green : gain over the best baseline.
Method
Training data
ACI
MDACE
Time (hr)
Explainability
Docs
Spans
Micro-F1
Macro-F1
Micro-F1
Macro-F1
SFT
120k
–
47.9
15.7
47.0
24.0
252
✗
SFT E
120k
–
53.6
29.6
55.7
30.2
264
✓
SCL (Ours)
248
200k
67.3 ∗ +19.4
41.0 +25.3
57.2 ∗ +10.2
32.4 +8.4
22
✓
Table 2: Full-document supervision vs. span-centric supervision. All models use Llama3-8B and are trained on a single H20 GPU. SFT and SFT E use about 120k training documents from MIMIC-IV, MDACE, and ACI, with the latter augmented with evidence generated by Llama-3.3-70B for document-level distillation. SCL uses 248 evidence-annotated documents and 200k spans. ∗ indicates p<10−2 vs. SFT (two-sided paired permutation tests, Holm-adjusted). Green : gain over SFT.
Metric
Doc
Doc & Span
Rule-based (lexical matching)
Exact Match Rate
99.3
98.9
Hit Rate (IoU > 0)
67.1
74.5 +7.4
Hit Rate (IoU > 0.5)
47.0
54.2 +7.1
LLM-based (semantic matching)
Recall
64.6
73.9 +9.2
Table 3: Evaluation of model-predicted evidence on MDACE. We additionally include LLM-based metrics, since there may be multiple semantically equivalent evidence spans for one code in a document. All scores are percentages; bold : better; green : gain over Doc.
Figure 3: Learning new code knowledge from spans on ACI. (a) We divide ACI test-set codes into two groups: codes covered by both the 248 training documents and the span library, and codes covered by the span library but absent from all 248 training documents. (b) Span-level supervision substantially improves coding performance for codes absent from these documents, without requiring additional training documents.
Span library
Naturalness
Plausibility
Initial spans
98.71
77.38
+ Span Synthesis
96.50
66.51
+ Iterative Refinement
100.00
100.00
Table 4: Span quality across iterative refinement. Naturalness and plausibility are pass rates (%) under LLM-based assessment.
Strategy
Micro-F1
Time (hr)
One-stage
Direct mixing
52.8
50
Separate long/short batches
42.9
20
Two-stage
w/o replay
43.8
22
w/ replay
57.2
22
Table 5: Ablation of training strategies. We compare different strategies for mixing long documents and short spans. Our two-stage strategy achieves the best performance while substantially shortening training time.
Variant
Micro-F1
Macro-F1
Documents only
w/o evidence CoT
36.8
13.9
w/ evidence CoT
43.9
17.9
Documents & spans
Initial spans
48.9
22.7
+ Span Synthesis
53.7
27.9
Table 6: Incremental ablation of span-centric supervision. Starting from initial spans, we progressively add span synthesis and iterative refinement. Span synthesis uses no rejected spans or rejection reasons; this feedback is introduced with iterative refinement.
Appendix figures & tables6 assets
Supplementary material from the paper’s appendix.
Appendix
Size
Micro-F1
Macro-F1
P
R
Llama-3.2
1B
40.8
16.0
48.6
35.2
3B
53.2
26.0
60.6
47.4
Qwen2.5
0.5B
31.8
10.6
44.2
24.9
1.5B
50.6
24.1
57.8
45.0
Appendix
Table 7: Scaling law of SCL under restricted code evaluation. Results on MDACE with Llama and Qwen backbones of different sizes. P and R denote micro-averaged precision and recall.
Figure 4: Paradigm comparison on an MDACE test case. Supervised methods predict codes without evidence. Explainable methods provide evidence but with lower coding accuracy. SCL recovers both the evidence spans and the ICD codes that match the expert annotation.
Note
CC: Right arm pain. HPI: Ms. Martinez is a 43-year-old female who presents today for an evaluation of right arm pain after she hitting her arm on a pole while playing tennis . She had mild swelling at the time. There is pain with motion. She denies any numbness or tingling in her hand. She has a past medical history of allergies and takes Flonase. Exam: Examination of the left wrist shows tenderness over the distal radius and pain with flexion of the wrist and thumb. Results: X-rays of the left wrist show no obvious signs of acute fracture or other abnormality. Impression: Right wrist sprain . Plan: At this point, I discussed the diagnosis and treatment options with the patient. I have recommended ice and anti-inflammatory medications. I am prescribing Motrin, 800 mg to take 3 times a day with food. She will follow up with me in 1 week or as needed.
Prediction
Right wrist sprain
S63.501A
Unspecified sprain of right wrist, initial encounter
hitting her arm on a pole
W22.8XXA
Striking against or struck by other objects, initial encounter
playing tennis
Y93.73
Activity, racquet and hand sports
Gold
S63.501A
Unspecified sprain of right wrist, initial encounter
Appendix
Table 8: Failure case from the ACI test set. The note documents a right wrist sprain after the patient hit her arm on a pole while playing tennis. SCL codes the injury, the mechanism, and the activity, while the gold annotation contains only the injury code.
Model output
Source text
Macro s ytosis
Macro c ytosis
Astha
Asth m a
emia
an emia
f e ll from a ladder
f a ll from ladder
ventricular fibrillation
vtach/ vfib arrest
Appendix
Table 9: Evidence rewriting errors that prevent source traceability. Model outputs and corresponding source text are reproduced verbatim; red marks the rewritten parts.
Category
Count
Unique codes
Initial assignments
1,765,371
16,156
Supported
1,380,071
14,275
No evidence found
363,639
1,635
Appendix
Table 10: Evidence availability in MIMIC-IV extraction. Counts refer to code assignments. No evidence found denotes assignments for which the extraction pipeline identifies no supporting span in the available discharge summary. Some extraction outputs could not be parsed and are excluded from both outcome categories, so their counts do not sum to the initial total.
Criterion
Matched/total
Agreement (%)
Naturalness
4,532 / 4,645
97.57
Plausibility
4,497 / 4,645
96.81
Appendix
Table 11: Agreement between LLM and human evaluations. All 4,645 spans passed both LLM-based criteria. Matched/total reports the number also judged by human evaluators to satisfy each criterion over the total number evaluated.
Automated International Classification of Diseases (ICD) coding is a core medical-coding task for billing, epidemiology, and clinical decision support. Generative large language models (LLMs) are often reported as weak medical coders, but this finding mainly comes from inference-time settings such as prompting, retrieval, reranking, or tool use, leaving the role of task-specific post-training underexplored. We present a controlled empirical study of post-training for generative ICD coding, comparing discriminative baselines with LLM coders across prompting, supervised fine-tuning, and reinforcement learning under a common protocol and metric set. To our knowledge, this is the first study to evaluate RL-based post-training for generative LLM coders in ICD coding. We further introduce PHI, a diagnostic curriculum that extends GRPO to refine missed-code cases. Our results show that prompting-only evaluation substantially underestimates the potential of LLMs for ICD coding. SFT provides the main capability jump, GRPO further improves code-set prediction beyond SFT, and PHI provides targeted gains on macro-level performance. These findings suggest that the main bottleneck is not the generative formulation alone, but how the model is adapted and optimized for full-taxonomy recall. We release our code, data splits, and checkpoints at https://github.com/AlexandreWANG915/LLM4ICD.
Automatic medical coding assigns ICD codes to clinical notes, but it remains challenging due to long documents, imbalanced label distributions, and diverse terms. These challenges are especially severe for rare codes, which have limited training instances and are easily confused with semantically similar labels. We introduce CoLa-ICD, a knowledge-enhanced framework for long-tail prediction. CoLa-ICD enriches ICD labels with external terms, models dependencies among related codes, and learns stronger alignment between label semantics and clinical evidence for long-tail prediction. Experiments show that CoLa-ICD improves long-tail prediction with larger gains in larger and sparser label spaces and achieves state-of-the-art performance in AUC, F1, and P@k. Our code is available at https://github.com/youwillbethebest/Cola-ICD.
Accurate medical coding requires consulting authoritative resources such as the ICD tabular list and coding guidelines. Existing LLM-based automated methods largely rely on LLMs' internal knowledge, which is prone to hallucination and cannot keep pace with guideline updates. We introduce RAG-Coding, an agentic, training-free method that augments LLMs with structured external knowledge: the tabular list is encoded as a knowledge graph capturing hierarchical and instructional code relationships, and the guidelines are distilled into concise, code-specific summaries rather than retrieved as raw text. To enable our study, we also introduce MDACE-2025, expert re-annotations of the MDACE dataset under the 2025 ICD-10-CM/PCS guidelines, adding code sequencing and justification comments. On MDACE, RAG-Coding outperforms the best LLM-based baseline by 3--13% in micro-F1 across five LLM backbones, and achieves comparable micro- and macro-F1 to the supervised state-of-the-art, with higher recall (+11%) at the cost of precision (−6%). On MDACE-2025, RAG-Coding outperforms all baselines, demonstrating effective generalisation to updated guidelines. Ablations confirm stepwise gains, highlighting the importance of integrating structured external knowledge for LLM-based medical coding.
Yidong Gan, David D. Nguyen, Yang Lin +4
Oracle Health and AI · The University of Sydney · CSIRO Data61