mixle.represent.segment module¶
Segmenters – cut a raw object of any modality into units, WITHOUT committing to a vocabulary.
A Segmenter turns one raw object (a string, an image, a waveform, a set of node features) into an array of
units: (n_units,) integer ids for a discrete alphabet, or (n_units, feat...) float features for a
continuous modality. That is the whole of “the tokenizer” that is not objective-dependent – it is a
decomposition, not a vocabulary. Discreteness (mapping units to a codebook of ids) is a separate, optional,
learned step (mixle.represent.quantize), so a segmenter never has to guess the right tokens.
Fixed segmenters (bytes, characters, patches, windows, whole-object, element-set) commit to nothing beyond where to cut and keep all information; the model learns the rest. Learned segmenters (a segmental HMM over boundaries) are the objective-coupled upgrade and plug into the same contract.
- class Segmenter[source]
Bases:
objectBase:
segment(raw) -> np.ndarray.discretesays whether units are ids (vs. float features).- discrete: bool = False
- class ByteSegmenter[source]
Bases:
SegmenterA string/bytes ->
(n,)byte ids in[0, 256). The vocabulary-free text decomposition.- discrete: bool = True
- num_categories = 256
- class ElementSegmenter(alphabet)[source]
Bases:
SegmenterA sequence of hashable symbols (chars, amino acids, k-mers, categories) ->
(n,)ids via a fixed alphabet.Given
alphabet(the ordered symbols), each element maps to its index; unknown symbols map to0. The natural decomposition for proteins/genomes/any categorical sequence, and for characters (alphabet=list(...)).- Parameters:
alphabet (list[Any])
- discrete: bool = True
- class PatchSegmenter(patch=8)[source]
Bases:
SegmenterAn image
(H, W)or(C, H, W)->(n_patches, patch_features)float units (ViT-style, no vocab).- Parameters:
patch (int)
- discrete: bool = False
- class WindowSegmenter(window=64, hop=None)[source]
Bases:
SegmenterA 1-D signal
(T,)->(n_frames, window)float units by a sliding window (seismic/audio/time-series).- discrete: bool = False
- class WholeSegmenter[source]
Bases:
SegmenterA single feature vector ->
(1, feat): the object is one unit (a pooled structure descriptor, a record).- discrete: bool = False
- class SetSegmenter[source]
Bases:
SegmenterA set/list of feature vectors ->
(n_elements, feat): nodes of a graph, atoms of a molecule, taxa of a section.The general structured-object decomposition – a scientific structure becomes its set of element features (which a downstream model can further couple with a structure/message-passing embedding).
- discrete: bool = False