Repository navigation
Keep punctuation inside a word when splitting word timestamps - #2898
Open
nirajkhetre wants to merge 1 commit into
Open
nirajkhetre wants to merge 1 commit into
nirajkhetre wants to merge 1 commit into
Conversation
split_tokens_on_spaces started a new word at every punctuation token, so "3.5" came out as " 3" and ".5", and "$1,234.50", "10:30" and "example.com" were split the same way. In Korean, a closing quote moved onto the particle after it. merge_punctuations can't repair those pieces, so they reached word timestamps and word-level subtitles. Punctuation now only stands alone at the end of a space-delimited word, so merge_punctuations and --append_punctuations work on it as before.
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.
Addresses discussion #2875.
With
word_timestamps=True,split_tokens_on_spacesstarts a new word at every punctuation token, even in the middle of a space-delimited word.merge_punctuationsonly handles punctuation that stands alone, so it can't repair the pieces, and they reachsegments[].wordsand word-level subtitles.Punctuation now only stands alone at the end of a space-delimited word. After
merge_punctuationswith the default settings:$1,234.50$1,,234,.50$1,234.5010:3010,:3010:30example.com.example,.com.example.com.U.S.U,.S.U.S.and/orand,/orand/or"안녕"이라고"안녕,"이라고"안녕"이라고3.5%3,.5,%3.5,%Languages that use
split_tokens_on_unicode(Chinese, Japanese, Thai, Lao, Burmese, Cantonese) aren't affected.Why not remove the punctuation check entirely? The discussion suggests that, but
merge_punctuationsneeds trailing punctuation as a separate word, so--append_punctuationswould stop having any effect. With this change,append_punctuations=""still givesHello,,as it does today.One case for you to decide: a bare
%before a space stays separate (3.5,%, and4,%as before), because%isn't in the defaultappend_punctuations. Anyone can add it through that option. I left the default alone since it's a separate behaviour change, but I'm happy to add it here if you'd prefer.Testing
test_split_on_spaces_only_separates_trailing_punctuationintests/test_tokenizer.py: 3 of its 5 cases fail onmain. The other 2 pin behaviour that shouldn't change (Hello, world!,4% today.).pytest tests/test_transcribe.py -k tinypasses. Onjfk.flacwithtiny, the transcript and all 22 word timings are identical before and after.find_alignmentwithtinyon a forced sentence containing the cases above returns the merged words, with word times still in order. That audio doesn't contain those words, so this checks the code path, not timing accuracy.-m "not requires_cuda"on Windows 11, Python 3.12, torch 2.15 CPU. Therequires_cudatests can't run on this machine.