How panushri25/emrqa works
Purpose and Runtime
emrQA is an offline, Python 2.7 data-generation pipeline for creating clinical question-answer (QA) and question–logical-form (QL) corpora from licensed i2b2/N2C2 challenge annotations. It is not a serving application. The primary entry point is main.py; its outputs are generated JSON/CSV files under an output/ directory.
Inputs and External Boundary
The pipeline combines expert-authored templates with externally downloaded, license-controlled i2b2 clinical notes and annotations. The template contract is a tabular row containing dataset selector, paraphrased question templates, logical-form template, answer type, and sub-answer type.
• Template source: templates/templates-all.csv
• Pipeline launcher/path configuration: main.py
• External dependency manifest: requirements.txt
The required i2b2/ input tree is deliberately absent from the repo because it contains controlled clinical datasets.
Orchestration and Dataset Routing
main.py coordinates generation across five source challenge families, dispatching templates and i2b2 annotations to specialized generators. Each generator produces challenge-specific QA and QL artifacts; a final aggregation stage emits corpus-level files. Dataset identity in the template CSV is the routing boundary: medications, relations, risk, smoking, or obesity.
• Orchestrator: main.py
• Final aggregation: generation/combine_data/combine_answers.py
• Templates: templates/templates-all.csv
Annotation-to-QA Generation Stages
The architecture is organized by materially different i2b2 annotation formats rather than a uniform parser. Each stage reads its challenge’s notes/annotations, resolves template placeholders from annotated entities or labels, constructs questions and logical forms, and attaches context/evidence/answer metadata.
• Medication extraction QA: generation/i2b2_medications/medication-answers.py
• Relation/concept/assertion QA: generation/i2b2_relations/relations-answers.py
• Heart-disease risk-factor QA: generation/i2b2_heart_disease_risk/risk-answers.py
• Smoking classification QA: generation/i2b2_smoking/smoking-answers.py
• Obesity/comorbidity classification QA: generation/i2b2_obesity/obesity-answers.py
Important Data Semantics
Generated QA JSON is organized by dataset title, then clinical-note paragraphs, then QAs. For span-oriented sources, answers carry entity text, line/token location, and evidence line; answer type distinguishes single, empty, and complex answers. Smoking and obesity are classification-oriented: their class label is the answer and the full note serves as context/evidence. Heart-risk contexts combine multiple chronologically ordered notes for a patient, unlike the generally one-note-per-patient sources.
Relations generation also relies on repository-local normalization/matching assets:
• generation/i2b2_relations/problem_classfiers.py
• generation/i2b2_relations/common_names.txt
• generation/i2b2_relations/matching_notes.csv
Consolidation and Deliverables
Per-challenge generators create intermediate QA JSON and QL CSV outputs. combine_answers.py merges them into the primary deliverables: data.json for reading-comprehension-style QA and data-ql.csv for question/logical-form learning. This cleanly separates source-specific parsing from cross-corpus packaging.
• Combiner: generation/combine_data/combine_answers.py
• Source-specific generators: generation/i2b2_relations/relations-answers.py, generation/i2b2_medications/medication-answers.py
Post-generation Analysis
Independent analysis scripts consume generated outputs or the template corpus; they are downstream and do not alter generation. They calculate corpus statistics, paraphrase similarity/diversity, and logical-form-template properties.
• Output statistics: evaluation/basic-stats.py
• Paraphrase analysis: evaluation/paraphrase-analysis.py
• Template/logical-form analysis: evaluation/template-analysis.py
Main entry points: main.py Pipeline orchestrator · templates-all.csv QA/QL templates · combine_answers.py Corpus combiner · relations-answers.py Relation QA generator
Components 17
Inputs & contracts
- QA/QL templates · Dataset selector and question, logical-form, and answer-type templates.
templates/templates-all.csv - Licensed i2b2 inputs · Controlled notes and annotations are intentionally absent from the repository.
- Python dependencies
requirements.txt
Source-specific generation
Each generator parses its challenge annotations and emits QA JSON plus QL CSV.
- Medication QA generator · Builds span-oriented medication QA and QL artifacts.
generation/i2b2_medications/medication-answers.py - Relation QA generator · Builds concept, relation, and assertion QA and QL artifacts.
generation/i2b2_relations/relations-answers.py - Heart-risk QA generator · Combines chronologically ordered notes per patient for risk-factor QA.
generation/i2b2_heart_disease_risk/risk-answers.py - Smoking QA generator · Uses smoking class labels with full-note evidence.
generation/i2b2_smoking/smoking-answers.py - Obesity QA generator · Uses obesity/comorbidity class labels with full-note evidence.
generation/i2b2_obesity/obesity-answers.py - Relation matching assets · Problem classifiers, common names, and note matching support relation generation.
generation/i2b2_relations/problem_classfiers.py - Per-challenge artifacts · Challenge-specific generated QA and logical-form outputs.
Corpus packaging & analysis
- Corpus combiner · Merges all challenge artifacts into corpus-level deliverables.
generation/combine_data/combine_answers.py - data.json · Reading-comprehension QA organized by dataset, paragraphs, and QAs.
- data-ql.csv · Question and logical-form training corpus.
- Output statistics
evaluation/basic-stats.py - Paraphrase analysis
evaluation/paraphrase-analysis.py - Template/LF analysis
evaluation/template-analysis.py
Other components
- Pipeline orchestrator · Routes templates and controlled annotations across challenge families.
main.py
Connections 20
- Python dependencies → Pipeline orchestrator: runtime dependencies
- QA/QL templates → Pipeline orchestrator: dataset routing
- Licensed i2b2 inputs → Pipeline orchestrator: notes and annotations
- Pipeline orchestrator → Medication QA generator: medications templates/input
- Pipeline orchestrator → Relation QA generator: relations templates/input
- Pipeline orchestrator → Heart-risk QA generator: risk templates/input
- Pipeline orchestrator → Smoking QA generator: smoking templates/input
- Pipeline orchestrator → Obesity QA generator: obesity templates/input
- Relation matching assets → Relation QA generator: normalization and matching
- Medication QA generator → Per-challenge artifacts: QA JSON and QL CSV
- Relation QA generator → Per-challenge artifacts: QA JSON and QL CSV
- Heart-risk QA generator → Per-challenge artifacts: QA JSON and QL CSV
- Smoking QA generator → Per-challenge artifacts: QA JSON and QL CSV
- Obesity QA generator → Per-challenge artifacts: QA JSON and QL CSV
- Per-challenge artifacts → Corpus combiner: source artifacts
- Corpus combiner → data.json: merged QA corpus
- Corpus combiner → data-ql.csv: merged QL corpus
- data.json → Output statistics: corpus metrics
- QA/QL templates → Paraphrase analysis: template diversity
- QA/QL templates → Template/LF analysis: template/LF properties