Skip to content

Conversation

@joshuasteier
Copy link

Pull Request: ConCare Model Update (1.0 → 2.0)

Contributor Information

  • Name: Joshua Steier

Contribution Type

  • Model Update
  • New Model
  • Dataset
  • Task
  • Bug Fix
  • Documentation
  • Other

High-Level Description

This PR updates the ConCare model from PyHealth 1.0 API to PyHealth 2.0 API.

Paper Reference

  • Title: Concare: Personalized clinical feature embedding via capturing the healthcare context
  • Authors: Liantao Ma et al.
  • Venue: AAAI 2020
  • Link: https://ojs.aaai.org/index.php/AAAI/article/view/5428

Changes Made

  1. API Migration (1.0 → 2.0):

    • Replaced SampleEHRDataset with SampleDataset
    • Integrated EmbeddingModel for unified embedding handling
    • Removed explicit feature_keys, label_key, mode, use_embedding parameters
    • Simplified constructor to derive feature information from dataset schemas
  2. Code Improvements:

    • Added comprehensive Google-style docstrings for all classes and methods
    • Added proper type hints throughout
    • Fixed bug in SingleAttention (removed undefined self.Wd initialization)
    • Improved code documentation with input/output descriptions
    • Added file header with paper reference and description
  3. Testing:

    • Added comprehensive unit tests covering:
      • Model initialization (with/without static features)
      • Forward pass validation
      • Backward pass (gradient flow)
      • Embedding extraction
      • Custom hyperparameters
      • Multiclass classification
      • Single feature input
  4. Examples:

    • Added example notebook for MIMIC-IV in-hospital mortality prediction
    • Added standalone Python script example

Files to Review

File Description
pyhealth/models/concare.py Main model implementation (updated)
tests/models/test_concare.py Unit tests for ConCare model
examples/concare_mimic4_example.ipynb Example notebook for MIMIC-IV

How to Test

1. Run Unit Tests

python -m pytest tests/models/test_concare.py -v

2. Run Quick Example (main block)

python pyhealth/models/concare.py

3. Expected Output

{
    'loss': tensor(..., grad_fn=<AddBackward0>),
    'y_prob': tensor([[...], [...]], grad_fn=<SigmoidBackward0>),
    'y_true': tensor([[...], [...]]),
    'logit': tensor([[...], [...]], grad_fn=<AddmmBackward0>)
}

Checklist

  • Code follows PEP8 style (88 character line length)
  • Code follows Google-style docstrings
  • All functions have type hints
  • All functions have input/output documentation
  • File header includes author, paper title, link, and description
  • Unit tests pass
  • Example code runs successfully
  • Backward pass (loss.backward()) works
  • Code is rebased with main branch

Additional Notes

The ConCare model includes:

  • Channel-wise GRUs: Separate GRU for each input feature dimension
  • Time-aware attention: Captures temporal decay in healthcare context
  • Multi-head self-attention: Captures feature interactions
  • DeCov loss: Regularization to reduce feature redundancy
  • Static feature support: Optional demographic/static features

This update maintains full backward compatibility with the original ConCare functionality while adopting the cleaner 2.0 API patterns.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Will review more of the codebase later (as I find time tomorrow sorry)

For some reason this notebook doesn't show up in GitHub? "The Notebook Does Not Appear to Be Valid JSON"

Copy link
Author

Choose a reason for hiding this comment

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

Thank you, no pressure.
I believe I've fixed this error now in the latest commit.
Much appreciated for your guidance.

@LogicFan LogicFan added the model Contribute a new model to PyHealth label Dec 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

model Contribute a new model to PyHealth

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants