-
Notifications
You must be signed in to change notification settings - Fork 570
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
Fixing Whisper Model Token Normalization #1904
Merged
csukuangfj
merged 3 commits into
k2-fsa:master
from
iprovalo:feature/whisper_token_array_normalization
Feb 21, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,4 +55,77 @@ TEST(RemoveInvalidUtf8Sequences, Case1) { | |
EXPECT_EQ(s.size() + 4, v.size()); | ||
} | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a few tests, verified the characters are being removed correctly. |
||
// Tests for sanitizeUtf8 | ||
TEST(RemoveInvalidUtf8Sequences, ValidUtf8StringPassesUnchanged) { | ||
std::string input = "Valid UTF-8 🌍"; | ||
EXPECT_EQ(RemoveInvalidUtf8Sequences(input), input); | ||
} | ||
|
||
TEST(RemoveInvalidUtf8Sequences, SingleInvalidByteReplaced) { | ||
std::string input = "Invalid \xFF UTF-8"; | ||
std::string expected = "Invalid UTF-8"; | ||
EXPECT_EQ(RemoveInvalidUtf8Sequences(input), expected); | ||
} | ||
|
||
TEST(RemoveInvalidUtf8Sequences, TruncatedUtf8SequenceReplaced) { | ||
std::string input = "Broken \xE2\x82"; // Incomplete UTF-8 sequence | ||
std::string expected = "Broken "; | ||
EXPECT_EQ(RemoveInvalidUtf8Sequences(input), expected); | ||
} | ||
|
||
TEST(RemoveInvalidUtf8Sequences, MultipleInvalidBytes) { | ||
std::string input = "Test \xC0\xC0\xF8\xA0"; // Multiple invalid sequences | ||
std::string expected = "Test "; | ||
EXPECT_EQ(RemoveInvalidUtf8Sequences(input), expected); | ||
} | ||
|
||
TEST(RemoveInvalidUtf8Sequences, BreakingCase_SpaceFollowedByInvalidByte) { | ||
std::string input = "\x20\xC4"; // Space followed by an invalid byte | ||
std::string expected = " "; // 0xC4 removed | ||
EXPECT_EQ(RemoveInvalidUtf8Sequences(input), expected); | ||
} | ||
|
||
TEST(RemoveInvalidUtf8Sequences, ValidUtf8WithEdgeCaseCharacters) { | ||
std::string input = "Edge 🏆💯"; | ||
EXPECT_EQ(RemoveInvalidUtf8Sequences(input), input); | ||
} | ||
|
||
TEST(RemoveInvalidUtf8Sequences, MixedValidAndInvalidBytes) { | ||
std::string input = "Mix \xE2\x82\xAC \xF0\x9F\x98\x81 \xFF"; | ||
std::string expected = "Mix € 😁 "; // Invalid bytes removed | ||
EXPECT_EQ(RemoveInvalidUtf8Sequences(input), expected); | ||
} | ||
|
||
TEST(RemoveInvalidUtf8Sequences, SpaceFollowedByInvalidByte) { | ||
std::string input = "\x20\xC4"; // Space (0x20) followed by invalid (0xC4) | ||
std::string expected = " "; // Space remains, 0xC4 is removed | ||
EXPECT_EQ(RemoveInvalidUtf8Sequences(input), expected); | ||
} | ||
|
||
TEST(RemoveInvalidUtf8Sequences, RemoveTruncatedC4) { | ||
std::string input = "Hello \xc4 world"; // Invalid `0xC4` | ||
std::string expected = "Hello world"; // `0xC4` should be removed | ||
EXPECT_EQ(RemoveInvalidUtf8Sequences(input), expected); | ||
} | ||
|
||
TEST(RemoveInvalidUtf8Sequences, SpaceFollowedByInvalidByte_Breaking) { | ||
std::string input = "\x20\xc4"; // Space followed by invalid `0xc4` | ||
std::string expected = " "; // `0xc4` should be removed, space remains | ||
EXPECT_EQ(RemoveInvalidUtf8Sequences(input), expected); | ||
} | ||
|
||
TEST(RemoveInvalidUtf8Sequences, DebugSpaceFollowedByInvalidByte) { | ||
std::string input = "\x20\xc4"; // Space followed by invalid `0xc4` | ||
std::string output = RemoveInvalidUtf8Sequences(input); | ||
|
||
std::cout << "Processed string: "; | ||
for (unsigned char c : output) { | ||
printf("\\x%02x ", c); | ||
} | ||
std::cout << std::endl; | ||
|
||
EXPECT_EQ(output, " "); // Expect `0xc4` to be removed, leaving only space | ||
} | ||
|
||
} // namespace sherpa_onnx |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to Convert()