Views
No views yet
1from transformers import AutoTokenizer
2import torch
3import pickle
4import numpy as np
5
6# Load tokenizer
7tokenizer = AutoTokenizer.from_pretrained("sshan95/clinical-medical-coding-comprehension")
8
9# Load label encoder
10with open("label_encoder.pkl", "rb") as f:
11 label_encoder = pickle.load(f)
12
13# Load classes
14with open("classes.json", "r") as f:
15 classes = json.load(f)
16
17# Example clinical text
18clinical_text = '''
19Patient presents with acute chest pain and shortness of breath.
20History of hypertension and diabetes. Physical exam reveals elevated blood pressure.
21ECG shows ST elevation. Troponin levels elevated.
22Diagnosed with acute myocardial infarction.
23Initiated on aspirin, metoprolol, and heparin.
24'''
25
26# Preprocess and tokenize
27inputs = tokenizer(
28 clinical_text,
29 return_tensors="pt",
30 truncation=True,
31 padding=True,
32 max_length=384
33)
34
35# Get predictions (load full model first)
36# with torch.no_grad():
37# outputs = model(**inputs)
38# predictions = (outputs > 0.15).float() # Use optimal threshold
39# predicted_codes = [classes[i] for i in torch.where(predictions[0])[0]]