Skip to main content

TextEncoder

Trait TextEncoder 

Source
pub trait TextEncoder {
    // Required methods
    fn n_embd(&self) -> usize;
    fn n_ctx_train(&self) -> usize;
    fn pooling_type(&self) -> PoolingType;
    fn encode_tokens(&self, tokens: &[u32]) -> Result<Vec<f32>, EncodeError>;

    // Provided methods
    fn wrap_special(&self, pieces: &[u32]) -> Vec<u32> { ... }
    fn embed_tokens(&self, tokens: &[u32]) -> Result<Vec<f32>, EncodeError> { ... }
}
Expand description

A model that turns a whole token sequence into hidden states in one pass, with no carried state and no logits.

Required Methods§

Source

fn n_embd(&self) -> usize

Width of one hidden-state row, and of the pooled embedding.

Source

fn n_ctx_train(&self) -> usize

Longest sequence this checkpoint can represent. For a learned position table this is the table’s height, and exceeding it is an error rather than a degradation.

Source

fn pooling_type(&self) -> PoolingType

What the checkpoint’s own {arch}.pooling_type said.

Source

fn encode_tokens(&self, tokens: &[u32]) -> Result<Vec<f32>, EncodeError>

n_tokens × n_embd hidden states, in row order.

Provided Methods§

Source

fn wrap_special(&self, pieces: &[u32]) -> Vec<u32>

Wraps a tokenizer’s pieces in whatever the model requires around them — for BERT, [CLS] … [SEP].

This is on the encoder rather than the tokenizer because ferrox’s tokenizers deliberately encode text only (they are checked token-for-token against llama_tokenize(..., add_special = false, ...)), while llama.cpp keeps add_special in the vocab and applies it here. The default adds nothing, so an encoder that genuinely needs no wrapper does not have to say so.

Source

fn embed_tokens(&self, tokens: &[u32]) -> Result<Vec<f32>, EncodeError>

Self::encode_tokens followed by the checkpoint’s own pooling. Not L2-normalized — see crate::pooling::pool.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§