How dmcguire81/explainable-automated-medical-coding works
1. This repository centers on an explainable multi-label text classification pipeline for medical coding. The primary production path is the HLAN family: Hierarchical Label-wise Attention Network, with variants for HLAN, HA-GRU, and HAN. The rest of the repo supports training, evaluation, inference visualization, and artifact storage.
2. The main runtime is a TensorFlow 1.x training/inference stack under HLAN/. HAN_train.py is the entry point for experiments and configuration, HAN_model_dynamic.py contains the model graph and per-label attention computation, and data_util_gensim.py prepares text and label inputs. model_predict_util.py powers prediction-time postprocessing for the notebook demo.
3. The model boundary is important: the network consumes tokenized clinical notes and emits per-label scores plus attention weights that are later rendered as explanations. The README calls out inference_per_label() in HAN_model_dynamic.py as the key computation graph for the label-wise attention mechanism.
4. Data enters the system from dataset files under datasets/, which are expected to be preformatted as note text plus a multi-label target list. The training code supports multiple dataset presets, including MIMIC-III, MIMIC-III-50, and a shielding-specific variant, with dataset-specific paths and hyperparameters selected in HAN_train.py.
5. Preprocessing and vocabulary/label caching are separated from model code. The cache_vocabulary_label_pik/ directory stores serialized vocabulary and label objects used to keep training and demo runs consistent, while datasets/README.md and related notebooks document the file layout and splits.
6. Label semantics are strengthened through the knowledge_bases/ folder. It contains ICD description files and an ICD-9 hierarchy graph, which are used for label subsumption relations and hierarchical evaluation support rather than as a live service dependency.
7. A major architectural feature is label embedding initialization. The embeddings/ folder holds or generates Gensim word2vec embeddings for both words and labels, and HAN_train.py loads these embeddings to initialize the final classifier layer so labels start from semantic vectors instead of random weights.
8. Training produces model checkpoints and logs under checkpoints/, with the README indicating pretrained HLAN, HA-GRU, and HAN artifacts are stored there. The code also supports repeated runs, early stopping, GPU execution, and TensorBoard logging, so the training subsystem is both experiment-oriented and reproducible.
9. Inference for humans is exposed through demo_HLAN_viz.ipynb. That notebook loads a trained checkpoint, runs prediction utilities, and writes attention visualizations to explanations/ as Excel sheets. This is the main explainability boundary: prediction output is transformed into token-level or sentence-level attention displays for inspection.
10. Evaluation is split into standard metrics and hierarchical metrics. multi_level_eval.py and evaluation_setup.py incorporate CoPHE-based hierarchical evaluation, while the rest of the training flow still computes conventional multi-label classification metrics. This means the repo has both flat and ontology-aware evaluation paths.
11. The repository also contains a results archive for the HealTAC 2020 experiments. results-HealTAC 2020/ stores CSV/XLSX outputs for CNN, CNN+attention, Bi-GRU, and BERT baselines, which are separate from the TensorFlow HLAN training path but useful as comparison artifacts.
12. External dependencies materially shape the architecture: Python 3, TensorFlow 1.x, Gensim, NLTK, spaCy 2.x, scikit-learn, and TFLearn are part of the HLAN stack, while the baseline result folders reflect older PyTorch/CAML and BERT-related tooling. The repo is therefore a research codebase with one main HLAN pipeline plus side-by-side baseline outputs and supporting assets.
Main entry points: HAN_train.py Train · readme.md HealTAC · demo_HLAN_viz.ipynb Demo notebook · data_util_gensim.py Data prep
Components 21
HLAN runtime
TensorFlow 1.x training, inference, attention explanation, and evaluation for medical coding.
- Train · Main experiment runner and configuration for HLAN, HA-GRU, and HAN.
HLAN/HAN_train.py - Attention model · Model definition and label-wise attention computation used for prediction and explanations.
HLAN/HAN_model_dynamic.py - Data prep · Tokenization, input assembly, and label/text loading for training and evaluation.
HLAN/data_util_gensim.py - Predict utils · Prediction-time postprocessing used by the demo notebook.
HLAN/model_predict_util.py - Eval setup · Evaluation wiring, including hierarchical and standard metric setup.
HLAN/evaluation_setup.py - Hier eval · Multi-level hierarchical evaluation against the ICD knowledge structure.
HLAN/multi_level_eval.py - Demo notebook · Human-facing notebook that loads checkpoints and renders attention explanations.
HLAN/demo_HLAN_viz.ipynb
Support assets
Cached vocabularies, datasets, embeddings, label knowledge, and output folders used by the pipeline.
- README · Top-level overview of the explainable medical coding pipeline.
README.md - Datasets · Dataset layout, splits, and preprocessing expectations.
datasets/README.md - Cache docs · Serialized vocabulary and label cache used to keep runs consistent.
cache_vocabulary_label_pik/README.md - Word emb · Builds or trains word embeddings used to initialize token representations.
embeddings/train_word_embedding.py - Code emb · Builds or trains label/code embeddings used to seed the classifier layer.
embeddings/train_code_embedding.py - ICD graph · ICD-9 hierarchy and description graph used for label relations.
knowledge_bases/icd9_graph_desc.json - ICD subsum · ICD subsumption table for hierarchical label support.
knowledge_bases/kb-icd-sub.csv - Checkpoints · Stored trained HLAN-family checkpoints and experiment artifacts.
checkpoints/README.md - Explanations · Attention visualization outputs exported for inspection.
explanations/README.md
Results archive
Stored HealTAC 2020 baseline outputs and comparison artifacts.
- HealTAC · Archived comparison results from the HealTAC 2020 experiments.
results-HealTAC 2020/readme.md - CNN results · CNN baseline outputs and metrics for full and 50-label settings.
results-HealTAC 2020/CNN results/README.md - CNN+att · Attention CNN baseline outputs and metrics.
results-HealTAC 2020/CNN+att results/README.md - Bi-GRU · Bi-GRU baseline outputs and metrics.
results-HealTAC 2020/Bi-GRU results/README.md - BERT results · BERT baseline outputs and metrics.
results-HealTAC 2020/BERT results/README.md
Connections 21
- README → Train: describes · Repository overview points to the main experiment pipeline.
- README → Demo notebook: documents · README also frames the explainability demo.
- Train → Data prep: loads · Training depends on preprocessing and input assembly.
- Train → Attention model: builds · Training instantiates the attention network graph.
- Train → Word emb: uses · Word embeddings initialize or seed text representations.
- Train → Code emb: uses · Label/code embeddings initialize the classifier side.
- Train → ICD graph: uses · Knowledge graph informs hierarchical label handling.
- Train → ICD subsum: uses · Subsumption data supports ontology-aware training/eval.
- Train → Checkpoints: writes · Runs produce checkpoints and logs under the artifact folder.
- Attention model → Hier eval: emits · Label-wise scores and attention weights feed evaluation and explanation.
- Data prep → Datasets: reads · Dataset files and formatting conventions originate here.
- Data prep → Cache docs: reads · Cached vocabulary/label objects keep runs consistent.
- Demo notebook → Predict utils: uses · Notebook prediction flow relies on postprocessing helpers.
- Demo notebook → Attention model: loads · Demo loads a trained model checkpoint for inference.
- Demo notebook → Explanations: writes · Attention visualizations are exported for human review.
- Eval setup → Hier eval: configures · Evaluation setup routes into hierarchical metrics.
- Eval setup → ICD graph: uses · Ontology structure supports hierarchical scoring.
- HealTAC → CNN results: indexes · Archive includes baseline result folders for comparison.
- HealTAC → CNN+att: indexes · Archive includes baseline result folders for comparison.
- HealTAC → Bi-GRU: indexes · Archive includes baseline result folders for comparison.
- HealTAC → BERT results: indexes · Archive includes baseline result folders for comparison.