jonleed/Medical-Dialogue-Summary

Medical dialogue summarization with BioBART-large LoRA and Flask EHR workflow

Jupyter Notebook

0

56 commits

updated Sep 2, 2026

See the code

README

Medical Dialogue Summary

CI License: MIT Model

A local Flask application that helps clinicians turn a post-visit doctor-patient transcript into copy-ready EHR sections. The clinician pastes the full transcript, selects only the sections needed for that encounter, reviews each generated block, and copies it into the EHR.

This is a continuation of a Deep Learning course project for the University of Surrey. The original BART fine-tuning approach is preserved; the default backbone is now GanjinZero/biobart-large, a biomedical BART model released in 2022.

Clinical Note Generator Flask application

Current Application

Run the doctor-facing application:

python app.py

Open http://127.0.0.1:5002.

The workflow is deliberately section-based because the MTS-Dialog training data pairs each dialogue with a documented EHR section. It does not force irrelevant sections into every note.

  • Paste the complete conversation, not an isolated snippet.
  • Select the sections relevant to the encounter.
  • Generate each section using the model's original dialogue-to-section task.
  • Review the output before copying it into the EHR.
  • Routine outputs such as None. and Noncontributory. are visibly flagged.

The older dataset-table explorer remains available:

python eval.py

Open http://127.0.0.1:5001.

Model

The committed adapter is biobart-large-lora/. It contains only the LoRA adapter and tokenizer; the 407M-parameter BioBART-large base downloads from Hugging Face on first use.

  • Base model: GanjinZero/biobart-large
  • Adapter: jonleed/clinical-note-biobart-large-lora
  • Fine-tuning method: PEFT LoRA
  • LoRA rank: 8
  • LoRA alpha: 64
  • LoRA dropout: 0.01
  • Target modules: BART q_proj and v_proj
  • Input context: 512 tokens
  • Output budget: 512 tokens in the Flask app
  • Decoding: deterministic beam search, 4 beams, repetition penalty 2.0, no-repeat 4-gram constraint

Results

Evaluation uses the same prompt and section-target construction as the original notebook. Scores use ROUGE with stemming on 100 validation dialogues, seed 42.

BioBART-large LoRA evaluationROUGE-1ROUGE-2ROUGE-LROUGE-Lsum
100 validation dialogues, seed 420.5530.3250.4720.474

The evaluation output is checked in at results/eval-biobart-large-2026-08.json.

Controlled Model Study

Using the same validation split, seed, prompt construction, token limits, deterministic decoding, and ROUGE scorer:

ModelROUGE-1ROUGE-2ROUGE-LROUGE-Lsum
BART-base, no adapter0.21950.07460.16730.1671
BART-base with LoRA0.49870.28580.43420.4336
BioBART-large with LoRA0.55890.33340.48030.4803

The complete study record is results/model-study-2026-08.json. The results show the value of the original LoRA fine-tuning approach and support BioBART-large as the project's selected backbone.

Run the original notebook-style evaluation:

python eval_notebook_protocol.py --split val

Run the Flask integration evaluation through the actual test client:

python eval_app_integration.py --app note --n 100
python eval_app_integration.py --app section --n 100

The BioBART-large adapter produced ROUGE-L 0.4719 through the Flask integration path. This confirms that the served application and evaluation use the same adapter, prompt, input length, and deterministic decode.

Setup

git clone --recurse-submodules https://github.com/jonleed/Medical-Dialogue-Summary.git
cd Medical-Dialogue-Summary
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python app.py

Configuration

Environment variableDefaultPurpose
BASE_MODEL_IDGanjinZero/biobart-largeBase seq2seq model
ADAPTER_MODEL_ID./biobart-large-loraLocal or Hugging Face LoRA adapter
HF_TOKENunsetOptional Hugging Face authentication

Reproducing Training

train_lora.py mirrors the original notebook while using BioBART-large by default:

python train_lora.py \
  --base_model GanjinZero/biobart-large \
  --output_dir ./biobart-large-lora \
  --per_device_batch 2 \
  --grad_accum 4 \
  --epochs 20

The original notebook recipe is retained in Medical_Dialogue_Generation.ipynb. Training uses the MTS-Dialog training split, the original prompt and target construction, 512-token inputs, 256-token targets, learning rate 2e-4, weight decay 0.01, and per-epoch validation ROUGE. The effective batch size is 8 in the recommended command.

Architecture

graph LR
    A["Full doctor-patient transcript"] --> B["Clinician selects EHR sections"]
    B --> C["Original section prompt"]
    C --> D["BioBART-large"]
    D --> E["LoRA adapter"]
    E --> F["Deterministic beam search"]
    F --> G["Reviewable EHR section"]

Project History

The original project used BART-base with LoRA. The restoration preserves that approach and improves the deployable artifact by:

  • Loading the base model and adapter separately through PEFT
  • Using the biomedical BioBART-large backbone
  • Increasing serving input context from 128 to the 512-token training context
  • Providing clinician-selected section generation in demo

This project is educational and is not a medical device.

Credits

License

MIT

