pub struct LocalTokenizer { /* private fields */ }Expand description
A tokenizer loaded from a local tokenizer.json.
Implementations§
Source§impl LocalTokenizer
impl LocalTokenizer
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_bytes(bytes: &[u8]) -> Result<Self>
Load a tokenizer.json already in memory.
Sourcepub fn tokenize(&self, content: &str) -> Result<Vec<u32>>
pub fn tokenize(&self, content: &str) -> Result<Vec<u32>>
Encode without special tokens, matching fastjev’s encode_prompt.
Sourcepub fn detokenize(&self, tokens: &[u32]) -> Result<String>
pub fn detokenize(&self, tokens: &[u32]) -> Result<String>
Decode skipping special tokens, matching fastjev’s round-trip check.
Sourcepub fn vocab_size(&self) -> usize
pub fn vocab_size(&self) -> usize
The vocabulary size, for startup diagnostics.
Sourcepub fn verify_special_tokens(&self, expected: &Map<String, Value>) -> Result<()>
pub fn verify_special_tokens(&self, expected: &Map<String, Value>) -> Result<()>
Refuse a tokenizer whose special tokens disagree with the template.
A template that emits {{ bos_token }} and a tokenizer whose BOS token
is something else would produce a prompt the model never saw in
training, so this is checked rather than assumed.
Auto Trait Implementations§
impl !Freeze for LocalTokenizer
impl RefUnwindSafe for LocalTokenizer
impl Send for LocalTokenizer
impl Sync for LocalTokenizer
impl Unpin for LocalTokenizer
impl UnsafeUnpin for LocalTokenizer
impl UnwindSafe for LocalTokenizer
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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