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: object

Base: segment(raw) -> np.ndarray. discrete says whether units are ids (vs. float features).

discrete: bool = False
segment(raw)[source]
Parameters:

raw (Any)

Return type:

ndarray

class ByteSegmenter[source]

Bases: Segmenter

A string/bytes -> (n,) byte ids in [0, 256). The vocabulary-free text decomposition.

discrete: bool = True
num_categories = 256
segment(raw)[source]
Parameters:

raw (Any)

Return type:

ndarray

class ElementSegmenter(alphabet)[source]

Bases: Segmenter

A 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 to 0. The natural decomposition for proteins/genomes/any categorical sequence, and for characters (alphabet=list(...)).

Parameters:

alphabet (list[Any])

discrete: bool = True
segment(raw)[source]
Parameters:

raw (Any)

Return type:

ndarray

class PatchSegmenter(patch=8)[source]

Bases: Segmenter

An image (H, W) or (C, H, W) -> (n_patches, patch_features) float units (ViT-style, no vocab).

Parameters:

patch (int)

discrete: bool = False
segment(raw)[source]
Parameters:

raw (Any)

Return type:

ndarray

unit_features(channels=1)[source]
Parameters:

channels (int)

Return type:

int

class WindowSegmenter(window=64, hop=None)[source]

Bases: Segmenter

A 1-D signal (T,) -> (n_frames, window) float units by a sliding window (seismic/audio/time-series).

Parameters:
  • window (int)

  • hop (int | None)

discrete: bool = False
segment(raw)[source]
Parameters:

raw (Any)

Return type:

ndarray

class WholeSegmenter[source]

Bases: Segmenter

A single feature vector -> (1, feat): the object is one unit (a pooled structure descriptor, a record).

discrete: bool = False
segment(raw)[source]
Parameters:

raw (Any)

Return type:

ndarray

class SetSegmenter[source]

Bases: Segmenter

A 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
segment(raw)[source]
Parameters:

raw (Any)

Return type:

ndarray