mixle.represent.heterogeneous module¶
Heterogeneous encoding – text, images, signals, sequences, and arbitrary scientific structures in ONE space.
A ModalityEncoder pairs a segmenter (raw -> units) with an embedding (units -> R^dim): one modality’s
path into the shared space. A HeterogeneousEncoder is a registry of them plus a learned modality tag
(a vector added to each unit so the downstream model knows the source), so a record with several modalities –
an image, a caption, a seismic trace, a molecule – becomes a single (N, dim) stream of vectors a single model
(a transformer, a mixture, the dependency-structure learner) consumes. Modalities compose because they land in
the same space; that is the representation-layer form of mixle’s “compose heterogeneous things into one model”.
Everything is torch modules, so the encoders train end to end – to a generative objective (wrap the stream in a
language-model / density leaf) or a downstream one (pool + a task head). Shared embeddings (the same
CategoricalEmbedding/FeatureEmbedding instance in two modalities) tie their vectors, as before.
- class ModalityEncoder(segmenter, embedding)[source]
Bases:
objectOne modality’s
raw -> (n_units, dim)path: a segmenter feeding an embedding into the shared space.- Parameters:
segmenter (Any)
embedding (Any)
- encode(raw)[source]
Torch tensor
(n_units, dim)– gradients flow to the embedding (and, via it, train the encoder).
- class HeterogeneousEncoder(dim)[source]
Bases:
objectA registry of per-modality encoders sharing one
dimspace, plus a learned modality-type embedding.- Parameters:
dim (int)
- register(modality, segmenter, embedding)[source]
Add a modality’s
(segmenter, embedding); the embedding’sdimmust match the shared space.
- register_encoder(modality, encoder)[source]
Add a pre-built
ModalityEncoder(e.g. aGraphEncoderthat owns its own segment+embed path).- Parameters:
modality (str)
encoder (ModalityEncoder)
- Return type:
HeterogeneousEncoder
- encode(record)[source]
A record
{modality: raw}->(stream, modality_ids): one(N, dim)tensor + each unit’s source id.Each modality’s units are embedded and the modality-tag vector is added, then all are concatenated in registration order – the unified token stream for a downstream model.
- encode_numpy(record)[source]