Downloads · 30 days
0
shalindasilva1/SOAPGemma
SOAPGemma is a text generation model from shalindasilva1. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as mit.
SOAPgemmav1 is a LoRA-fine-tuned version of Google's google/txgemma-2b-predict model, specifically adapted for generating medical SOAP (Subjective, Objective, Assessment, Plan) notes from patient-doctor dialogues.
Downloads · 30 days
0
Access
Public
Updated May 29, 2025
Repo size
75.9 MB
Likes
0
Public
Click a slice to open those files.
.safetensors41.6 MB · 55%
From the Hugging Face model README
SOAPgemma_v1 is a LoRA-fine-tuned version of Google's google/txgemma-2b-predict model, specifically adapted for generating medical SOAP (Subjective, Objective, Assessment, Plan) notes from patient-doctor dialogues.
This model was developed as a collaborative effort by:
google/txgemma-2b-predict (a Gemma 2 architecture derivative)SOAPGemma aims to alleviate the significant documentation burden faced by healthcare professionals. SOAP notes are a structured and essential method for recording patient encounters. This model takes a transcribed patient-doctor dialogue as input and generates a structured SOAP note, summarizing the key information into Subjective, Objective, Assessment, and Plan sections.
The primary goal is to improve clinical efficiency, reduce administrative workload, and allow clinicians to dedicate more time to direct patient care.
This model is a PEFT LoRA adapter. To use it, you need to load the base model (google/txgemma-2b-predict) and then apply this adapter.
import torch
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
# Define the base model ID and the adapter path (your Hugging Face model ID for SOAPgemma_v1)
base_model_id = "google/txgemma-2b-predict"
adapter_model_id = "your_username/SOAPgemma_v1" # Replace with your actual model ID on Hugging Face
# Configure 4-bit quantization
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16
)
# Load the base model with quantization
base_model = AutoModelForCausalLM.from_pretrained(
base_model_id,
quantization_config=bnb_config,
device_map="auto", # Automatically maps model to available devices (GPU/CPU)
trust_remote_code=True # If required by the base model
)
# Load the tokenizer
tokenizer = AutoTokenizer.from_pretrained(base_model_id)
if tokenizer.pad_token is None:
tokenizer.pad_token = tokenizer.eos_token # Set pad token if not set
# Load the PEFT adapter
model = PeftModel.from_pretrained(base_model, adapter_model_id)
model.eval() # Set the model to evaluation mode
# Example dialogue
dialogue = """
Doctor: Hello, how can I help you today?
Patient: I've been having this persistent cough for about two weeks now. It's dry and sometimes I get a bit short of breath, especially when I climb stairs.
Doctor: Any fever, chills, or body aches?
Patient: No fever, no chills. Just this annoying cough and some fatigue.
Doctor: Okay, let's have a listen to your lungs. (Performs examination) Lungs sound clear. Have you had any recent colds or flu?
Patient: Not really, no.
Doctor: We should probably get a chest X-ray to be sure. In the meantime, try to rest and use a humidifier. I'll also prescribe a cough suppressant.
"""
# Format the input for the model (ensure this matches your fine-tuning format)
# The prompt structure used during fine-tuning was:
# "dialogue: {dialogue}<soap_start> soap_note:{soap_note} <eos>"
# For inference, we provide the dialogue and the start token for the soap_note.
input_text = f"dialogue: {dialogue}<soap_start> soap_note:"
# Tokenize the input
inputs = tokenizer(input_text, return_tensors="pt", padding=True, truncation=True, max_length=1536).to(model.device)
# Generate the SOAP note
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=512, # Adjust as needed
num_beams=1, # Using num_beams=1 for greedy decoding, can be increased for beam search
temperature=0.7, # Adjust for creativity vs. factuality
pad_token_id=tokenizer.eos_token_id,
eos_token_id=tokenizer.eos_token_id
)
# Decode the output
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
# Extract the SOAP note part
# The generated text will include the input prompt, so we need to extract the part after "soap_note:"
soap_note_start_phrase = "soap_note:"
generated_soap_note = generated_text.split(soap_note_start_phrase)[-1].strip()
print("Dialogue:\n", dialogue)
print("\nGenerated SOAP Note:\n", generated_soap_note)