pub struct StaticModel { /* private fields */ }Expand description
Static embedding model for Model2Vec
Implementations§
Source§impl StaticModel
impl StaticModel
Sourcepub fn from_bytes<T, M, C>(
tokenizer_bytes: T,
model_bytes: M,
config_bytes: C,
normalize: Option<bool>,
) -> Result<Self>
pub fn from_bytes<T, M, C>( tokenizer_bytes: T, model_bytes: M, config_bytes: C, normalize: Option<bool>, ) -> Result<Self>
Load a Model2Vec model directly from in-memory bytes.
This path is useful for runtimes that fetch model assets as bytes rather than reading them from a local filesystem.
Sourcepub fn from_pretrained<P: AsRef<Path>>(
repo_or_path: P,
token: Option<&str>,
normalize: Option<bool>,
subfolder: Option<&str>,
) -> Result<Self>
pub fn from_pretrained<P: AsRef<Path>>( repo_or_path: P, token: Option<&str>, normalize: Option<bool>, subfolder: Option<&str>, ) -> Result<Self>
Load a Model2Vec model from a local folder or the HuggingFace Hub.
§Arguments
repo_or_path- HuggingFace repo ID or local path to the model folder.token- Optional HuggingFace token for authenticated downloads.normalize- Optional flag to normalize embeddings (default from the resolved config file).subfolder- Optional subfolder within the repo or path to look for model files.
Sourcepub fn from_owned(
tokenizer: Tokenizer,
embeddings: Vec<f32>,
rows: usize,
cols: usize,
normalize: bool,
weights: Option<Vec<f32>>,
token_mapping: Option<Vec<usize>>,
) -> Result<Self>
pub fn from_owned( tokenizer: Tokenizer, embeddings: Vec<f32>, rows: usize, cols: usize, normalize: bool, weights: Option<Vec<f32>>, token_mapping: Option<Vec<usize>>, ) -> Result<Self>
Construct from owned data.
§Arguments
tokenizer- Pre-deserialized tokenizerembeddings- Owned f32 embedding datarows- Number of vocabulary entriescols- Embedding dimensionnormalize- Whether to L2-normalize output embeddingsweights- Optional per-token weights for quantized modelstoken_mapping- Optional token ID mapping for quantized models
Sourcepub fn from_borrowed(
tokenizer: Tokenizer,
embeddings: &'static [f32],
rows: usize,
cols: usize,
normalize: bool,
weights: Option<&'static [f32]>,
token_mapping: Option<&'static [usize]>,
) -> Result<Self>
pub fn from_borrowed( tokenizer: Tokenizer, embeddings: &'static [f32], rows: usize, cols: usize, normalize: bool, weights: Option<&'static [f32]>, token_mapping: Option<&'static [usize]>, ) -> Result<Self>
Construct from static slices (zero-copy for embedded binary data).
§Arguments
tokenizer- Pre-deserialized tokenizerembeddings- Static f32 embedding data (borrowed, no copy)rows- Number of vocabulary entriescols- Embedding dimensionnormalize- Whether to L2-normalize output embeddingsweights- Optional static per-token weights for quantized modelstoken_mapping- Optional static token ID mapping for quantized models
Sourcepub fn encode_with_args(
&self,
sentences: &[String],
max_length: Option<usize>,
batch_size: usize,
) -> Vec<Vec<f32>>
pub fn encode_with_args( &self, sentences: &[String], max_length: Option<usize>, batch_size: usize, ) -> Vec<Vec<f32>>
Encode texts into embeddings.
§Arguments
sentences- the list of sentences to encode.max_length- max tokens per text.batch_size- number of texts per batch.
Sourcepub fn encode(&self, sentences: &[String]) -> Vec<Vec<f32>>
pub fn encode(&self, sentences: &[String]) -> Vec<Vec<f32>>
Default encode: max_length=512, batch_size=1024
Sourcepub fn encode_single(&self, sentence: &str) -> Vec<f32>
pub fn encode_single(&self, sentence: &str) -> Vec<f32>
Encode a single sentence into a vector.
Trait Implementations§
Source§impl Clone for StaticModel
impl Clone for StaticModel
Source§fn clone(&self) -> StaticModel
fn clone(&self) -> StaticModel
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl !Freeze for StaticModel
impl RefUnwindSafe for StaticModel
impl Send for StaticModel
impl Sync for StaticModel
impl Unpin for StaticModel
impl UnsafeUnpin for StaticModel
impl UnwindSafe for StaticModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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