Skip to content

Conversation

@bilalarif3197
Copy link

Bilal Arif
netID: barif

Contribution Type: Updated model

Description:

  • Updated to current BaseModel/EmbeddingModel API
  • Implemented dilated causal convolutions for temporal sequence modeling on EHR data
  • Supports both discrete code sequences (diagnoses, procedures) and continuous timeseries
  • Includes comprehensive test suite with 6 passing unit tests
  • Added example notebook demonstrating mortality prediction on MIMIC-III

Files to review:

  • pyhealth/models/tcn.py - Full TCN implementation
  • tests/core/test_tcn.py - Main testing suite
  • examples/tcn_mimic3_codes.ipynb - Jupyter notebook for using MIMIC-III

Copilot AI review requested due to automatic review settings December 9, 2025 18:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR successfully updates the TCN (Temporal Convolutional Networks) model to the current PyHealth 2.0 API, replacing the deprecated SampleEHRDataset with SampleDataset and adopting the EmbeddingModel architecture. The implementation provides dilated causal convolutions for temporal sequence modeling on EHR data, supporting both discrete code sequences (diagnoses, procedures) and continuous timeseries data.

Key changes:

  • Modernized API: Updated from legacy SampleEHRDataset to SampleDataset with EmbeddingModel
  • Simplified architecture: Removed complex manual feature processing in favor of EmbeddingModel's automatic handling
  • Improved PyTorch compatibility: Updated weight_norm import to PyTorch 2.0+ path (torch.nn.utils.parametrizations)

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
pyhealth/models/tcn.py Complete TCN model refactor to PyHealth 2.0 API; removed 150+ lines of legacy code; updated weight_norm import; added safety check in Chomp1d; improved forward pass with explicit last-output extraction
tests/core/test_tcn.py New comprehensive test suite with 6 test cases covering initialization, forward/backward passes, embeddings, and custom hyperparameters
examples/tcn_mimic3_codes.ipynb New example notebook demonstrating mortality prediction on MIMIC-III dataset with clear step-by-step instructions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


# Get the actual output dimension from TCNLayer instances
# All TCNLayers have the same output dimension
self.num_channels = next(iter(self.tcn.values())).num_channels
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential StopIteration error if self.feature_keys is empty. Consider adding a check:

if not self.feature_keys:
    raise ValueError("At least one input feature is required")

before line 240, or handle the case where self.tcn might be empty.

Copilot uses AI. Check for mistakes.
@LogicFan LogicFan added model Contribute a new model to PyHealth bounty Please see the bounty list in PyHealth Discord Server labels Dec 18, 2025
Comment on lines 224 to 226
Examples:
>>> from pyhealth.datasets import SampleEHRDataset
>>> samples = [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add usage examples in the new docstring?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a usage example in the docstring. I also changed SampleDataset to create_sample_dataset in the test file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bounty Please see the bounty list in PyHealth Discord Server model Contribute a new model to PyHealth

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants