Repository navigation
Truncate StageNet nested visits longer than the fitted width - #1380
Open
Mahdi-Hasan wants to merge 2 commits into
Open
Mahdi-Hasan wants to merge 2 commits into
Mahdi-Hasan wants to merge 2 commits into
Conversation
StageNetProcessor padded each visit to the width seen in fit() but never truncated a longer one. When the processor is fitted on the training split, a test visit with more codes than any training visit made the rows ragged: process() raised "expected sequence of length ..." for a sample with mixed widths, and returned a wider tensor that failed later at collation for a sample with one visit. Apply the same rule sunlabuiuc#1263 added to the nested processors: keep the first codes up to the fitted width and log one warning per processor. The existing padding argument still widens the fitted width. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fold the _warn_truncated import into the existing base_processor import and remove FeatureProcessor, which the module never used. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Mahdi-Hasan
marked this pull request as ready for review
November 4, 2026 12:03
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contributor: Mehedi Hasan (@Mahdi-Hasan)
Contribution Type: Bug fix
Description:
StageNetProcessorpads each nested visit to the width seen infit(), but it never truncates a longer visit. Two symptoms follow when the processor is fitted on the training split:process()raisesexpected sequence of length ...for a sample that mixes visit widths.process()returns a wider tensor for a one-visit sample, and collation fails later.The fix applies the rule from #1263 to the nested processors. Visits longer than the fitted width keep their first codes, and each processor logs one warning. The existing
paddingargument still widens the fitted width.No existing issue covers this. Searched
stagenet truncateandtruncatin issues and open PRs, with no matches.Files to Review:
pyhealth/processors/stagenet_processor.py- truncation in_encode_nested_codes, docstring updates, import cleanuptests/core/test_nested_processor_truncation.py-TestStageNetTruncation(4 cases, synthetic data)Tests:
tests/core/test_nested_processor_truncation.py: 11 passedtests/core/test_stagenet_processor.py,test_stagenet.py,test_vocab_processors.py, plus the truncation file: 64 passedtools/check_pr_rules.py: passed