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| 2 |
+
language: en
|
| 3 |
+
tags:
|
| 4 |
+
- medical
|
| 5 |
+
- icd-10
|
| 6 |
+
- clinical-nlp
|
| 7 |
+
- mimic-iv
|
| 8 |
+
- llama
|
| 9 |
+
- lora
|
| 10 |
+
- discriminative
|
| 11 |
+
- text-classification
|
| 12 |
+
base_model: aaditya/Llama3-OpenBioLLM-8B
|
| 13 |
+
datasets:
|
| 14 |
+
- physionet/mimic-iv
|
| 15 |
+
pipeline_tag: text-classification
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
# OpenBioLLM-D — Discriminative ICD-10 Classifier
|
| 19 |
+
|
| 20 |
+
Trained as part of the Master's thesis:
|
| 21 |
+
**"Enhancing Automated ICD-10 Medical Coding with Large Language Models"**
|
| 22 |
+
California State University, Sacramento
|
| 23 |
+
Author: Namirah Imtieaz Shaik
|
| 24 |
+
Advisor: Dr. Haiquan Chen
|
| 25 |
+
|
| 26 |
+
---
|
| 27 |
+
|
| 28 |
+
## Model Description
|
| 29 |
+
|
| 30 |
+
OpenBioLLM-D is a discriminative ICD-10 medical coding model built on top of
|
| 31 |
+
Llama3-OpenBioLLM-8B. It treats ICD-10 coding as a 30-class single-label
|
| 32 |
+
classification problem over the most frequent diagnostic codes in MIMIC-IV
|
| 33 |
+
clinical discharge summaries.
|
| 34 |
+
|
| 35 |
+
**Architecture:**
|
| 36 |
+
- Backbone: aaditya/Llama3-OpenBioLLM-8B loaded via AutoModel (hidden states only, no LM head)
|
| 37 |
+
- LoRA: r=16, alpha=32, targeting q/k/v/o/gate/up/down projections (~0.1% trainable params)
|
| 38 |
+
- Pooling: Masked mean pooling over non-padding token hidden states
|
| 39 |
+
- Head: Two-layer MLP (4096 → 1536 → 30 logits)
|
| 40 |
+
- Loss: CrossEntropyLoss (single-label multiclass)
|
| 41 |
+
|
| 42 |
+
**Training Details:**
|
| 43 |
+
- Dataset: MIMIC-IV discharge summaries
|
| 44 |
+
- Train / Val / Test: 16,540 / 2,068 / 2,068 examples
|
| 45 |
+
- Optimizer: AdamW with cosine LR schedule and 5% warmup
|
| 46 |
+
- Early stopping: monitored on macro F1 with patience=2
|
| 47 |
+
- Text handling: Head+tail cropping (40% head / 60% tail) to fit 512-token limit
|
| 48 |
+
- Results reported as mean ± std across 5 random seeds
|
| 49 |
+
|
| 50 |
+
---
|
| 51 |
+
|
| 52 |
+
## Results
|
| 53 |
+
|
| 54 |
+
| Metric | Score |
|
| 55 |
+
|---|---|
|
| 56 |
+
| Micro F1 | 0.7802 ± 0.0045 |
|
| 57 |
+
| ROC-AUC (Weighted OVR) | 0.9857 ± 0.0004 |
|
| 58 |
+
|
| 59 |
+
**Best performing discriminative model in the thesis.**
|
| 60 |
+
Outperforms BERT-PLM-ICD (0.7466), Longformer-PLM-ICD (0.7316),
|
| 61 |
+
RoBERTa-PLM-ICD (0.7282), Meditron-D (0.7668), and BioMistral-D (0.7776).
|
| 62 |
+
|
| 63 |
+
---
|
| 64 |
+
---
|
| 65 |
+
|
| 66 |
+
## How to Load and Use
|
| 67 |
+
|
| 68 |
+
```python
|
| 69 |
+
from transformers import AutoTokenizer, AutoModel
|
| 70 |
+
from peft import PeftModel
|
| 71 |
+
import torch
|
| 72 |
+
import torch.nn as nn
|
| 73 |
+
from types import SimpleNamespace
|
| 74 |
+
|
| 75 |
+
# Step 1 - Load base model
|
| 76 |
+
base_model = AutoModel.from_pretrained(
|
| 77 |
+
"aaditya/Llama3-OpenBioLLM-8B",
|
| 78 |
+
torch_dtype=torch.float16,
|
| 79 |
+
device_map="auto",
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
# Step 2 - Attach LoRA adapter
|
| 83 |
+
base_model = PeftModel.from_pretrained(
|
| 84 |
+
base_model,
|
| 85 |
+
"Namirah07/OpenBioLLM-D-ICD10",
|
| 86 |
+
subfolder="lora_adapter"
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
# Step 3 - Load tokenizer
|
| 90 |
+
tokenizer = AutoTokenizer.from_pretrained("Namirah07/OpenBioLLM-D-ICD10")
|
| 91 |
+
if tokenizer.pad_token is None:
|
| 92 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 93 |
+
|
| 94 |
+
# Step 4 - Load label map
|
| 95 |
+
import json
|
| 96 |
+
from huggingface_hub import hf_hub_download
|
| 97 |
+
label_map_path = hf_hub_download("Namirah07/OpenBioLLM-D-ICD10", "label_map.json")
|
| 98 |
+
with open(label_map_path) as f:
|
| 99 |
+
label_map = json.load(f)
|
| 100 |
+
id2label = {int(k): v for k, v in label_map["id2label"].items()}
|
| 101 |
+
|
| 102 |
+
# Step 5 - Tokenize and predict
|
| 103 |
+
note = "Patient admitted with chest pain and shortness of breath..."
|
| 104 |
+
inputs = tokenizer(
|
| 105 |
+
note,
|
| 106 |
+
return_tensors="pt",
|
| 107 |
+
truncation=True,
|
| 108 |
+
max_length=512,
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
with torch.no_grad():
|
| 112 |
+
out = base_model(**inputs)
|
| 113 |
+
# Mean pool
|
| 114 |
+
mask = inputs["attention_mask"].unsqueeze(-1).float()
|
| 115 |
+
pooled = (out.last_hidden_state * mask).sum(1) / mask.sum(1)
|
| 116 |
+
|
| 117 |
+
# Note: custom_head.pt must be loaded separately for full inference
|
| 118 |
+
# See GitHub repository for the complete inference pipeline
|
| 119 |
+
print("See GitHub for full inference code including the MLP head")
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
For the complete inference pipeline including the custom MLP head see the
|
| 123 |
+
full training and evaluation code in the GitHub repository below.
|
| 124 |
+
|
| 125 |
+
---
|
| 126 |
+
|
| 127 |
+
## Dataset
|
| 128 |
+
|
| 129 |
+
MIMIC-IV clinical discharge summaries (Johnson et al., 2023).
|
| 130 |
+
Access requires a PhysioNet credentialed account and data use agreement.
|
| 131 |
+
https://physionet.org/content/mimiciv/
|
| 132 |
+
|
| 133 |
+
---
|
| 134 |
+
|
| 135 |
+
## GitHub Repository
|
| 136 |
+
|
| 137 |
+
Full training code, evaluation scripts, hyperparameter tuning scripts,
|
| 138 |
+
and the Gradio explainability demo:
|
| 139 |
+
https://github.com/Namirah07/Enhancing-Automated-ICD-Medical-Coding-with-Large-Language-Models
|
| 140 |
+
|
| 141 |
+
---
|
| 142 |
+
|
| 143 |
+
## Citation
|
| 144 |
+
|
| 145 |
+
```bibtex
|
| 146 |
+
@mastersthesis{shaik2025icd10,
|
| 147 |
+
author = {Namirah Imtieaz Shaik},
|
| 148 |
+
title = {Enhancing Automated ICD-10 Medical Coding with Large Language Models},
|
| 149 |
+
school = {California State University, Sacramento},
|
| 150 |
+
year = {2025},
|
| 151 |
+
advisor = {Dr. Haiquan Chen}
|
| 152 |
+
}
|
| 153 |
+
```
|
| 154 |
+
|
| 155 |
+
---
|
| 156 |
+
|
| 157 |
+
## License
|
| 158 |
+
|
| 159 |
+
MIT License.
|
| 160 |
+
The base model (Llama3-OpenBioLLM-8B) is subject to its own license on HuggingFace.
|
| 161 |
+
The MIMIC-IV dataset requires a PhysioNet data use agreement.
|