pub struct Vocab {
pub kind: VocabKind,
pub model: String,
pub specials: Specials,
pub linefeed: Option<u32>,
pub add_space_prefix: bool,
pub add_bos: bool,
pub add_eos: bool,
pub ignore_merges: bool,
pub clean_spaces: bool,
pub escape_whitespaces: bool,
pub treat_whitespace_as_suffix: bool,
pub lowercase: bool,
/* private fields */
}Expand description
A loaded vocabulary and its tokenizer.
Fields§
§kind: VocabKind§model: String§specials: Specials§linefeed: Option<u32>§add_space_prefix: bool§add_bos: bool§add_eos: bool§ignore_merges: bool§clean_spaces: bool§escape_whitespaces: bool§treat_whitespace_as_suffix: bool§lowercase: boolImplementations§
Source§impl Vocab
impl Vocab
Sourcepub fn from_meta(
meta: &BTreeMap<String, MetaValue>,
) -> Result<Vocab, VocabError>
pub fn from_meta( meta: &BTreeMap<String, MetaValue>, ) -> Result<Vocab, VocabError>
Read the vocabulary a checkpoint’s metadata describes: its tokenizer.* keys, and the general.* keys whose
names llama.cpp keys token attributes by.
pub fn n_tokens(&self) -> usize
pub fn token(&self, id: u32) -> &TokenData
pub fn text_to_token(&self, text: &[u8]) -> Option<u32>
Sourcepub fn special_order(&self) -> &[u32]
pub fn special_order(&self) -> &[u32]
The special tokens in the order fragments are split on them.
Sourcepub fn byte_to_token(&self, b: u8) -> Result<u32, TokenizeError>
pub fn byte_to_token(&self, b: u8) -> Result<u32, TokenizeError>
byte_to_token: the token standing for one byte.
Sourcepub fn tokenize(
&self,
text: &[u8],
add_special: bool,
parse_special: bool,
) -> Result<Vec<u32>, TokenizeError>
pub fn tokenize( &self, text: &[u8], add_special: bool, parse_special: bool, ) -> Result<Vec<u32>, TokenizeError>
llama_tokenize: the token ids of text. add_special adds the vocabulary’s beginning- and end-of-sequence
tokens as it asks; parse_special lets control tokens written in the text match as themselves.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Vocab
impl RefUnwindSafe for Vocab
impl Send for Vocab
impl Sync for Vocab
impl Unpin for Vocab
impl UnsafeUnpin for Vocab
impl UnwindSafe for Vocab
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.