|
Mila
Deep Neural Network Library
|
Character-level tokenizer. More...
Public Member Functions | |
| CharTokenizer (CharVocabulary vocab) | |
| Construct a CharTokenizer with a vocabulary. | |
| std::string | decode (std::span< const TokenId > tokens) override |
| Decode token ids back to text. | |
| std::vector< TokenId > | encode (const std::string &text) override |
| Encode text into token ids (one id per input byte). | |
| std::optional< TokenId > | getBosTokenId () const override |
| BOS id query - not supported for char-level tokenizer. | |
| std::optional< TokenId > | getEosTokenId () const override |
| EOS id query - not supported for char-level tokenizer. | |
| std::optional< TokenId > | getPadTokenId () const override |
| PAD id query - not supported for char-level tokenizer. | |
| size_t | getVocabSize () const override |
| Number of tokens in the underlying vocabulary. | |
| bool | isValidToken (TokenId tokenId) const override |
| Check if token id is valid in the vocabulary. | |
| std::string | tokenToString (TokenId tokenId) const override |
| Convert a token id to a debug string. | |
Static Public Member Functions | |
| static CharTokenizer | load (const std::filesystem::path &path) |
Character-level tokenizer.
This tokenizer treats tokens as single bytes (single-character strings). It delegates all token <-> id mapping and persistence to a TokenizerVocabulary implementation.
Ownership:
Encoding/decoding semantics:
Note: This implementation does not add or interpret BOS/EOS tokens; encodeWithSpecial() ignores the addBos/addEos flags because the generic TokenizerVocabulary interface does not expose special-token ids.
|
inlineexplicit |
Construct a CharTokenizer with a vocabulary.
| vocab | Shared pointer to a TokenizerVocabulary implementation. Must remain valid for the lifetime of this tokenizer. |
|
inlineoverridevirtual |
Decode token ids back to text.
Each token id is converted to its token string via the vocabulary, and the first byte of that token is appended to the result. If an id is missing the character '?' is appended.
| tokens | Span of token ids to decode. |
Implements Mila::Data::Tokenizer.
|
inlineoverridevirtual |
Encode text into token ids (one id per input byte).
| text | UTF-8 encoded text to encode. Each input byte is treated as a separate token; callers should handle multi-byte characters if needed. |
Implements Mila::Data::Tokenizer.
|
inlineoverridevirtual |
BOS id query - not supported for char-level tokenizer.
Returns empty optional because the generic vocabulary does not expose special-token ids in the interface.
Implements Mila::Data::Tokenizer.
|
inlineoverridevirtual |
EOS id query - not supported for char-level tokenizer.
Implements Mila::Data::Tokenizer.
|
inlineoverridevirtual |
PAD id query - not supported for char-level tokenizer.
Implements Mila::Data::Tokenizer.
|
inlineoverridevirtual |
Number of tokens in the underlying vocabulary.
Implements Mila::Data::Tokenizer.
|
inlineoverridevirtual |
Check if token id is valid in the vocabulary.
Implements Mila::Data::Tokenizer.
|
inlineoverridevirtual |
Convert a token id to a debug string.
Returns the token string from the vocabulary or an empty string if not found.
Implements Mila::Data::Tokenizer.