Skip to content

Towards Unified Sequence Representation III: Add SequenceEmbeddingModel for SequenceProcessorV2 fields - #1352

Draft
Logiquo wants to merge 1 commit into
feat/seq-v2-2from
feat/seq-v2-3
Draft

Logiquo wants to merge 1 commit into
feat/seq-v2-2from
feat/seq-v2-3

Conversation

@Logiquo

@Logiquo Logiquo commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Third PR in the stack toward a unified sequence representation, on top of #1347. It adds SequenceEmbeddingModel, the embedding building block for models over SequenceProcessorV2 fields.

Changes

  • SequenceEmbeddingModel embeds the packed records of every sequence_v2 field of a batch, level by level. A record's embedding is one nn.Embedding per token namespace (<pad> embeds to zeros) and a linear projection of its values, concatenated. Offsets and times are passed through, so models can encode the hierarchy bottom-up.
  • embedding_dim takes one LevelEmbedding per level and field.
  • flatten_spatial keeps spatial value axes (e.g. ECG samples) apart and projects at each position.
  • pretrain initializes token namespaces from text-vector files (PretrainedEmbedding).
  • mask="concat" projects a level's values together with its missing indicators.
  • Exported from pyhealth.models, with an API page.

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Test Coverage

Total: 74.96% (21214 / 28300 lines)

Modified file Coverage Lines
pyhealth/benchmarks/__init__.py 100.00% 2 / 2
pyhealth/benchmarks/_serialization.py 95.95% 71 / 74
pyhealth/benchmarks/base.py 98.33% 59 / 60
pyhealth/models/__init__.py 100.00% 53 / 53
pyhealth/models/sequence_embedding.py 100.00% 148 / 148
pyhealth/models/vae.py 96.77% 90 / 93
pyhealth/tasks/__init__.py 89.74% 35 / 39
pyhealth/tasks/covid19_cxr_generation.py 100.00% 9 / 9

Workflow run · 8bc5b4f

SequenceEmbeddingModel embeds the packed records of every sequence_v2
field of a batch, level by level: one nn.Embedding per token namespace
(<pad> embeds to zeros) and a linear projection of the values,
concatenated. Offsets and times are passed through, so models can encode
the hierarchy bottom-up.

- embedding_dim takes one LevelEmbedding per level and field.
- flatten_spatial keeps spatial value axes (e.g. ECG samples) apart and
  projects at each position.
- pretrain initializes token namespaces from text-vector files
  (PretrainedEmbedding).
- mask="concat" projects a level's values together with its missing
  indicators.
- An empty numeric level embeds to an empty [0, D] tensor.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant