This video shows how to install Sum Small which is a powerful language model specifically designed to generate SOAP summaries from medical dialogues.
Code:
!pip install transformers
!pip install accelerate
!pip install -i https://pypi.org/simple/ bitsandbytes
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
import warnings
warnings.filterwarnings('ignore')
MODEL_NAME = 'omi-health/sum-small'
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, device_map='cuda', load_in_8bit=True,trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
dialogue ='''Doctor: Hello, can you please tell me about your past medical history?
Patient: Hi, I don't have any past medical history. Doctor:
Okay. What brings you in today? Patient: I've been experiencing
painless blurry vision in my right eye for a week now.
I've also had intermittent fevers, headache, body aches, and a nonpruritic
maculopapular rash on my lower legs for the past 6 months.
Doctor: Thank you for sharing that. Have you had any other symptoms such
as neck stiffness, nausea, vomiting, Raynaud's phenomenon, oral ulcerations
, chest pain, shortness of breath, abdominal pain,
or photosensitivity? Patient: No, only an isolated episode of left knee swelling
and testicular swelling in the past. Doctor: Do you work with
any toxic substances or have any habits like smoking,
drinking, or illicit drug use? Patient: No, I work as a flooring
installer and I don't have any toxic habits. Doctor: Alright.
We checked your vital signs and they were normal. During the physical exam,
we found bilateral papilledema and optic nerve
erythema in your right eye, which was greater than in your left eye.
You also have a right inferior nasal quadrant visual field defect and a
right afferent pupillary defect. Your muscle strength and reflexes were
normal, and your sensation to light touch,
pinprick, vibration, and proprioception was intact. We also noticed the
maculopapular rash on your bilateral lower extremities. Patient: Oh,
I see. Doctor: Your admitting labs showed some abnormal results.
You have microcytic anemia with a hemoglobin of 11.6 gm/dL, hematocrit of
35.3%, and mean corpuscular volume of 76.9 fL. You also have
hyponatremia with a sodium level of 133 mmol/L. Your erythrocyte
sedimentation rate (ESR) is elevated at 33 mm/hr, and your
C-reactive protein (CRP) is also elevated at 13.3 mg/L.
Your urinalysis did not show any protein or blood.
Patient: Okay. What does that mean? Doctor: These results could
indicate an underlying inflammatory or infectious process. We also performed a lumbar puncture, which
showed clear and colorless fluid, 2 red blood cells per
microliter, and 56 white blood cells per microliter.
Patient: So, what's the next step? Doctor: We need to investigate
further to determine the cause of your symptoms. We'll run additional
tests and consult with a specialist to get a clearer understanding of your
condition. In the meantime, we'll monitor your symptoms and provide supportive
care. We'll keep you informed about any new findings and discuss the
best course of treatment. Patient: Alright, thank you, Doctor.'''
prompt_short = f"""Instruct: Create a medical SOAP summary of this dialogue:
### Dialogue:
{dialogue}
### Your SOAP Summary:
"""
prompt = f"""
role: system, content: You are an expert medical professor assisting in the creation of medically accurate SOAP summaries. Please ensure the response follows the structured format: S:, O:, A:, P: without using markdown or special formatting.
role: user, content:{prompt_short}
"""
inputs = tokenizer(
prompt,
return_tensors="pt",
return_attention_mask=False
)
inputs = inputs.to('cuda')
outputs = model.generate(**inputs, max_length=1000, pad_token_id=tokenizer.eos_token_id)
text = tokenizer.batch_decode(outputs)[0]
print(text[len(prompt):])
No comments:
Post a Comment