pub struct ByteLevel { /* private fields */ }Expand description
A compiled ByteLevel pre-tokenizer.
Optionally splits input using the GPT-2 regex, then maps every byte of the resulting UTF-8 text to a visible Unicode character.
Constructed once from config fields (typically via
PreTokenizerConfig::ByteLevel), then reused across
many inputs.
Implementations§
Source§impl ByteLevel
impl ByteLevel
Sourcepub fn from_config(
add_prefix_space: bool,
trim_offsets: bool,
use_regex: bool,
) -> Result<Self, Error>
pub fn from_config( add_prefix_space: bool, trim_offsets: bool, use_regex: bool, ) -> Result<Self, Error>
Build a ByteLevel from config fields.
Sourcepub fn is_bulk_only(&self) -> bool
pub fn is_bulk_only(&self) -> bool
Returns true when this instance does no regex splitting or prefix-space
insertion — only bulk byte encoding. In that mode the encoding can be
fused into the BPE cache lookup to skip it on warm runs.
Sourcepub fn pre_tokenize(&self, pts: &mut PreTokenizedString) -> Result<(), Error>
pub fn pre_tokenize(&self, pts: &mut PreTokenizedString) -> Result<(), Error>
Pre-tokenize in place using byte-level encoding.
For each text split in pts: optionally prepend a space, split
by the GPT-2 regex, and byte-encode each piece. Splits with a
pre-assigned token ID are byte-encoded but otherwise passed
through.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for ByteLevel
impl<'de> Deserialize<'de> for ByteLevel
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for ByteLevel
impl RefUnwindSafe for ByteLevel
impl Send for ByteLevel
impl Sync for ByteLevel
impl Unpin for ByteLevel
impl UnsafeUnpin for ByteLevel
impl UnwindSafe for ByteLevel
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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