Skip to main content

CrossModalTokenizer

Struct CrossModalTokenizer 

Source
pub struct CrossModalTokenizer { /* private fields */ }
Expand description

Unified cross-modal tokenizer.

Manages one ModalityTokenizer per registered modality and applies:

  1. Per-modality linear projection (input → shared_dim)
  2. Modality-type embedding offset (for identity disambiguation)
  3. Shared alignment projection (shared_dim → shared_dim)
  4. Nearest-neighbour codebook quantization

Implementations§

Source§

impl CrossModalTokenizer

Source

pub fn new(shared_dim: usize) -> TokenizerResult<Self>

Create a new cross-modal tokenizer with the given shared embedding dimension.

Source

pub fn add_modality( &mut self, config: ModalityTokenizerConfig, ) -> TokenizerResult<()>

Register a new modality.

The config.token_dim must equal self.shared_dim.

Source

pub fn tokenize( &self, modality: &ModalityKind, input: &Array1<f32>, ) -> TokenizerResult<CrossModalToken>

Tokenize a single-modality input.

Steps:

  1. Encode raw input → shared_dim embedding (per-modality encoder + GELU)
  2. Add modality-type embedding offset
  3. Apply shared alignment projection
  4. Quantize against per-modality codebook
Source

pub fn tokenize_batch( &self, inputs: &[(ModalityKind, Array1<f32>)], ) -> TokenizerResult<CrossModalSequence>

Tokenize a batch of (modality, signal) pairs and return them as a CrossModalSequence.

Source

pub fn decode(&self, token: &CrossModalToken) -> TokenizerResult<Array1<f32>>

Decode a CrossModalToken back to the raw input space.

Uses the per-modality codebook entry as the quantized embedding, inverts the shared projection, removes the modality offset, and applies the pseudo-inverse decoder.

Source

pub fn shared_dim(&self) -> usize

The shared embedding dimension.

Source

pub fn num_modalities(&self) -> usize

Number of registered modalities.

Source

pub fn modality_names(&self) -> Vec<String>

Sorted list of registered modality keys.

Source

pub fn robotics_preset() -> TokenizerResult<Self>

Robotics preset: audio (16-dim), control (6-dim), sensor (9-dim) → shared_dim 64.

Source

pub fn audio_video_preset() -> TokenizerResult<Self>

Audio-video preset: audio (80-dim), video (512-dim) → shared_dim 256.

Trait Implementations§

Source§

impl SignalTokenizer for CrossModalTokenizer

SignalTokenizer implementation for CrossModalTokenizer.

Treats the input as a concatenation of registered modality signals (in registration order). Encodes each slice, concatenates the resulting embeddings, and returns the full multi-modal embedding vector.

For decode, the embedding is split back into per-modality chunks, decoded, and concatenated.

Source§

fn encode(&self, signal: &Array1<f32>) -> TokenizerResult<Array1<f32>>

Encode a concatenated multi-modal signal.

The input must be the concatenation of all registered modalities’ raw signals (in sorted key order). Each modality’s token embedding is concatenated into a single output vector of length num_modalities * shared_dim.

Source§

fn decode(&self, tokens: &Array1<f32>) -> TokenizerResult<Array1<f32>>

Decode a concatenated embedding vector back to the raw input space.

Source§

fn embed_dim(&self) -> usize

Total output embedding dimension: num_modalities * shared_dim.

Source§

fn vocab_size(&self) -> usize

Returns 0 (continuous-style tokenizer; each modality has its own discrete codebook).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> BatchTokenizer for T
where T: SignalTokenizer,

Source§

fn encode_batch(&self, signals: &Array2<f32>) -> TokenizerResult<Array2<f32>>

Encode multiple signals in batch Read more
Source§

fn decode_batch(&self, tokens: &Array2<f32>) -> TokenizerResult<Array2<f32>>

Decode multiple token sequences in batch Read more
Source§

fn encode_batch_padded_to( &self, signals: &[Array1<f32>], target_len: usize, ) -> TokenizerResult<Array2<f32>>

Encode batch with padding to handle variable length signals Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,