jonleed/Medical-Dialogue-Summary

Medical dialogue summarization with BioBART-large LoRA and Flask EHR workflow

Jupyter Notebook

0

56 commits

updated Sep 2, 2026

See the code

README

Medical Dialogue Summary

CI License: MIT Model

A local Flask application that helps clinicians turn a post-visit doctor-patient transcript into copy-ready EHR sections. The clinician pastes the full transcript, selects only the sections needed for that encounter, reviews each generated block, and copies it into the EHR.

This is a continuation of a Deep Learning course project for the University of Surrey. The original BART fine-tuning approach is preserved; the default backbone is now GanjinZero/biobart-large, a biomedical BART model released in 2022.

Clinical Note Generator Flask application

Current Application

Run the doctor-facing application:

python app.py

Open http://127.0.0.1:5002.

The workflow is deliberately section-based because the MTS-Dialog training data pairs each dialogue with a documented EHR section. It does not force irrelevant sections into every note.

  • Paste the complete conversation, not an isolated snippet.
  • Select the sections relevant to the encounter.
  • Generate each section using the model's original dialogue-to-section task.
  • Review the output before copying it into the EHR.
  • Routine outputs such as None. and Noncontributory. are visibly flagged.

The older dataset-table explorer remains available:

python eval.py

Open http://127.0.0.1:5001.

Model

The committed adapter is biobart-large-lora/. It contains only the LoRA adapter and tokenizer; the 407M-parameter BioBART-large base downloads from Hugging Face on first use.

  • Base model: GanjinZero/biobart-large
  • Adapter: jonleed/clinical-note-biobart-large-lora
  • Fine-tuning method: PEFT LoRA
  • LoRA rank: 8
  • LoRA alpha: 64
  • LoRA dropout: 0.01
  • Target modules: BART q_proj and v_proj
  • Input context: 512 tokens
  • Output budget: 512 tokens in the Flask app
  • Decoding: deterministic beam search, 4 beams, repetition penalty 2.0, no-repeat 4-gram constraint

Results

Evaluation uses the same prompt and section-target construction as the original notebook. Scores use ROUGE with stemming on 100 validation dialogues, seed 42.

BioBART-large LoRA evaluationROUGE-1ROUGE-2ROUGE-LROUGE-Lsum
100 validation dialogues, seed 420.5530.3250.4720.474

The evaluation output is checked in at results/eval-biobart-large-2026-08.json.

Controlled Model Study

Using the same validation split, seed, prompt construction, token limits, deterministic decoding, and ROUGE scorer:

ModelROUGE-1ROUGE-2ROUGE-LROUGE-Lsum
BART-base, no adapter0.21950.07460.16730.1671
BART-base with LoRA0.49870.28580.43420.4336
BioBART-large with LoRA0.55890.33340.48030.4803

The complete study record is results/model-study-2026-08.json. The results show the value of the original LoRA fine-tuning approach and support BioBART-large as the project's selected backbone.

Run the original notebook-style evaluation:

python eval_notebook_protocol.py --split val

Run the Flask integration evaluation through the actual test client:

python eval_app_integration.py --app note --n 100
python eval_app_integration.py --app section --n 100

The BioBART-large adapter produced ROUGE-L 0.4719 through the Flask integration path. This confirms that the served application and evaluation use the same adapter, prompt, input length, and deterministic decode.

Setup

git clone --recurse-submodules https://github.com/jonleed/Medical-Dialogue-Summary.git
cd Medical-Dialogue-Summary
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python app.py

Configuration

Environment variableDefaultPurpose
BASE_MODEL_IDGanjinZero/biobart-largeBase seq2seq model
ADAPTER_MODEL_ID./biobart-large-loraLocal or Hugging Face LoRA adapter
HF_TOKENunsetOptional Hugging Face authentication

Reproducing Training

train_lora.py mirrors the original notebook while using BioBART-large by default:

python train_lora.py \
  --base_model GanjinZero/biobart-large \
  --output_dir ./biobart-large-lora \
  --per_device_batch 2 \
  --grad_accum 4 \
  --epochs 20

The original notebook recipe is retained in Medical_Dialogue_Generation.ipynb. Training uses the MTS-Dialog training split, the original prompt and target construction, 512-token inputs, 256-token targets, learning rate 2e-4, weight decay 0.01, and per-epoch validation ROUGE. The effective batch size is 8 in the recommended command.

Architecture

graph LR
    A["Full doctor-patient transcript"] --> B["Clinician selects EHR sections"]
    B --> C["Original section prompt"]
    C --> D["BioBART-large"]
    D --> E["LoRA adapter"]
    E --> F["Deterministic beam search"]
    F --> G["Reviewable EHR section"]

Project History

The original project used BART-base with LoRA. The restoration preserves that approach and improves the deployable artifact by:

  • Loading the base model and adapter separately through PEFT
  • Using the biomedical BioBART-large backbone
  • Increasing serving input context from 128 to the 512-token training context
  • Providing clinician-selected section generation in demo

This project is educational and is not a medical device.

Credits

License

MIT