fix(python): forward unk_id in SentencePieceUnigramTokenizer - #2393
Open
Con-Benksl wants to merge 1 commit into
Open
fix(python): forward unk_id in SentencePieceUnigramTokenizer#2393Con-Benksl wants to merge 1 commit into
Con-Benksl wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1576.
Even with
<unk>in a custom vocabulary,SentencePieceUnigramTokenizercannot encode unknown characters because its constructor does not expose the underlyingUnigrammodel'sunk_id. Add an optional trailing parameter and forward it to the existing model constructor, preserving the default behavior and positional arguments. Also passunk_idby keyword in the parity checker, where it was incorrectly bound toreplacement.Validation on Python 3.13.13 with the native extension built from this checkout:
PYTHONPATH=py_src HF_HUB_OFFLINE=1 HF_DATASETS_OFFLINE=1 python -m pytest -q tests/implementations/test_sentencepiece.py: 7 passed; before the fix, the two new cases failed and the five existing cases passed. The regression covers zero/nonzero IDs, default behavior, positional compatibility, and missing-vocabulary validation.unk_id=2and an unseen character in the input: all three encodings matched SentencePiece. The original call failed with aTypeError.make check-stylepassed; final ruff checks, formatting checks, and the repository's ty check also passed after excluding unrelated generated stub changes from the diff.No model files were downloaded. The full network-dependent test suite was not run.
AI assistance: OpenAI Codex implemented and tested this change; a separate Codex agent reviewed the diff.