Views
No views yet
| Metric | Score |
|---|---|
| Micro F1 | 0.7802 ± 0.0045 |
| ROC-AUC (Weighted OVR) | 0.9857 ± 0.0004 |
1from transformers import AutoTokenizer, AutoModel
2from peft import PeftModel
3import torch
4import torch.nn as nn
5from types import SimpleNamespace
6
7# Step 1 - Load base model
8base_model = AutoModel.from_pretrained(
9 "aaditya/Llama3-OpenBioLLM-8B",
10 torch_dtype=torch.float16,
11 device_map="auto",
12)
13
14# Step 2 - Attach LoRA adapter
15base_model = PeftModel.from_pretrained(
16 base_model,
17 "Namirah07/OpenBioLLM-D-ICD10",
18 subfolder="lora_adapter"
19)
20
21# Step 3 - Load tokenizer
22tokenizer = AutoTokenizer.from_pretrained("Namirah07/OpenBioLLM-D-ICD10")
23if tokenizer.pad_token is None:
24 tokenizer.pad_token = tokenizer.eos_token
25
26# Step 4 - Load label map
27import json
28from huggingface_hub import hf_hub_download
29label_map_path = hf_hub_download("Namirah07/OpenBioLLM-D-ICD10", "label_map.json")
30with open(label_map_path) as f:
31 label_map = json.load(f)
32id2label = {int(k): v for k, v in label_map["id2label"].items()}
33
34# Step 5 - Tokenize and predict
35note = "Patient admitted with chest pain and shortness of breath..."
36inputs = tokenizer(
37 note,
38 return_tensors="pt",
39 truncation=True,
40 max_length=512,
41)
42
43with torch.no_grad():
44 out = base_model(**inputs)
45 # Mean pool
46 mask = inputs["attention_mask"].unsqueeze(-1).float()
47 pooled = (out.last_hidden_state * mask).sum(1) / mask.sum(1)
48
49# Note: custom_head.pt must be loaded separately for full inference
50# See GitHub repository for the complete inference pipeline
51print("See GitHub for full inference code including the MLP head")1@mastersthesis{shaik2025icd10,
2 author = {Namirah Imtieaz Shaik},
3 title = {Enhancing Automated ICD-10 Medical Coding with Large Language Models},
4 school = {California State University, Sacramento},
5 year = {2025},
6 advisor = {Dr. Haiquan Chen}
7}