Skip to main content

Gpt2Tokenizer

Struct Gpt2Tokenizer 

Source
pub struct Gpt2Tokenizer { /* private fields */ }

Implementations§

Source§

impl Gpt2Tokenizer

Source

pub fn from_files( vocab_path: impl AsRef<Path>, merges_path: impl AsRef<Path>, ) -> Result<Self>

Source

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.

Source

pub fn from_dir(dir: impl AsRef<Path>) -> Result<Self>

Load vocab.json + merges.txt from a directory.

Source

pub fn encode(&self, text: &str) -> Result<Vec<u32>>

Source

pub fn decode(&self, ids: &[u32]) -> String

Source

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.

Source

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).

Source§

fn encode(&self, text: &str) -> Result<Vec<u32>>

Source§

fn decode(&self, ids: &[u32]) -> String

Source§

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.
Source§

fn vocab_size(&self) -> usize

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,