Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add lexicographic ordering for breaking ties to make the tokenizer deterministic #90

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dapopov-st
Copy link

I could be wrong, but I think it lexicographic tie breaking is currently not implemented. For example, running the following will yield different results:
custom_text = 'bbbaaaddddcccc'
extra_tokens = 4
tokenizer = RegexTokenizerAK(pattern=GPT2_SPLIT_PATTERN)
tokenizer.train(custom_text,vocab_size=256+extra_tokens,verbose=True)
assert tokenizer.decode(tokenizer.encode(custom_text))==custom_text, 'enc/dec mismatch'
Yields
merge 1/4: (100, 100) -> 256 (b'dd') had 3 occurrences
merge 2/4: (99, 99) -> 257 (b'cc') had 3 occurrences
merge 3/4: (98, 98) -> 258 (b'bb') had 2 occurrences
merge 4/4: (97, 97) -> 259 (b'aa') had 2 occurrences

Whereas
custom_text = 'aaabbbccccdddd'
extra_tokens = 4
tokenizer = RegexTokenizerAK(pattern=GPT2_SPLIT_PATTERN)
tokenizer.train(custom_text,vocab_size=256+extra_tokens,verbose=True)
assert tokenizer.decode(tokenizer.encode(custom_text))==custom_text, 'enc/dec mismatch'
Yields
merge 1/4: (99, 99) -> 256 (b'cc') had 3 occurrences
merge 2/4: (100, 100) -> 257 (b'dd') had 3 occurrences
merge 3/4: (97, 97) -> 258 (b'aa') had 2 occurrences
merge 4/4: (98, 98) -> 259 (b'bb') had 2 occurrences

With the suggested tie breaking, both yield the same result
merge 1/4: (99, 99) -> 256 (b'cc') had 3 occurrences
merge 2/4: (100, 100) -> 257 (b'dd') had 3 occurrences
merge 3/4: (97, 97) -> 258 (b'aa') had 2 occurrences
merge 4/4: (98, 98) -> 259 (b'bb') had 2 occurrences

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant