-
Notifications
You must be signed in to change notification settings - Fork 15
Superseded by #85: Investigate HMM backend surface #79
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
Closed
Closed
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
e0ff322
Move project skill into .agent
AKuederle 4f0dcb6
Document HMM backend refactor direction
AKuederle 8ca5d8c
Move HMM refactor note out of docs
AKuederle def5317
Refactor HMM config input surface
AKuederle 5bb0e61
Address HMM config review feedback
AKuederle 8fb574d
Add HMM state and pomegranate backend abstraction
AKuederle 6101b6d
Bundle Roth HMM preprocessing into config
AKuederle db24183
Drop legacy clone mixin from Roth HMM
AKuederle db3985a
Add SciPy inference backend for HMM states
AKuederle a51d326
Fix Roth HMM example and migration checks
AKuederle 25909f3
Fix legacy fused HMM end probabilities
AKuederle c8a49bc
Repair pretrained Roth HMM terminal probabilities
AKuederle 48a14f2
Refactor HMM backends into dedicated packages
AKuederle b7b75b8
Limit HMM backend imports to backend packages
AKuederle cdde465
Widen optional pomegranate dependency range
AKuederle d865b62
Apply repo formatting and lint cleanup
AKuederle 95991b6
Reload HMM package with backend selection tests
AKuederle fdaaa0a
Keep legacy HMM annotations compatible with Python 3.9
AKuederle 83fc01b
Align HMM backend imports and inference regression tests
AKuederle 775ebb7
Stabilize HMM training example snapshots
AKuederle 70fe6f9
Simplify HMM test coverage
AKuederle 501b3cf
Fix HMM lint issues
AKuederle a1474e3
Merge branch 'investigate/hmm-pomegranate-modern-backend' into invest…
AKuederle 4231bb1
Install HMM extras in CI test jobs
AKuederle d9e2796
Install all extras in CI test jobs
AKuederle 104778b
Fix modern pomegranate compatibility
AKuederle 446f7e0
Remove raw legacy HMM serialization
AKuederle ae62c36
Tighten legacy HMM import boundaries
AKuederle 58f2e9e
Proper uv layout
AKuederle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
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
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
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,6 @@ | |
|
|
||
| import pandas as pd | ||
|
|
||
|
|
||
| # %% | ||
| # The Data | ||
| # -------- | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # HMM Refactor Plan Overview | ||
|
|
||
| This note replaces the earlier single investigation note with a staged plan. | ||
|
|
||
| The refactor should happen in three steps: | ||
|
|
||
| 1. Move the current HMM system to a unified input config while still storing and operating on `pomegranate` models. | ||
| 2. Introduce a generic serializable `HMMState` and change `RothSegmentationHmm.model` to use that state. | ||
| 3. Add a dedicated `pomegranate 0.14` backend abstraction that converts between backend-native models and `HMMState`. | ||
|
|
||
| Why this order: | ||
|
|
||
| - Step 1 changes the public construction/configuration surface without changing the trained-model representation. | ||
| - Step 2 changes the trained-model representation while still keeping the current implementation behavior. | ||
| - Step 3 isolates the legacy backend after the public config and model-state surfaces are already stable. | ||
|
|
||
| This order reduces risk and keeps regressions easier to localize. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| # Step 1: Unified Config Surface | ||
|
|
||
| ## Goal | ||
|
|
||
| Replace the dedicated `stride_model` and `transition_model` init parameters with a single composite model config while | ||
| still using the current `pomegranate` model objects internally. | ||
|
|
||
| ## Target API | ||
|
|
||
| The HMM class should accept one nested config object that describes: | ||
|
|
||
| - the available submodules, | ||
| - each submodule's local HMM settings, | ||
| - how submodules are connected, | ||
| - and how the combined model is trained. | ||
|
|
||
| Example target surface: | ||
|
|
||
| ```python | ||
| class HmmSubModelConfig(_BaseSerializable): | ||
| n_states: int | ||
| n_gmm_components: int | ||
| architecture: Literal["left-right-strict", "left-right-loose", "fully-connected"] | ||
| algo_train: Literal["viterbi", "baum-welch", "labeled"] | ||
| stop_threshold: float | ||
| max_iterations: int | ||
| name: str | ||
|
|
||
|
|
||
| class HmmConnectionConfig(_BaseSerializable): | ||
| from_module: str | ||
| from_state: int | ||
| to_module: str | ||
| to_state: int | ||
| initial_probability: float | None = None | ||
|
|
||
|
|
||
| class CompositeHmmConfig(_BaseSerializable): | ||
| modules: dict[str, HmmSubModelConfig] | ||
| connections: tuple[HmmConnectionConfig, ...] | ||
| initialization: Literal["labels", "fully-connected"] | ||
| combined_algo_train: Literal["viterbi", "baum-welch", "labeled"] | ||
| combined_stop_threshold: float | ||
| combined_max_iterations: int | ||
| name: str | ||
| ``` | ||
|
|
||
| ## Scope | ||
|
|
||
| This step should only change configuration flow. | ||
| It should not yet change: | ||
|
|
||
| - `RothSegmentationHmm.model` | ||
| - the stored pretrained model format | ||
| - the use of raw `pomegranate` models internally | ||
| - `_HackyClonableHMMFix` | ||
| - `gaitmap/base.py` HMM serialization | ||
|
|
||
| ## Implementation Notes | ||
|
|
||
| - Keep the current Roth behavior by providing a default two-module config with `transition` and `stride`. | ||
| - Move the current submodel-specific parameters into default config values. | ||
| - Keep the current training loop structure: | ||
| - train each configured submodule independently | ||
| - combine them by building a final `pomegranate` model | ||
| - run the final refinement pass on the combined model | ||
| - The training/data-splitting logic can still be Roth-specific in this step. | ||
| The point is to stabilize the input surface first. | ||
|
|
||
| ## Compatibility Strategy | ||
|
|
||
| - Backwards compatibility for init parameters is optional. | ||
| - If needed, provide a thin compatibility shim that maps legacy `stride_model` / `transition_model` inputs to the new | ||
| config internally. | ||
| - The stored model format should remain unchanged in this step so that the pretrained artifact continues to load | ||
| without migration work. | ||
|
|
||
| ## Expected Outcome | ||
|
|
||
| After this step: | ||
|
|
||
| - the public constructor uses a single config object, | ||
| - custom multi-module setups become expressible, | ||
| - but the trained model is still a `pomegranate` model and behavior should be unchanged. |
Oops, something went wrong.
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.
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.
use assign and reuse the stride index/stride id