pub struct PromptTokenizer { /* private fields */ }Expand description
A tokenizer prepared for prompt encoding.
It holds a copy of the tokenizer without its added vocabulary, which encodes plain text, and the added vocabulary, which supplies special token IDs.
Implementations§
Trait Implementations§
Source§impl Clone for PromptTokenizer
impl Clone for PromptTokenizer
Source§impl TokenizerEncoder for PromptTokenizer
impl TokenizerEncoder for PromptTokenizer
Source§fn encode_ids(
&self,
text: &str,
special_ranges: &[Range<usize>],
) -> Result<Vec<u32>, String>
fn encode_ids( &self, text: &str, special_ranges: &[Range<usize>], ) -> Result<Vec<u32>, String>
Encode the plain text regions as one batch with the tokenizer without
its added vocabulary, and each special range as the added-vocabulary
token ID of its spelling. The batch runs in parallel unless the
TOKENIZERS_PARALLELISM environment variable disables it. The
tokenizer adds no tokens, such as a BOS token, beyond those that the
text encodes to, provided that it has no padding configured.
§Errors
Returns an error message when the tokenizer fails to encode a plain text region or the spelling of a special range is not in the added vocabulary.
§Panics
Panics if a range starts before the end of the previous range, ends
before it starts, extends past the end of text, or does not start and
end on char boundaries.
Auto Trait Implementations§
impl !Freeze for PromptTokenizer
impl RefUnwindSafe for PromptTokenizer
impl Send for PromptTokenizer
impl Sync for PromptTokenizer
impl Unpin for PromptTokenizer
impl UnsafeUnpin for PromptTokenizer
impl UnwindSafe for PromptTokenizer
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
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> ⓘ
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