-
Notifications
You must be signed in to change notification settings - Fork 555
[Bounty] Update Dr. Agent model (PyHealth 2.0) #663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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 implements the Dr. Agent model from "Dr. Agent: Clinical predictive model via mimicked second opinions" (JAMIA 2020) for PyHealth 2.0. The model uses dual reinforcement learning agents with dynamic skip connections to capture long-term dependencies in patient EHR sequences.
Key changes:
- New
AgentandAgentLayerclasses implementing the Dr. Agent architecture with REINFORCE-based policy gradient learning - Comprehensive unit tests covering model initialization, forward/backward passes, and various configurations
- Example notebook demonstrating mortality prediction on MIMIC-IV data
Critical issues identified:
- Missing tensor dimensionality reduction for NestedSequenceProcessor embeddings (4D → 3D pooling required)
- Incorrect input schema in tests and examples (
"sequence"should be"nested_sequence") - Binary classification reward computation doesn't provide feedback for negative class predictions
- Mode resolution doesn't use BaseModel's
_resolve_mode()method
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 14 comments.
| File | Description |
|---|---|
pyhealth/models/agent.py |
Core model implementation with AgentLayer (dual RL agents) and Agent (BaseModel wrapper). Contains critical bugs in embedding handling and reward computation. |
tests/core/test_agent.py |
Unit tests for the model. Uses incorrect schema and doesn't test the temporal/nested sequence case. |
examples/agent_mimic4.ipynb |
Tutorial notebook for MIMIC-IV mortality prediction. Contains minor spelling issues and will fail with current model bugs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bbfc9a2 to
e1190b5
Compare
…schema - Add 4D->3D pooling for NestedSequenceProcessor (sum across codes dim) - Fix binary/multilabel reward to provide feedback for both classes - Change schema from 'sequence' to 'nested_sequence' throughout - Update test samples to use nested visit structure
e1190b5 to
374f114
Compare
Contributor
Contribution Type
Model
Description
Implements the Dr. Agent model from "Dr. Agent: Clinical predictive model via mimicked second opinions" (JAMIA 2020).
Key features:
Paper: https://doi.org/10.1093/jamia/ocaa074
Files to Review
pyhealth/models/agent.pytests/test_agent.pyexamples/agent_mimic4.ipynbHow to Test
Checklist