pub struct Gpt2Tokenizer { /* private fields */ }Implementations§
Source§impl Gpt2Tokenizer
impl Gpt2Tokenizer
pub fn from_files( vocab_path: impl AsRef<Path>, merges_path: impl AsRef<Path>, ) -> Result<Self>
Sourcepub fn from_strs(vocab_json: &str, merges: &str) -> Result<Self>
pub fn from_strs(vocab_json: &str, merges: &str) -> Result<Self>
Build from the contents of vocab.json and merges.txt — the primary
form; on wasm the strings arrive from an HTTP fetch.
Sourcepub fn from_dir(dir: impl AsRef<Path>) -> Result<Self>
pub fn from_dir(dir: impl AsRef<Path>) -> Result<Self>
Load vocab.json + merges.txt from a directory.
pub fn encode(&self, text: &str) -> Result<Vec<u32>>
pub fn decode(&self, ids: &[u32]) -> String
Sourcepub fn decode_bytes(&self, ids: &[u32]) -> Vec<u8> ⓘ
pub fn decode_bytes(&self, ids: &[u32]) -> Vec<u8> ⓘ
Raw byte-level decode. Unlike Gpt2Tokenizer::decode this is exact
and append-only per token (id sequence a ++ b decodes to
bytes(a) ++ bytes(b)), which streaming builds on: a multi-byte UTF-8
character split across BPE tokens completes once the next token’s
bytes arrive.
pub fn vocab_size(&self) -> usize
Trait Implementations§
Source§impl Tokenizer for Gpt2Tokenizer
Delegates to the inherent methods, which stay public so existing callers
compile unchanged (inherent methods win over trait methods at the call
site, so this is not recursive).
impl Tokenizer for Gpt2Tokenizer
Delegates to the inherent methods, which stay public so existing callers compile unchanged (inherent methods win over trait methods at the call site, so this is not recursive).
fn encode(&self, text: &str) -> Result<Vec<u32>>
fn decode(&self, ids: &[u32]) -> String
Source§fn decode_bytes(&self, ids: &[u32]) -> Vec<u8> ⓘ
fn decode_bytes(&self, ids: &[u32]) -> Vec<u8> ⓘ
Raw byte-level decode. Must be append-only per token — i.e.
decode_bytes(a ++ b)
equals decode_bytes(a) ++ decode_bytes(b) — because the streaming path
emits only the valid-UTF-8 prefix of the accumulated bytes.fn vocab_size(&self) -> usize
Auto Trait Implementations§
impl !Freeze for Gpt2Tokenizer
impl RefUnwindSafe for Gpt2Tokenizer
impl Send for Gpt2Tokenizer
impl Sync for Gpt2Tokenizer
impl Unpin for Gpt2Tokenizer
impl UnsafeUnpin for Gpt2Tokenizer
impl UnwindSafe for Gpt2Tokenizer
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
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