Repository navigation
hftokenizer: pick the best-scoring Unigram split with Viterbi - #84
Conversation
Matches Hugging Face tokenizers: piece scores, unk penalty with fused unknowns, byte fallback. Parity test against onnx-community/gliner_multi-v2.1 ids from internal/py/unigram_parity.py.
|
Thank you so much for finding/fixing this issue 🙏🏻 , I was not aware of it.
Now the AI also had some comments about the code itself, for your consideration: |
|
Here are a few suggestions and edge cases noticed while reviewing the PR: Correctness & edge cases
Performance
Test coverage
|
model.unk_id wins over added [UNK]/<unk>; min score is NaN-safe; Viterbi steps by rune. Adds NewFromGGUF Unigram, unk_id and fused byte-fallback span tests.
|
Thanks for the review! Pushed 6d796c1 addressing items 1–4 and 6:
I left item 5 for later, as suggested. One thing I noticed while adding the span test: for |
|
Thank you for the clean up @daescha 🙏🏻 And the PR for the problem you mentioned about the replacement breaking the spans would be most welcome!!! |
Unigram tokenization picks the split with the best total piece score (Viterbi), as HuggingFace
tokenizersdoes. Greedy longest-match gives different ids for SentencePiece vocabularies such as deberta-v3:Munichencodes as▁Munic+hinstead of▁+Munich, which breaks parity with models trained on HuggingFace ids (e.g. GLiNER).min_score - 10, consecutive unknowns fuse into one token, andbyte_fallbackemits<0xXX>tokens, following the Rust implementation.ModelgainsScoresandUnkID; GGUF Unigram tokenizers passtokenizer.ggml.scoresthrough (equal scores when absent, so fewest pieces win).unigram_test.gochecks ids generated byinternal/py/unigram_parity.pyfor English, German, French, Russian, Japanese and emoji text. A network parity test againstonnx-community/gliner_multi-v2.1runs without-short.Open points for review: