pub struct Tokenizer { /* private fields */ }Expand description
Tokenizer implementation that wraps HuggingFace tokenizers
Implementations§
Source§impl Tokenizer
impl Tokenizer
Sourcepub fn from_file<P: AsRef<Path>>(path: P) -> ModelResult<Self>
pub fn from_file<P: AsRef<Path>>(path: P) -> ModelResult<Self>
Load tokenizer from a tokenizer.json file (HuggingFace format)
Sourcepub fn from_model_dir<P: AsRef<Path>>(model_dir: P) -> ModelResult<Self>
pub fn from_model_dir<P: AsRef<Path>>(model_dir: P) -> ModelResult<Self>
Load tokenizer from a model directory (looks for tokenizer.json)
Sourcepub fn from_gguf(gguf_tokenizer: &GGUFTokenizer) -> ModelResult<Self>
pub fn from_gguf(gguf_tokenizer: &GGUFTokenizer) -> ModelResult<Self>
Create tokenizer from GGUF tokenizer data
Sourcepub fn from_model_weights(weights: &ModelWeights) -> ModelResult<Self>
pub fn from_model_weights(weights: &ModelWeights) -> ModelResult<Self>
Create tokenizer from ModelWeights (prefers GGUF tokenizer if available)
Sourcepub fn from_pretrained(model_name: &str) -> ModelResult<Self>
pub fn from_pretrained(model_name: &str) -> ModelResult<Self>
Create tokenizer from pretrained model name (downloads from HuggingFace) Note: This requires network access and HuggingFace Hub authentication for gated models
Sourcepub fn encode_with_special_tokens(
&self,
text: &str,
add_bos: bool,
add_eos: bool,
) -> Vec<u32>
pub fn encode_with_special_tokens( &self, text: &str, add_bos: bool, add_eos: bool, ) -> Vec<u32>
Encode text with special tokens
Sourcepub fn decode_raw(&self, token_ids: &[u32]) -> String
pub fn decode_raw(&self, token_ids: &[u32]) -> String
Decode token IDs without special token filtering
Sourcepub fn vocab_size(&self) -> usize
pub fn vocab_size(&self) -> usize
Get vocabulary size
Sourcepub fn special_tokens(&self) -> &SpecialTokens
pub fn special_tokens(&self) -> &SpecialTokens
Get special tokens
Sourcepub fn bos_token_id(&self) -> u32
pub fn bos_token_id(&self) -> u32
Get BOS token ID
Sourcepub fn eos_token_id(&self) -> u32
pub fn eos_token_id(&self) -> u32
Get EOS token ID
Sourcepub fn pad_token_id(&self) -> u32
pub fn pad_token_id(&self) -> u32
Get PAD token ID
Sourcepub fn unk_token_id(&self) -> u32
pub fn unk_token_id(&self) -> u32
Get UNK token ID
Sourcepub fn contains_token(&self, token: &str) -> bool
pub fn contains_token(&self, token: &str) -> bool
Check if token exists in vocabulary
Sourcepub fn token_to_id(&self, token: &str) -> Option<u32>
pub fn token_to_id(&self, token: &str) -> Option<u32>
Get token ID for a string
Sourcepub fn id_to_token(&self, id: u32) -> Option<String>
pub fn id_to_token(&self, id: u32) -> Option<String>
Get string for a token ID
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Tokenizer
impl RefUnwindSafe for Tokenizer
impl Send for Tokenizer
impl Sync for Tokenizer
impl Unpin for Tokenizer
impl UnsafeUnpin for Tokenizer
impl UnwindSafe for Tokenizer
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
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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