Repository navigation
fix(postprocess): keep word timestamps aligned after filtered tokens - #3802
Open
ANDROIDHASSAN wants to merge 1 commit into
Open
ANDROIDHASSAN wants to merge 1 commit into
ANDROIDHASSAN wants to merge 1 commit into
Conversation
sentence_postprocess drops <s>, </s>, <unk> and <OOV> from the tokens but then indexed time_stamp by the washed position. time_stamp has one entry per token, so every word after a filtered token took the previous token's time. Keep the entries of the surviving tokens. A list too short to cover them stays as it was, because the branches below index it directly.
This branch has not been deployed
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
sentence_postprocessremoves<s>,</s>,<unk>and<OOV>from the tokens, then readstime_stampby the position in the cleaned list.ts_prediction_lfr6_standardandtime_stamp_lfr6_onnxgive one timestamp per token, including<unk>, so every word after a filtered token gets the previous token's time. The last word's real end is lost as well.Paraformer only strips eos, sos and blank from
token_int, so<unk>reaches this function. Tokens今 <unk> 天 好throughts_prediction_lfr6_standard,sentence_postprocessandtimestamp_sentence:The fix keeps the timestamps of the tokens that survive the cleaning loop, in the three copies of the function (
funasr,funasr_onnx,funasr_torch). If the list is too short to cover those tokens, it is left as it was before this change, because the branches below index it directly and would raiseIndexError.tests/test_sentence_postprocess_timestamps.pyloads all three files by path, so it needs no model or torch. I added it totest-text-postprocessing.yml, which lists its tests by name and would otherwise skip it.Type of change
Validation
python -m compileall funasr examples testsWith pytest 8.1.1, pypinyin 0.55.0 and rapidfuzz 3.14.5, the versions the workflow pins:
mainsource: 3 failed, 2 passed. The Chinese, English and mixed cases fail, for example[[0, 100], [100, 200], [200, 300]] != [[0, 100], [200, 300], [300, 400]]. The other two are guards that pass before and after: a trailing</s>without a timestamp, and too few timestamps.tests/test_postprocess_hotwords.py tests/test_rich_transcription_postprocess.py tests/test_sentence_postprocess_timestamps.pygives 27 passed.tests/test_paraformer_timestamp_contract.py tests/test_paraformer_timestamp_padding.pyplus the new file gives 13 passed.These are unit tests plus the function chain above with synthetic CIF peaks. I did not run a real Paraformer model or the ONNX/libtorch runtime.
User impact
Anyone using Paraformer, BiCif Paraformer, SeACo Paraformer, E-Paraformer, the monotonic aligner, or the ONNX and libtorch runtimes gets correct word and sentence times when the output contains
<unk>.Notes for reviewers
elseappends a word with no timestamp, which shifts later words the same way (["你", "g5", "好", "吗"]). The runtime copies raiseValueErrorthere. The runtime wash lists also lack<OOV>.