Skip to content

fix(auto): preserve Paraformer token alignment across VAD segments - #3793

Closed
phoenixray2000 wants to merge 1 commit into
modelscope:mainfrom
phoenixray2000:codex-fix-paraformer-token-alignment
Closed

phoenixray2000 wants to merge 1 commit into
modelscope:mainfrom
phoenixray2000:codex-fix-paraformer-token-alignment

Conversation

@phoenixray2000

Copy link
Copy Markdown
Contributor

Summary

Paraformer returns space-delimited ASR tokens with matching timestamps. When adjacent Chinese VAD chunks are joined for punctuation, their boundary separator is removed: 客 户 + 需 求 becomes 客 户需 求. Sentence segmentation then pairs three text units with four unchanged timestamps and punctuation labels. On long recordings this shifts words into earlier sentence timestamps and speaker turns, and can leave punctuation-only sentences at the end.

Use the original ASR token text as the default input to timestamp segmentation. Keep the existing cleaned punctuation input and explicit words alignment paths for SenseVoice and other surface-text backends. The regression exercises both sentence timestamps and speaker punctuation segmentation, checking text, raw token text, timestamp intervals, and speaker labels.

Type of change

  • Bug fix
  • Documentation
  • Example or demo
  • Runtime or deployment
  • Benchmark or evaluation
  • Model/training change

Validation

  • python -m compileall -q funasr examples tests
  • Both new regression subcases fail before the fix and pass afterward.
  • python -m pytest -q tests/test_punc_model_none.py tests/test_timestamp_tools.py tests/test_sensevoice_word_timestamps.py: 41 passed, 10 subtests passed, including the existing SenseVoice tag, word-alignment, English surface-text, and malformed-metadata cases.
  • Extended local suite covering the upstream NumPy CI selection plus submodel devices, clustering, Paraformer timestamp contracts, and WER helpers: 247 passed, 22 subtests passed, 1 deselected.
  • Black 24.4.0 with the repository's 100-character line length on the added test range; git diff --check.
  • Offline full-recording replay on Windows, Python 3.13.1, PyTorch 2.6.0+cu124, RTX 4070 SUPER: the same 616-second, 16 kHz mono Chinese recording, cached models, VAD settings, and hotwords. All 306 sentence texts and intervals match the pre-regression baseline; punctuation-only sentences fall from 27 to 0. Raw recognition text, token timestamps, and speaker cluster labels remain unchanged.
  • Docs/links and service deployment checks: not applicable to this Python alignment fix.

User impact

Restores the correspondence between recognized tokens, sentence timestamps, and speaker turns in multi-segment Paraformer transcription. Recognition accuracy and automatic speaker-count estimation remain unchanged.

Notes for reviewers

The local Windows run deselects TestLoadAudioBytes::test_decodes_no_id3_mp3_consistently_with_file_path: its still-open NamedTemporaryFile cannot be reopened by the audio decoder on Windows (Permission denied). The same failure was reproduced in a clean checkout of upstream fbbfe018; the test remains selected by the upstream Linux workflow. Optional CI dependencies were installed in a separate test environment, leaving the production environment intact.

The real recording is private. The checked-in reproduction is synthetic and requires no model weights. This PR contains only the alignment change and its regression test.

@LauraGPT

Copy link
Copy Markdown
Collaborator

Thank you @phoenixray2000 for the VAD-boundary investigation and focused regression.

This overlaps the fix now integrated by #3804 and shipped in v1.4.18. I ran your exact regression from ecaf729fe45346c3c1ad4746a9dae4a7e2475aa7 against main fb595cd6dba9146e3ec3481fe130024d53fa98d6: test_sentence_timestamps_preserve_token_boundaries_across_vad_segments passes, including both speaker-enabled and speaker-disabled subcases. This was one selected test with 17 others deselected, not a rerun of your private 616-second recording.

The current implementation retains VAD boundary spaces for timestamp units, removes rich tags only for alignment, and preserves the top-level punctuation result. The existing main regressions also cover reordered segments, Chinese/mixed/English boundaries and speaker assignment. The AutoModel file is unchanged since that accepted test in the current integration tip.

Closing this PR as superseded to avoid applying the same production change twice. Your branch and original commit are untouched; this closure does not claim that commit was merged or that your private recording was independently reproduced. Thank you for the earlier contribution. Original-recording feedback on #3801 remains open.

@LauraGPT LauraGPT closed this Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants