How does the structural organization of clinical notes (e.g., use of section headers, bullet lists, and consistent formatting) influence the performance of large language models on clinical NLP tasks such as summarization?
This repository implements a comprehensive experimental framework to investigate how clinical note structure affects LLM summarization performance.
Models Tested:
Structure Variants:
Evaluation Metrics:
ms-thesis/
├── config.py # Configuration (models, parameters)
├── structure_manipulation.py # Note structure transformation
├── models.py # Model wrappers
├── evaluation.py # Evaluation metrics
├── experiment.py # Main experiment runner
├── visualize.py # Results visualization
├── requirements.txt # Dependencies
└── results/ # Output directory
├── summary_results.csv # Main results table
├── detailed_results.json # Full results with samples
└── figures/ # Generated plots
pip install -r requirements.txt
python -c "import nltk; nltk.download('punkt')"
Place your MIMIC-IV dataset as mimic_1000_notes_with_references.csv with columns:
note_idtext (full clinical note)reference_summary (gold standard summary)Test the pipeline with a small subset:
python experiment.py
This runs BART-CNN on 2 structure variants (original, no_formatting) with 10 samples.
Run complete experiment with all models and variants:
python experiment.py --full
This will:
results/Note: Full experiment may take several hours depending on GPU.
from experiment import ExperimentRunner
runner = ExperimentRunner(n_samples=100)
# Test specific configurations
runner.run_full_experiment(
models_to_test=['bart-cnn', 'clinical-t5'],
variants_to_test=['original', 'no_formatting']
)
# Create comparison tables
runner.create_comparison_table()
python visualize.py
This creates:
import pandas as pd
# Load results
results = pd.read_csv('results/summary_results.csv')
# Compare models
print(results.groupby('model')['rouge1'].mean())
# Compare structures
print(results.groupby('structure_variant')['rouge1'].mean())
# Best combination
print(results.nlargest(1, 'rouge1'))
Models will perform better on structured notes (original) compared to unstructured notes (no_formatting).
Expected: original > no_headers > no_formatting
Medical models (Clinical-T5) will be more robust to structure degradation than general models (BART-CNN).
Expected: Smaller performance drop for Clinical-T5 when structure is removed.
Shuffled section order will significantly hurt performance, showing models rely on conventional note organization.
Expected: shuffled will have lowest scores.
Performance Drop: How much does removing structure hurt?
Drop% = (original_score - no_formatting_score) / original_score × 100
Model Comparison: Do medical models handle unstructured notes better?
Critical Structure Elements: Which matters more - headers or formatting?
Edit config.py:
MODELS = {
'general': {
'bart-cnn': 'facebook/bart-large-cnn',
'pegasus': 'google/pegasus-large',
't5-base': 't5-base', # Add this
},
'medical': {
'clinical-t5': 'luqh/ClinicalT5-large',
'your-model': 'your/model-name', # Add this
}
}
Implement in structure_manipulation.py:
def bullets_only(self, text: str) -> str:
"""Keep only bullet points."""
# Your implementation
pass
Then add to config.py:
STRUCTURE_VARIANTS = [..., 'bullets_only']
Implement in evaluation.py:
def compute_medical_accuracy(self, predictions, references):
"""Custom medical metric."""
# Your implementation
pass
Reduce batch size in config.py:
BATCH_SIZE = 1 # Default is 4
Disable BERTScore in experiment.py:
metrics = self.evaluator.compute_all_metrics(
predictions, references,
include_bertscore=False # Set to False
)
If HuggingFace downloads fail, manually download models first:
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
model = AutoModelForSeq2SeqLM.from_pretrained('facebook/bart-large-cnn')
tokenizer = AutoTokenizer.from_pretrained('facebook/bart-large-cnn')
If you use this framework, please cite:
@mastersthesis{yourname2024structure,
title={Effect of Note Structure on Large Language Model Performance in Clinical Summarization},
author={Your Name},
year={2024},
school={Your University}
}
This research framework is provided for academic use.
For questions or collaboration: [email protected]
How does the structural organization of clinical notes (e.g., use of section headers, bullet lists, and consistent formatting) influence the performance of large language models on clinical NLP tasks such as summarization?
This repository implements a comprehensive experimental framework to investigate how clinical note structure affects LLM summarization performance.
Models Tested:
Structure Variants:
Evaluation Metrics:
ms-thesis/
├── config.py # Configuration (models, parameters)
├── structure_manipulation.py # Note structure transformation
├── models.py # Model wrappers
├── evaluation.py # Evaluation metrics
├── experiment.py # Main experiment runner
├── visualize.py # Results visualization
├── requirements.txt # Dependencies
└── results/ # Output directory
├── summary_results.csv # Main results table
├── detailed_results.json # Full results with samples
└── figures/ # Generated plots
pip install -r requirements.txt
python -c "import nltk; nltk.download('punkt')"
Place your MIMIC-IV dataset as mimic_1000_notes_with_references.csv with columns:
note_idtext (full clinical note)reference_summary (gold standard summary)Test the pipeline with a small subset:
python experiment.py
This runs BART-CNN on 2 structure variants (original, no_formatting) with 10 samples.
Run complete experiment with all models and variants:
python experiment.py --full
This will:
results/Note: Full experiment may take several hours depending on GPU.
from experiment import ExperimentRunner
runner = ExperimentRunner(n_samples=100)
# Test specific configurations
runner.run_full_experiment(
models_to_test=['bart-cnn', 'clinical-t5'],
variants_to_test=['original', 'no_formatting']
)
# Create comparison tables
runner.create_comparison_table()
python visualize.py
This creates:
import pandas as pd
# Load results
results = pd.read_csv('results/summary_results.csv')
# Compare models
print(results.groupby('model')['rouge1'].mean())
# Compare structures
print(results.groupby('structure_variant')['rouge1'].mean())
# Best combination
print(results.nlargest(1, 'rouge1'))
Models will perform better on structured notes (original) compared to unstructured notes (no_formatting).
Expected: original > no_headers > no_formatting
Medical models (Clinical-T5) will be more robust to structure degradation than general models (BART-CNN).
Expected: Smaller performance drop for Clinical-T5 when structure is removed.
Shuffled section order will significantly hurt performance, showing models rely on conventional note organization.
Expected: shuffled will have lowest scores.
Performance Drop: How much does removing structure hurt?
Drop% = (original_score - no_formatting_score) / original_score × 100
Model Comparison: Do medical models handle unstructured notes better?
Critical Structure Elements: Which matters more - headers or formatting?
Edit config.py:
MODELS = {
'general': {
'bart-cnn': 'facebook/bart-large-cnn',
'pegasus': 'google/pegasus-large',
't5-base': 't5-base', # Add this
},
'medical': {
'clinical-t5': 'luqh/ClinicalT5-large',
'your-model': 'your/model-name', # Add this
}
}
Implement in structure_manipulation.py:
def bullets_only(self, text: str) -> str:
"""Keep only bullet points."""
# Your implementation
pass
Then add to config.py:
STRUCTURE_VARIANTS = [..., 'bullets_only']
Implement in evaluation.py:
def compute_medical_accuracy(self, predictions, references):
"""Custom medical metric."""
# Your implementation
pass
Reduce batch size in config.py:
BATCH_SIZE = 1 # Default is 4
Disable BERTScore in experiment.py:
metrics = self.evaluator.compute_all_metrics(
predictions, references,
include_bertscore=False # Set to False
)
If HuggingFace downloads fail, manually download models first:
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
model = AutoModelForSeq2SeqLM.from_pretrained('facebook/bart-large-cnn')
tokenizer = AutoTokenizer.from_pretrained('facebook/bart-large-cnn')
If you use this framework, please cite:
@mastersthesis{yourname2024structure,
title={Effect of Note Structure on Large Language Model Performance in Clinical Summarization},
author={Your Name},
year={2024},
school={Your University}
}
This research framework is provided for academic use.
For questions or collaboration: [email protected]