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.
Collaborator
|
感谢这个边界清楚的修复。我复核了 exact head 独立验证结果:
目前没有新的静态代码修改要求。验证范围仍需准确限定为纯 CPU 文件级后处理:没有加载真实 Paraformer 权重,也没有执行 ONNX 引擎或 libtorch runtime。 当前阻塞是 exact-head CI,而不是独立 approval:该 head 仍为 0 个 check runs、0 个 commit statuses、 另外,#3801 报告的是 VAD 中文 chunk 拼接时文本 unit 融合导致的累计漂移,和本 PR 的“过滤 |
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>.