Unified BPE tokenizer targeting GPT-2, Llama 3.x, and Mistral model families.
More...
|
|
| BpeTokenizer (BpeVocabulary vocab) |
| std::string | decode (std::span< const TokenId > tokens) override |
| | Decode a sequence of token IDs back to a UTF-8 string.
|
| std::vector< TokenId > | encode (const std::string &text) override |
| | Encode text to a sequence of token IDs.
|
| std::optional< TokenId > | getBosTokenId () const override |
| std::optional< TokenId > | getEosTokenId () const override |
| std::optional< TokenId > | getPadTokenId () const override |
|
const BpeVocabulary & | getVocab () const |
| size_t | getVocabSize () const override |
| bool | isValidToken (TokenId tokenId) const override |
| std::string | tokenToString (TokenId tokenId) const override |
|
| static BpeTokenizer | load (const std::filesystem::path &path) |
| | Load a tokenizer from a Mila binary vocabulary file.
|
| static std::shared_ptr< BpeTokenizer > | loadGemma (const std::filesystem::path &path) |
| | Load a Gemma 4 tokenizer from the binary produced by convert_tokenizer.py.
|
| static std::shared_ptr< BpeTokenizer > | loadGpt2 (const std::filesystem::path &path) |
| | Load a GPT-2 tokenizer from the binary produced by convert_gpt2_tokenizer.py.
|
| static std::shared_ptr< BpeTokenizer > | loadLlama32 (const std::filesystem::path &path) |
| | Load a Llama 3.2 tokenizer from the binary produced by convert_llama_tokenizer.py.
|
| static std::shared_ptr< BpeTokenizer > | loadMistral (const std::filesystem::path &vocab_path, const std::filesystem::path &merges_path) |
| | Load a Mistral tokenizer.
|
Unified BPE tokenizer targeting GPT-2, Llama 3.x, and Mistral model families.
Construct from a pre-built vocabulary or via the convenience factory methods:
auto ids = tok->encode( "Hello, world!" );
auto ids = tok->encode( "<|begin_of_text|>Hello, world!" );
static std::shared_ptr< BpeTokenizer > loadGpt2(const std::filesystem::path &path)
Load a GPT-2 tokenizer from the binary produced by convert_gpt2_tokenizer.py.
Definition BpeTokenizer.ixx:106
static std::shared_ptr< BpeTokenizer > loadLlama32(const std::filesystem::path &path)
Load a Llama 3.2 tokenizer from the binary produced by convert_llama_tokenizer.py.
Definition BpeTokenizer.ixx:118
The special token pre-pass is enabled whenever the vocabulary registers at least one special token. For GPT-2, this means "<|endoftext|>" is intercepted before BPE runs; for Llama 3.x, the full set of named and extended tokens is intercepted.