Repository navigation
hftokenizer: apply GPT-2 ByteLevel regex when use_regex is true (#94) - #95
Merged
Merged
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 #94
Summary
byteLevelPreTokenizeWithOffsets(tokenizers/hftokenizer/pretokenizer.go) to split input using HuggingFace's GPT-2ByteLevelregex ('s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+) before byte remapping wheneveruse_regexistrue(or omitted), while keeping the no-split path (byteLevelEncodeNoSplit) unchanged whenuse_regexisfalse.tokenizers(onig/fancy-regex):\sto full UnicodeWhite_Space([\t\n\x0b\f\r \x{85}\p{Z}]) so characters such as\u00a0,\x0b,\u0085,\u2028, and\u3000match whitespace rather than punctuation.\s+(?!\S)via a named capturing group that trims the trailing whitespace rune when at least two whitespace runes precede a non-whitespace rune.tokenizers/hftokenizer/pretokenizer_test.go:TestByteLevelUseRegexcovering the issue hftokenizer: ByteLevel with use_regex splits only at spaces, not at the GPT-2 regex boundaries #94 reproduction ("a1"withuse_regex: truevsfalse).TestByteLevelGPT2RegexParityverifying 29 cases (letter/number, punctuation, contractions, multi-space/CRLF/tab lookahead, CJK, Unicode whitespace) against HuggingFacetokenizers0.22.2 outputs and byte spans.docs/CHANGELOG.md.Testing
go test -short ./...passes across all packages.go test ./modeltests/ -modeltests -cached_only -v -run "TestModels/.*/.*/tokenize"passes across all cached models.