Medical Dialogue to SOAP Note Generation

Model Overview

med_dialogue2soap is a fine-tuned model based on microsoft/Phi-3-mini-4k-instruct. The model has been specifically trained to generate SOAP notes (Subjective, Objective, Assessment, Plan) from medical dialogues. It processes doctor-patient conversations and automatically summarizes them into structured medical documentation, aiding healthcare professionals in creating accurate patient records efficiently.

  • Model Type: Text Generation
  • Base Model: microsoft/Phi-3-mini-4k-instruct
  • Fine-tuned Task: Generating SOAP notes from medical dialogues
  • Language(s): English
  • License: [MIT / Apache 2.0 / etc.]
  • Developed by: raselmeya2194

Model Details

Training Overview

  • Training Framework: PEFT (Parameter-Efficient Fine-Tuning)
  • Batch Size: 1 (per device)
  • Epochs: 3
  • Learning Rate: 2e-4
  • FP16 Training: Enabled (for memory efficiency)
  • Gradient Accumulation: Simulated batch size of 8 with gradient_accumulation_steps=8
  • Evaluation: Evaluated every 200 steps with loss-based early stopping (eval_loss)

Training Results

  • Training Loss: 0.900
  • Steps: 750
  • Training Runtime: 4 hours and 23 minutes
  • Train Samples per Second: 0.381
  • Train Steps per Second: 0.048

Evaluation Results

  • Eval Loss: 0.841
  • Eval Runtime: 197.51 seconds
  • Eval Samples per Second: 1.215
  • Mean Token Accuracy: 77.19%
  • Entropy: 0.805

Model Use

Direct Use

You can directly use this model to generate SOAP notes from a doctor-patient dialogue by passing the conversation as input. Here's how you can use the model:

from transformers import AutoTokenizer, AutoModelForCausalLM

# Load the fine-tuned model and tokenizer
model_name = "raselmeya2194/med_dialogue2soap"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

# Define the doctor-patient dialogue (input_text)
input_text = """
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: Alright, thank you, Doctor.
"""

# Format the input with special tokens
prompt = f"<|user|>\nGenerate a SOAP note based on the following doctor-patient dialogue:\n\n{input_text}<|end|>\n<|assistant|>SOAP Notes:\n"

# Tokenize the input with special tokens
inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=512)

# Generate the SOAP note
outputs = model.generate(
    inputs["input_ids"],
    max_new_tokens=512,  # Adjust based on the size of the output you want
    temperature=0.7,
    top_p=0.9,
    pad_token_id=tokenizer.eos_token_id,
    eos_token_id=tokenizer.eos_token_id,
)

# Decode the output tokens to text
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True).strip()

# Print the generated SOAP note
print(generated_text)

Model Output Example

Input:

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...

Generated SOAP Note:

SOAP Notes:
- **Subjective**: Patient reports blurry vision in the right eye for the past week. Also experiencing intermittent fevers, headache, body aches, and a nonpruritic rash on the lower legs for the past 6 months.
- **Objective**: Vital signs are normal. Physical exam reveals bilateral papilledema, optic nerve erythema in the right eye, and a right afferent pupillary defect.
- **Assessment**: Possible underlying inflammatory or infectious process, including autoimmune or infectious causes like viral infections or systemic lupus erythematosus.
- **Plan**: Further testing and specialist consultation needed. Continue supportive care and monitor symptoms.

Model Evaluation

Testing Data & Metrics

The model was evaluated on a dataset containing doctor-patient dialogues, focusing on the model's ability to generate coherent and accurate SOAP notes from medical conversations.

  • Evaluation Metrics:

    • Eval Loss: 0.841
    • Mean Token Accuracy: 77.19%
    • Eval Entropy: 0.805

The model performed well in generating relevant and structured SOAP notes, with a mean token accuracy of 77.19% and a relatively low entropy, indicating good confidence in the generated output.

How It Works

Input Format

The model requires input in the form of a dialogue between a doctor and a patient. You should format the input text as a conversation with clear speaker labels.

Output Format

The model generates a structured SOAP note containing:

  • Subjective: Information provided by the patient about symptoms, history, and concerns.
  • Objective: Objective findings from the physical exam, lab results, and vital signs.
  • Assessment: The doctor’s clinical reasoning or differential diagnosis.
  • Plan: Next steps for diagnosis, treatment, and follow-up.

Bias, Risks, and Limitations

Bias

The model may exhibit biases present in its training data. The data primarily includes English-language doctor-patient dialogues, which may limit its generalization to other languages or healthcare systems.

Risks

  • Accuracy: Always review generated SOAP notes for medical accuracy before use in clinical settings.
  • Privacy: Ensure compliance with privacy regulations (e.g., HIPAA, GDPR) when using the model with real patient data.
  • Misuse: The model should not be used to replace human clinical judgment. It should assist healthcare professionals in documenting patient encounters but not make clinical decisions.

Recommendations

The generated SOAP notes should always be reviewed by qualified healthcare providers. The model is intended as a tool for automating the documentation process and should not be solely relied upon for clinical decision-making.

Training Details

Data

The model was fine-tuned on a curated medical dialogue dataset, which includes conversations between doctors and patients on various health conditions. The dataset was preprocessed to remove sensitive information and ensure the training quality.

Hyperparameters

  • Learning Rate: 2e-4
  • Batch Size: 1 (per device)
  • Epochs: 3
  • Gradient Accumulation Steps: 8
  • FP16 Training: Enabled for memory efficiency

Technical Specifications

Model Architecture

The model is based on the Phi-3-mini-4k-instruct architecture, a smaller and more efficient version of a larger GPT-like model. It was fine-tuned using PEFT (Parameter-Efficient Fine-Tuning) with LoRA to optimize for SOAP note generation.

Compute Infrastructure

  • Hardware: [e.g., Nvidia A100 GPUs]
  • Software: Hugging Face Transformers, PyTorch

Citation

If you use this model, please cite the following:

BibTeX:

@misc{meddialogue2soap2025,
  author = {Rasel Meya},
  title = {med_dialogue2soap: A Model for Generating SOAP Notes from Medical Dialogue},
  year = {2025},
  publisher = {Hugging Face},
  url = {https://huggingface.co/raselmeya2194/med_dialogue2soap}
}

APA: Meya, R. (2025). med_dialogue2soap: A model for generating SOAP notes from medical dialogue. Hugging Face. URL: https://huggingface.co/raselmeya2194/med_dialogue2soap

License

This model is licensed under the MIT License (or other chosen license).

For more information, visit the model repository.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for raselmeya2194/med_dialogue2soap

Finetuned
(390)
this model

Space using raselmeya2194/med_dialogue2soap 1