Class DeepSeekEngramTokenMap
java.lang.Object
smile.llm.model.deepseek.DeepSeekEngramTokenMap
Maps every token id to a "compressed" id, so that tokens which normalize alike (" The", "the", "THE") share one.
The engram n-gram hashes are computed over these ids, and every hash multiplier derives from the compressed
vocabulary size, so the partition must match the training one exactly (the released model has 99092 classes).
Each id is decoded alone (byte-level BPE, lossy UTF-8). A token that decodes to a replacement character is
keyed by its raw tokenizer.json string; otherwise by the text after NFKC, NFD, removal of all marks
(Mn, Mc and Me: removing only Mn gives 99510 classes), lower-casing, collapsing [ \t\r\n]+ to one space and
stripping whitespace (a lone space stays). Raw and normalized keys share one key space, as in the reference,
so a raw key can coincide with a normalized one.
-
Method Summary
-
Method Details
-
map
public int map(int token) Maps a token id to its compressed id.- Parameters:
token- the token id.- Returns:
- the compressed id.
-
table
public int[] table()The whole lookup table.- Returns:
- a copy of the table, indexed by token id.
-
size
public int size()Number of compressed ids.- Returns:
- the compressed vocabulary size.
-
load
Builds the map from atokenizer.json.- Parameters:
tokenizerJson- the file.vocabSize- number of ids to map (the model's vocabulary size); ids without a token map to ""'s class.- Returns:
- the map.
- Throws:
IOException- if the file cannot be read.
-