Interface Tokenizer
- All Known Implementing Classes:
QwenTokenizer
public interface Tokenizer
Local tokenizer contract (3.0 home of the 2.x
tokenizers leaf). Failures are unchecked:
NoSpecialTokenException / UnsupportedSpecialTokenModeException.-
Method Summary
-
Method Details
-
encodeOrdinary
Encoding that ignores any special tokens. There is no guarantee that the results will be completely consistent with the model output. Compared with the python version, there are some differences. It is known that the results of processing 2 or 4 consecutive spaces are different. Detailed information for qwen reference: https://github.com/QwenLM/Qwen/blob/main/tokenization_note_zh.md- Parameters:
text- The input.- Returns:
- The list of token ids.
-
encode
Encode the input text, handles special tokens. Same accuracy caveats asencodeOrdinary(String).- Parameters:
text- The input to be encoded.allowedSpecial- The special token options, one of "all"|"none"|"none_raise"; with "none_raise" aNoSpecialTokenExceptionis thrown when no special token is present; null means "all".- Returns:
- The list of token ids.
- Throws:
NoSpecialTokenException- No special token in the input (none_raise mode).UnsupportedSpecialTokenModeException- allowedSpecial is not all/none/none_raise.
-
decode
Decode token ids to String.- Parameters:
ids- The input token ids, eg: [2610, 525, 264, 10950, 17847, 13], will be decoded to "You are a helpful assistant."- Returns:
- The token ids corresponding string.
-