Wrapper for the llama_vocab structure
Constructors
new(handle :
Pointer(
LibLlama::LlamaVocab))
Creates a new Vocab instance from a raw pointer
Note: This constructor is intended for internal use.
Users should obtain Vocab instances through Model#vocab.
SourceInstance methods
add_bos?
Returns whether the model adds BOS token by default
Sourceadd_eos?
Returns whether the model adds EOS token by default
Sourceadd_sep?
Returns whether the model adds SEP token by default
Sourcebos
Returns the beginning-of-sentence token ID
SourceChecks if a token is a control token
SourceChecks if a token is an end-of-generation token
Sourceeos
Returns the end-of-sentence token ID
Sourceeot
Returns the end-of-turn token ID
SourceFormat a token for display
Parameters:
- token: The token to format
- show_id: Whether to show the token ID
- show_text: Whether to show the token text
Returns:
- A formatted string representation of the token
Sourcemask
Returns the mask token ID (if defined by the tokenizer)
Sourcen_tokens
Returns the number of tokens in the vocabulary
Sourcenl
Returns the newline token ID
Sourcepad
Returns the padding token ID
Sourceto_unsafe
Returns the raw pointer to the underlying llama_vocab structure
SourceConverts a token to a piece of text
This is similar to token_to_text but provides more control over the output format
Parameters:
- token: The token to convert
- lstrip: Whether to strip leading spaces (0 = no, 1 = yes)
- special: Whether to render special tokens
Returns:
- The text representation of the token
SourceReturns the text representation of a token
SourceTokenizes a string into an array of token IDs
Source