Class MiniMaxTokenizer
java.lang.Object
smile.llm.tokenizer.Tiktoken
smile.llm.model.minimax.MiniMaxTokenizer
- All Implemented Interfaces:
Tokenizer
MiniMax-M3 tokenizer: NFC normalization, then byte-level BPE with the model's case-aware
split regex. Control tokens (
]~b] BOS, [e~[ EOS, ]!p~[ pad, ...)
are taken from tokenizer.json's added_tokens; only specials actually present
are registered so no id can fall outside the embedding table.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordOne entry ofadded_tokensintokenizer.json. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringBeginning-of-turn token.static final StringEnd-of-turn token.static final StringPadding token.Fields inherited from class Tiktoken
ranks, specialTokens -
Constructor Summary
ConstructorsConstructorDescriptionMiniMaxTokenizer(Map<Bytes, Integer> ranks) Constructor for a vocabulary whose added tokens are the built-in MiniMax set.MiniMaxTokenizer(Map<Bytes, Integer> ranks, List<MiniMaxTokenizer.AddedToken> added) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionint[]Encodes a string into a list of token IDs.int[]encodeWithSpecials(String text) Encodes template text in which markers such as]~b],[e~[and]<]minimax[>[stand for single special tokens, as the reference tokenizer does for text containing them.static MiniMaxTokenizerLoads the tokenizer from a checkpoint directory containingtokenizer.json.intpad()Padding token id.int[]Stop token ids used during generation.tryDecode(int[] tokens, boolean skipSpecial) Decodes tokens.Methods inherited from class Tiktoken
allowSpecialTokens, decode, encode, isSpecialTokenAllowed, load, size, specialToken, tokenize, tryDecode
-
Field Details
-
BOS
-
EOS
-
PAD
-
-
Constructor Details
-
MiniMaxTokenizer
Constructor for a vocabulary whose added tokens are the built-in MiniMax set.- Parameters:
ranks- token byte sequence to id map, including added tokens.- Throws:
IllegalArgumentException- if the BOS, EOS or pad token is missing.
-
MiniMaxTokenizer
Constructor.Every added token is atomic when encoding text, special or not (as in the reference tokenizer), which is what makes
<tool_call>and]<]minimax[>[single tokens. Tokens flagged special are hidden when decoding for display.- Parameters:
ranks- token byte sequence to id map, including added tokens.added- theadded_tokensoftokenizer.json.- Throws:
IllegalArgumentException- if the BOS, EOS or pad token is missing.
-
-
Method Details
-
of
Loads the tokenizer from a checkpoint directory containingtokenizer.json.- Parameters:
checkpointDir- model directory.- Returns:
- tokenizer.
- Throws:
IOException- iftokenizer.jsonis missing or malformed.
-
encode
Description copied from interface:TokenizerEncodes a string into a list of token IDs. -
encodeWithSpecials
Encodes template text in which markers such as]~b],[e~[and]<]minimax[>[stand for single special tokens, as the reference tokenizer does for text containing them.- Parameters:
text- a rendered chat prompt.- Returns:
- token ids.
-
tryDecode
Decodes tokens. WithskipSpecial, control tokens (]~b],[e~[, padding, ...) are dropped, the reasoning tags<mm:think>and</mm:think>are rendered as<think>and</think>(the form chat clients style as reasoning), and the tool-call marker]<]minimax[>[stays so tool calls can be parsed from the text.- Specified by:
tryDecodein interfaceTokenizer- Overrides:
tryDecodein classTiktoken- Parameters:
tokens- The list of token IDs to be decoded.skipSpecial- whentrue, registered special-token IDs are omitted (useful for streaming chat so headers/eot are not shown as literal<|...|>text).- Returns:
- The decoded string.
- Throws:
CharacterCodingException- If the byte sequence is not legal UTF-8.
-
pad
public int pad()Padding token id.- Returns:
- pad token id.
-
stopTokens
public int[] stopTokens()Stop token ids used during generation.- Returns:
- the end-of-turn token id.
-