Tokenizer test cases and reformatting of tokenizer training file#41
Merged
chandanms merged 14 commits intosimple-stories:devfrom Aug 15, 2025
Merged
Conversation
Collaborator
Author
|
Check only the last commit please. I had already started coding and didnt see the previous merge for #40 |
danbraunai
approved these changes
Aug 15, 2025
Collaborator
danbraunai
left a comment
There was a problem hiding this comment.
Nice. Minor comments below. I love the removal of COMMON_PREFIXES and COMMON_SUFFIXES. Best also to add that this is done to the README, because it differs to the paper (bottom of page 5 https://arxiv.org/pdf/2504.09184).
Can merge after addressing those.
tests/test_tokenizer.py
Outdated
| """Create a fresh tokenizer for testing.""" | ||
| train_data = ["hello world", "hello there", "world peace", "simple stories"] | ||
| train_iter = create_test_data_iterator(train_data) | ||
| return train_tokenizer(train_iter, vocab_size=200) |
Collaborator
There was a problem hiding this comment.
You should be able to just do return train_tokenizer(iter(train_iter), vocab_size=200 and remove the create_test_data_iterator function.
| pruned = prune_tokenizer(data_iter, tokenizer) | ||
| vocab_pruned = pruned.get_vocab() | ||
| assert "[UNK]" in vocab_pruned and "[EOS]" in vocab_pruned | ||
| assert vocab_pruned["[UNK]"] in [0, 1] and vocab_pruned["[EOS]"] in [0, 1] |
Collaborator
There was a problem hiding this comment.
Maybe assert that they're not both 0 or 1 too. (i.e. that they're not equal).
…ens; Made the data to tokenizer training iterable.
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.
Description
Added test cases for tokenizer to verify the functionality of test cases both after training and after pruning. Reformatted the tests to use
create_tokenizerfunction directly to make it more aligned with the creation script.Removed COMMON_PREFIXES and COMMON_SUFFIXES from initial_alphabet as empirical testing (trained with and without it) showed the WordPiece trainer naturally discovers these frequent morphemes during training, making explicit seeding redundant and causing unnecessary complexity. We should have validated this assumption earlier rather than adding potentially redundant configuration.
Related Issue
Sanity check on using special tokens correctly
Motivation and Context
The training and pruning tokenizer could potentially cause unwanted risk which would be deeply problematic if not discovered. Hence the thorough checking of edge cases and use of special tokens.
How Has This Been Tested?
Added tests to check the behaviour and reformatted the tests to test the functionality after training and after pruning.
Does this PR introduce a breaking change?
No