Skip to main content

GgufWordPieceTokenizer

Struct GgufWordPieceTokenizer 

Source
pub struct GgufWordPieceTokenizer { /* private fields */ }
Expand description

A real WordPiece tokenizer built from a GGUF file’s own tokenizer.ggml.tokens metadata array.

See the module docs for the algorithm and for why the vocabulary looks the way it does. Checked against llama.cpp on the same GGUF by crates/ferrox-models/tests/wordpiece_parity.rs.

Implementations§

Source§

impl GgufWordPieceTokenizer

Source

pub fn from_gguf(file: &impl TensorSource) -> Result<Self, TokenizerLoadError>

Source

pub fn vocab_size(&self) -> usize

Source

pub fn normalizer(&self) -> NormalizerOptions

Source

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

Encodes text, with no [CLS]/[SEP] added.

Upstream’s add_special wraps the result in BOS and SEP; that decision lives with super::should_add_bos_token and super::prepend_bos for every tokenizer in this crate, and baking it in here would double it for callers that already do it.

Source

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

The text a token id stands for.

Reverses the converter’s phantom space, so ▁hello decodes to " hello" and the continuation ing decodes to "ing". Concatenating a sequence therefore reproduces the normalized text with a leading space, which is what llama.cpp’s llama_unescape_whitespace produces before its clean_spaces pass trims the first one.

A WordPiece round trip is lossy no matter what this does: the normalizer lowercased, stripped accents and dropped controls before any of these ids existed. Round-tripping is therefore NOT evidence that this tokenizer is right, which is why the tests that matter compare ids against llama.cpp instead.

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<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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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.