fix: crash on inputs containing runs of 4 spaces#8
Merged
Conversation
- MarkdownProcessor, LaTeXProcessor, PlainTextProcessor: drop the
"\t": " " * self.spaces entry from _get_replace_tokens.
- MarkdownProcessor.parse_text: add an explicit
text.replace("\t", " " * self.spaces). The other two processors
already did this substitution explicitly.
- BaseProcessor: drop the now-dead "if k != '\t'" filter from
reverse_replace_tokens.
Owner
|
Thanks, merged. I have not tested it though, hope it fixes the bug and doesn't have regressions. I hope to plan to add tests later... |
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: #7
The processors register their replace_tokens values with the tokenizer via tokenizer.add_tokens(). The 4-space string used for the "\t" -> spaces substitution seems like it has no row in the sembr2023 model's embedding matrix. This means any input with four or more consecutive spaces therefore produces an out-of-range token ID and crashes with:
Reproducer:
The fix in this PR is to not register the 4-space string with the tokenizer. Since its registration was a result of being a value in replace_tokens, I removed it from the dict and handle the tab-to-spaces substitution separately:
"\t": " " * self.spacesentry from _get_replace_tokens.