Handle multibyte characters correctly in process (fixes #31)#35
Open
Handle multibyte characters correctly in process (fixes #31)#35
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.
Summary
This PR addresses issue #31 by checking raw bytes to prevent failures caused by multibyte (3-byte) characters.
Background
In some cases, text containing 3-byte characters (e.g., Japanese) could be processed incorrectly and lead to an “index out of range” error.
These cases tend to include two consecutive illegal bytes, and 3-byte characters can easily trigger this situation.
Commit 1
hide_incomplete_unicodenow usesself.model.tokenizer.encoding.decode_bytes_batchinstead ofself.model.tokenizer.split_tokens_on_unicode. Token decoding still occurs once per iteration.�) check now runs per token, and all detected tokens are buffered.Commit 2
After Commit 1, I observed an increased frequency of
pop from empty list: frames.pop(0)exceptions.I found that
timestamped_textadds frames depending on the length ofself.unicode_buffer. Previously, the untranslated part ofgeneration[result][frames]often compensated for this, but the increased buffer size made the behavior unstable. This commit adds an additional fix:frame_bufferto record the length ofunicode_bufferand pad/fill frames accordingly.Commit 3
iteration_outputsometimes contains onlyis_finalandemission_time, which caused aKeyError.Example:
{"is_final": false, "emission_time": 57.90499949455261}iteration_outputhas at least thestartkey before accessing it.Result
With these fixes applied, SimulStreaming worked without issues during a 10-hour field test in a Japanese environment.
References
P.S.
This is my first time using the “git” side of GitHub. If I made any mistakes in the PR, I’d appreciate any guidance.