mixle.represent.generative module¶
Generative objective for fitting embeddings and optional codebooks.
Rather than tune the encoder to a label, train it to reconstruct its input as
an autoencoder over units. The shared-space vector must retain enough
information to rebuild the unit, so the representation has an explicit
generative objective. Add a
VectorQuantizer and the model becomes a
VQ-VAE: encode -> quantize (straight-through) -> decode, with the codebook
periodically refit on the current embeddings. The learned vocabulary is then
selected by reconstruction quality instead of being fixed by a tokenizer chosen
outside the model.
fit_autoencoder returns the trained encoder + decoder (+ codebook) and the reconstruction-loss history. It is
modality-agnostic: feed it the unit-feature array from any continuous segmenter (patches, windows, atoms, …).
- class AutoencoderResult(encoder, decoder, quantizer, losses=<factory>)[source]
Bases:
objectA reconstruction-trained representation with encoder, decoder, optional codebook, and loss curve.
- Parameters:
- fit_autoencoder(units, dim, *, hidden=(), quantizer=None, epochs=200, lr=1e-2, refit_codebook_every=25, commitment=0.25, seed=0)[source]
Train an encoder+decoder to reconstruct
units(N, in_features)with an optional VQ bottleneck.Without
quantizerthis is a standard autoencoder. With one, it is a VQ-VAE: the encoder’s vectors are quantized (straight-through) before decoding and the codebook is refit everyrefit_codebook_everyepochs on the current embeddings.commitmentweights the VQ codebook-commitment term.