include/entropic/inference/tokenizer.h¶
include/entropic/inference/tokenizer.h
entropic::Tokenizer
Pure-virtual tokenizer surface used by the inference backend.
Derived by entropic::LlamaCppTokenizer.
virtual entropic::Tokenizer::~Tokenizer()=default
virtual std::vector< int32_t > entropic::Tokenizer::tokenize(const std::string &text, bool add_special) const =0
Encode text to token IDs.
- Parameters
text— UTF-8 input.add_special— Insert model-specific BOS/EOS specials when true.
- Returns
- Token IDs (empty on failure or empty input).
virtual std::string entropic::Tokenizer::detokenize(int32_t token) const =0
Decode a single token to its surface piece.
- Parameters
token— Token ID.
- Returns
- Surface string ("" for special tokens that don't render).
virtual int entropic::Tokenizer::count_tokens(const std::string &text) const
Count tokens in text without retaining the IDs.
Default implementation invokes tokenize() and returns size(). Overrides may use a faster path (e.g., model size-prediction without actual allocation).
- Parameters
text— UTF-8 input.
- Returns
- Token count (>= 0). Returns 0 on empty input.