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

[ML] Fix deberta tokenizer bug caused by bug in normalizer #117189

Merged
merged 4 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/117189.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 117189
summary: Fix deberta tokenizer bug caused by bug in normalizer
area: Machine Learning
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ Reader normalize(CharSequence str) {
if (charDelta < 0) {
// normalised form is shorter
int lastDiff = getLastCumulativeDiff();
addOffCorrectMap(normalizedCharPos, lastDiff + charDelta);
addOffCorrectMap(normalizedCharPos, lastDiff - charDelta);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subtle, nice find! Can we add any tests here as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I added a test which I confirmed fails prior to this fix, and works with this fix.

} else if (charDelta > 0) {
// inserted chars, add the offset in the output stream
int lastDiff = getLastCumulativeDiff();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ public void testTokenize() throws IOException {
}
}

public void testTokenizeWithHiddenControlCharacters() throws IOException {
try (
DebertaV2Tokenizer tokenizer = DebertaV2Tokenizer.builder(
TEST_CASE_VOCAB,
TEST_CASE_SCORES,
new DebertaV2Tokenization(false, false, null, Tokenization.Truncate.NONE, -1)
).build()
) {
TokenizationResult.Tokens tokenization = tokenizer.tokenize("\u009F\u008Fz", Tokenization.Truncate.NONE, -1, 0, null).get(0);
assertThat(tokenStrings(tokenization.tokens().get(0)), contains("▁", "z"));

}
}

public void testSurrogatePair() throws IOException {
try (
DebertaV2Tokenizer tokenizer = DebertaV2Tokenizer.builder(
Expand Down
Loading