Repository navigation
Conversation
fd23b12 to
157f8e5
Compare
157f8e5 to
350e50e
Compare
|
/review |
Test CoverageTotal: 86.13% (44790 / 52003 lines)
|
| size (default 128). A ``{field: ...}`` dict sets fields one by | ||
| one: an int for all of a field's levels, or one | ||
| :class:`LevelEmbedding` per level, innermost first. Unlisted | ||
| fields get 128. See :func:`level_embeddings`. |
There was a problem hiding this comment.
Fixed in a719c9a: added level_embeddings to docs/api/models/pyhealth.models.SequenceEmbeddingModel.rst. Also took the other suggestion: a non-int, non-dict embedding_dim now raises a TypeError saying what is accepted (tested).
There was a problem hiding this comment.
Previous review
AI Review
suggestion: approve
decision: human review
Thank you for this contribution. It lets RNN_V2(dataset) build with no hand-written settings. embedding_dim now defaults to 128, accepts one int, or takes a per-field dict of ints and/or per-level lists. The new level_embeddings helper expands an int into per-level embeddings.
The diff looks correct and complete, and the description matches the code. The behaviour change (an omitted field gets the default instead of raising) is stated clearly, and the two tests that asserted the old error were updated. The new tests cover the default, an int, per-field values, an unlisted field and invalid sizes. Coverage is above the bar: 94.86% for rnn.py, 100% for sequence_embedding.py and 86.12% for the whole repository. RNN_V2 already builds on SequenceEmbeddingModel, so this adds no new link between components.
The first-pass automated check marked this for manual review because SequenceEmbeddingModel is a building block that RNN_V2 depends on. The change alters its embedding_dim signature, its default and its missing-field behaviour. A maintainer will make the final call. To me it looks like a self-contained, low-risk change.
Optional suggestions:
- The SequenceEmbeddingModel docstring cross-references :func:
level_embeddings, which has no docs/api entry. You could add one or drop the cross-reference. - A non-int, non-dict embedding_dim, such as a float, gives an unclear TypeError. You could validate it up front and raise a clearer message.
- Stacking on #1590 means this should merge after that PR.
Reviewed commit 350e50e
| size (default 128). A ``{field: ...}`` dict sets fields one by | ||
| one: an int for all of a field's levels, or one | ||
| :class:`LevelEmbedding` per level, innermost first. Unlisted | ||
| fields get 128. See :func:`level_embeddings`. |
There was a problem hiding this comment.
Fixed in a719c9a: added level_embeddings to docs/api/models/pyhealth.models.SequenceEmbeddingModel.rst. Also took the other suggestion: a non-int, non-dict embedding_dim now raises a TypeError saying what is accepted (tested).
|
/review |
| missing = processors.keys() - set(embedding_dim) | ||
| if missing: | ||
| raise ValueError(f"embedding_dim has no entry for {sorted(missing)}.") | ||
| embedding_dim = { |
There was a problem hiding this comment.
Fixed in cb0cb17: a per-field value that is neither an int nor a list of LevelEmbedding now raises a TypeError naming the field (e.g. embedding_dim['labs'] must be an int ...), consistent with the top-level check. Took the other two suggestions as well: tests for {"labs": 0} and {"labs": 64.0}, and each field's value is read once.
There was a problem hiding this comment.
Previous review
AI Review
suggestion: approve
decision: human review
Thank you for this contribution. It lets RNN_V2(dataset) and SequenceEmbeddingModel build with no hand-written embedding sizes. They accept a single int (default 128), a per-field int, or the existing per-level lists. The new level_embeddings helper is documented and has a doctest. The behaviour change is stated in the description: a field missing from the dict now gets the default instead of raising an error. The two tests that asserted the old error were updated. It looks ready to merge.
Coverage meets the bar. sequence_embedding.py is at 100%, rnn.py at 94.86%, and the whole repository at 86.12%. The RNN_V2 to SequenceEmbeddingModel link already existed, so there is no new sharing to explain.
Optional suggestions:
- A float per-field size such as
{"labs": 64.0}currently falls through to the "must have one dict per level" error. A "positive int" message would be clearer. - Add a test for invalid per-field sizes, for example
{"labs": 0}. - Both
isinstance(..., int)checks in the dict comprehension callembedding_dim.get(field, 128)twice. Computing the value once would be a bit tidier.
Reviewed commit a719c9a
a719c9a to
cb0cb17
Compare
| missing = processors.keys() - set(embedding_dim) | ||
| if missing: | ||
| raise ValueError(f"embedding_dim has no entry for {sorted(missing)}.") | ||
| embedding_dim = { |
There was a problem hiding this comment.
Fixed in cb0cb17: a per-field value that is neither an int nor a list of LevelEmbedding now raises a TypeError naming the field (e.g. embedding_dim['labs'] must be an int ...), consistent with the top-level check. Took the other two suggestions as well: tests for {"labs": 0} and {"labs": 64.0}, and each field's value is read once.
|
/review |
| namespaces, shape = vocab_size[depth], value_dim[depth] | ||
| level: LevelEmbedding = {} | ||
| if namespaces is not None: | ||
| level["tokens"] = (size,) * len(namespaces) |
There was a problem hiding this comment.
Added in 3d133e6: test_int_embedding_dim_per_namespace_and_spatial_values in tests/core/test_sequence_embedding.py. A level with two token namespaces and values gets 8 + 8 + 8 from embedding_dim=8, and spatial values kept apart (flatten_spatial=False) get the int size at each position.
There was a problem hiding this comment.
Previous review
AI Review
suggestion: approve
decision: human review
Thank you for this contribution. It lets RNN_V2 and SequenceEmbeddingModel build from the dataset alone. It accepts an int, a per-field dict, or the full per-level form, and it adds a documented level_embeddings helper.
The change looks ready to merge. The code matches the description. The one behaviour change is that a field missing from an embedding_dim dict now gets the default size instead of raising. You state this clearly, and you updated the two tests that asserted the old error. The new tests cover default building, training, an int, per-field values and invalid sizes. The docs match the code. The RNN_V2 to SequenceEmbeddingModel link already existed, and the new helper is in the same module. Coverage is above the bar: 94.86% for rnn.py, 100% for sequence_embedding.py, and 86.12% for the whole repository.
Optional suggestions:
- Add a test for the int path with a field that has several token namespaces and with spatial values, since the new tests don't cover those cases directly.
- Since PR #1590 is stacked below this one, remember to merge it first.
Reviewed commit cb0cb17
| namespaces, shape = vocab_size[depth], value_dim[depth] | ||
| level: LevelEmbedding = {} | ||
| if namespaces is not None: | ||
| level["tokens"] = (size,) * len(namespaces) |
There was a problem hiding this comment.
Added in 3d133e6: test_int_embedding_dim_per_namespace_and_spatial_values in tests/core/test_sequence_embedding.py. A level with two token namespaces and values gets 8 + 8 + 8 from embedding_dim=8, and spatial values kept apart (flatten_spatial=False) get the int size at each position.
cb0cb17 to
3d133e6
Compare
|
/review |
There was a problem hiding this comment.
Previous review
AI Review
suggestion: approve
decision: human review
Thank you for this contribution. It lets RNN_V2 and SequenceEmbeddingModel build from the dataset alone. embedding_dim can now be one int, a per-field dict, or the full per-level form. A new public helper, level_embeddings, does the expansion.
It looks ready to merge. The change does what the description says, and the one behaviour change is stated: a field missing from the dict now gets 128 instead of raising an error. The tests cover the no-settings build, an int, per-field values, invalid sizes, and spatial values. Coverage is 100% for sequence_embedding.py and 94.86% for rnn.py, and 86.12% for the whole repository. All of these are above the bar. The docs are updated to match the code, including the new autofunction entry.
Optional suggestions:
- Silently defaulting a field left out of the dict could hide a typo in a field name. Unknown names still raise, so this risk is small. You could mention the default in the RNN_V2 class docstring example.
- test_no_settings runs a backward pass but not an optimizer step. That is enough for this change.
- Merge this after #1590, as your description says.
Reviewed commit 3d133e6
3d133e6 to
b22be84
Compare
|
/review |
| [{'tokens': (16,)}, {}] | ||
| """ | ||
| if not isinstance(size, int) or isinstance(size, bool) or size <= 0: | ||
| raise ValueError(f"embedding_dim must be a positive int, got {size!r}.") |
There was a problem hiding this comment.
Fixed in 5e4ee11: a bad per-field size now raises "embedding_dim['labs'] must be a positive int, got 0." (tested). Also took the optional suggestion: a top-level int is validated up front, so it is checked even when the dataset has no jagged fields.
There was a problem hiding this comment.
Previous review
AI Review
suggestion: approve
decision: human review
Thank you for this contribution. It lets RNN_V2 and SequenceEmbeddingModel be built from the dataset alone, with a default embedding size of 128. It also accepts a single int or per-field ints, and the full per-level form still works.
This looks ready to merge. SequenceEmbeddingModel and RNN_V2 are self-contained components. The change is additive for existing dict-form callers, and the one behaviour change (an unlisted field now gets the default instead of raising) is stated in the description and covered by the updated tests. Coverage is 100% for sequence_embedding.py and 94.9% for rnn.py, and the whole repository is at 86.1%. All of these are above the bar. The docs page for the new level_embeddings function is included.
Optional suggestions:
- The "positive int" error from
level_embeddingsdoesn't name the field when a per-field value is bad. Including the field name would make it easier to debug. - An int
embedding_dimisn't validated when the dataset has no jagged fields. You could validate it up front. - The PR is stacked on #1590, so please merge that one first.
Reviewed commit b22be84
b22be84 to
5e4ee11
Compare
| [{'tokens': (16,)}, {}] | ||
| """ | ||
| if not isinstance(size, int) or isinstance(size, bool) or size <= 0: | ||
| raise ValueError(f"embedding_dim must be a positive int, got {size!r}.") |
There was a problem hiding this comment.
Fixed in 5e4ee11: a bad per-field size now raises "embedding_dim['labs'] must be a positive int, got 0." (tested). Also took the optional suggestion: a top-level int is validated up front, so it is checked even when the dataset has no jagged fields.
|
/review |
| size (default 128). A ``{field: ...}`` dict sets fields one by | ||
| one: an int for all of a field's levels, or one | ||
| :class:`LevelEmbedding` per level, innermost first. Unlisted | ||
| fields get 128. See :func:`level_embeddings`. |
There was a problem hiding this comment.
Fixed in 7b2dfaa: level_embeddings is now exported from pyhealth.models, the docs page documents it as pyhealth.models.level_embeddings, and the docstring reference uses that public path. The page also notes the default of 128.
| :undoc-members: | ||
| :show-inheritance: | ||
|
|
||
| .. autofunction:: pyhealth.models.sequence_embedding.level_embeddings |
There was a problem hiding this comment.
Fixed in 7b2dfaa: level_embeddings is now exported from pyhealth.models, the docs page documents it as pyhealth.models.level_embeddings, and the docstring reference uses that public path. The page also notes the default of 128.
There was a problem hiding this comment.
Previous review
AI Review
suggestion: approve
decision: human review
Thank you for this contribution. It lets RNN_V2(dataset) and SequenceEmbeddingModel build with no hand-written embedding sizes. They now take an int, a per-field dict, or the full per-level form, and fields left out get 128. The change looks correct and complete, and it looks ready to merge.
Both changed files are self-contained components, not base classes or shared infrastructure. The existing RNN_V2 to SequenceEmbeddingModel link is unchanged. The one behaviour change, that an unlisted field now gets the default instead of raising, is stated in the description, and the two tests that asserted the old error were updated. Coverage is above the bar: sequence_embedding.py is at 100%, rnn.py at 94.86%, and the whole repository at 86.13%.
Optional suggestions:
- The
:func:level_embeddings`` reference in the SequenceEmbeddingModel docstring may not resolve in Sphinx. The rst documents the function by its internal module path, andpyhealth.modelsdoesn't export it. Using the full path in the reference, or exporting the function, would fix this. - A short line in the docs noting that 128 is the default would help readers.
Reviewed commit 5e4ee11
embedding_dim is now optional (default 128) and also takes one int for every field, or an int per field. level_embeddings() expands an int into one LevelEmbedding per level from the processor's token namespaces and value layout. A field left out of a dict gets the default instead of an error, so RNN_V2(dataset) builds with no hand-written settings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A per-field value that is neither an int nor a list of LevelEmbedding now raises a TypeError naming the field, like the top-level check, instead of the per-level count error. Each field's value is read once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A bad per-field size now raises "embedding_dim['labs'] must be a positive int", and a top-level int is checked before the fields are read, so it is checked even when the dataset has no jagged fields. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The docs and the SequenceEmbeddingModel docstring now use the public pyhealth.models.level_embeddings path, so the reference resolves, and the docs page says embedding sizes default to 128. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5e4ee11 to
7b2dfaa
Compare
| size (default 128). A ``{field: ...}`` dict sets fields one by | ||
| one: an int for all of a field's levels, or one | ||
| :class:`LevelEmbedding` per level, innermost first. Unlisted | ||
| fields get 128. See :func:`level_embeddings`. |
There was a problem hiding this comment.
Fixed in 7b2dfaa: level_embeddings is now exported from pyhealth.models, the docs page documents it as pyhealth.models.level_embeddings, and the docstring reference uses that public path. The page also notes the default of 128.
| :undoc-members: | ||
| :show-inheritance: | ||
|
|
||
| .. autofunction:: pyhealth.models.sequence_embedding.level_embeddings |
There was a problem hiding this comment.
Fixed in 7b2dfaa: level_embeddings is now exported from pyhealth.models, the docs page documents it as pyhealth.models.level_embeddings, and the docstring reference uses that public path. The page also notes the default of 128.
|
/review |
| embedding_dim: Per V2 field, one | ||
| embedding_dim: The embedding sizes, as in | ||
| :class:`~pyhealth.models.SequenceEmbeddingModel`: one int for | ||
| every field and level (default 128), or per field an int or one |
There was a problem hiding this comment.
Fixed in 288dd62: the RNN_V2 and SequenceEmbeddingModel docstrings and the PR description now say the int is the size of each token namespace embedding and each values projection, so a level with K namespaces and values is size * (K + 1) wide. On the optional point, level_embeddings has a direct doctest (run by the docs checks) besides the model tests.
There was a problem hiding this comment.
Correction to my last reply: CI does not run docstring examples, so the level_embeddings doctest is only checked when run by hand (it passes locally). Its behaviour is covered in CI through tests/core/test_sequence_embedding.py (test_int_embedding_dim_per_namespace_and_spatial_values) and the RNN_V2 default-size tests.
There was a problem hiding this comment.
Previous review
AI Review
suggestion: approve
decision: human review
Thank you for this contribution. RNN_V2(dataset) now builds with no hand-written embedding settings. embedding_dim also accepts one int or a per-field dict, and the new level_embeddings helper expands an int into per-level embeddings.
The change looks ready to merge. The code matches the description. The behaviour change is stated, and the two old tests that asserted the removed error were updated. The new tests cover defaults, an int, per-field values and invalid sizes. Coverage is 100% for sequence_embedding.py, about 95% for rnn.py and 100% for models/__init__.py. The whole repository is at 86%, so all files meet the bar. The change stays within self-contained components. It adds no new links between components, and SequenceEmbeddingModel was already used by RNN_V2.
Optional suggestions:
- The wording "one size for every field and level" is slightly loose. A level with several token namespaces plus values ends up with
size × (namespaces + 1)dimensions, because each namespace and the values projection getsize. You could clarify this in the docstring and docs. - Add a small direct test for
level_embeddings. It is currently exercised only through the models.
Reviewed commit 7b2dfaa
…ction Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| embedding_dim: Per V2 field, one | ||
| embedding_dim: The embedding sizes, as in | ||
| :class:`~pyhealth.models.SequenceEmbeddingModel`: one int for | ||
| every field and level (default 128), or per field an int or one |
There was a problem hiding this comment.
Fixed in 288dd62: the RNN_V2 and SequenceEmbeddingModel docstrings and the PR description now say the int is the size of each token namespace embedding and each values projection, so a level with K namespaces and values is size * (K + 1) wide. On the optional point, level_embeddings has a direct doctest (run by the docs checks) besides the model tests.
|
/review |
There was a problem hiding this comment.
AI Review
suggestion: approve
decision: human review
Thank you for this contribution. It lets RNN_V2(dataset) and SequenceEmbeddingModel(dataset) build with no hand-written settings. embedding_dim now takes an int, a per-field dict, or the full per-level form, and the new level_embeddings helper expands an int into per-level embeddings.
The change looks ready to merge as far as I can tell. The code matches the description and docs. The tests cover the default build, a single int, per-field sizes, invalid sizes and the two updated tests. Coverage is above the bar: 100% for sequence_embedding.py, 94.86% for rnn.py and 100% for models/init.py, with 86.13% for the whole repository. I didn't see any new link between components. level_embeddings is only used inside its own module, and RNN_V2 already used SequenceEmbeddingModel.
This can't be approved automatically because SequenceEmbeddingModel is a shared building block that RNN_V2 builds on. Its constructor default changes, and a field missing from embedding_dim now gets 128 instead of raising an error. The change is documented and looks sound, but a maintainer should confirm those defaults. A maintainer makes the final call.
Optional suggestions:
- Silently defaulting omitted fields to 128 could hide a forgotten field. You could log a short message listing the defaulted fields.
- The
size * (K + 1)width can get large with many namespaces. A short example in the docs might help.
Reviewed commit 288dd62
What this does
RNN_V2(dataset)now builds with no hand-written settings.embedding_dimused to be required and had to spell out one dict per field and per level, matching each processor's vocabularies and value layout:The full per-level form still works unchanged.
Why
This is the "needs per-field config" group from the task x model compatibility run (18 crashes): models that cannot be built from the dataset alone. It also matters for #1590, where the YAIB
jaggedview is read byRNN_V2, and for a CI matrix that constructs every model withModel(dataset).Changes
pyhealth/models/sequence_embedding.py: newlevel_embeddings(processor, size)expands one size into aLevelEmbeddingper level, from the processor's token namespaces and values.SequenceEmbeddingModelaccepts an int, or a dict of ints and/or per-level lists; a field left out gets 128.pyhealth/models/rnn.py:RNN_V2'sembedding_dimdefaults to 128 and takes the same forms.Behaviour change
A field missing from an
embedding_dimdict now gets the default size instead of raisingembedding_dim has no entry for [...]. Two existing tests asserted the old error and were updated.Testing
TestDefaultEmbeddingDimintests/core/test_rnn_v2.py: building and training with no settings, an int, per-field values, and rejection of invalid sizes.RNN_V2(train)trains one step on the YAIBjaggedview (synthetic data).test_sequence_embedding.py,test_rnn_v2.py,test_unified_bridge.py,test_per_step_labels.py,test_timeseries_modes.py,test_task_views.py: 213 passed.tools/check_pr_rules.pypasses.The default of 128 can change results versus a hand-tuned setting; it matches
RNN_V2's existinghidden_dimdefault.🤖 Generated with Claude Code