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
impl GgufWordPieceTokenizer
pub fn from_gguf(file: &impl TensorSource) -> Result<Self, TokenizerLoadError>
pub fn vocab_size(&self) -> usize
pub fn normalizer(&self) -> NormalizerOptions
Sourcepub fn encode(&self, text: &str) -> Vec<u32>
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.
Sourcepub fn decode(&self, ids: &[u32]) -> String
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§
impl Freeze for GgufWordPieceTokenizer
impl RefUnwindSafe for GgufWordPieceTokenizer
impl Send for GgufWordPieceTokenizer
impl Sync for GgufWordPieceTokenizer
impl Unpin for GgufWordPieceTokenizer
impl UnsafeUnpin for GgufWordPieceTokenizer
impl UnwindSafe for GgufWordPieceTokenizer
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> 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