← Back to Pull requests

Keep spaces between English words in Paraformer transcripts #890

Open
Shizoqua opened this pull request with 38 lines diff across 2 files
View on GitHub
Shizoqua Shizoqua commented on Nov 27, 2026 12:25 UTC
Author

Fixes #887

What was wrong

ParaformerSTTHandler.process in src/speech_to_speech/STT/paraformer_handler.py called .replace(" ", "") on the transcript. FunASR keeps the spaces between English words on both of its output paths, so paraformer-en output "hello world how are you" became "helloworldhowareyou".

Fix

Keep a space only between two Latin or digit words and drop the rest. FunASR's timestamp path joins every token with a space (我 有 3 个) while its plain path does not (我有3个), so Chinese text, digits and full-width punctuation now come out the same on both paths. Warmup uses the same helper.

Tests

test_paraformer_keeps_spaces_only_between_latin_or_digit_words in tests/test_paraformer_transcription_events.py feeds a stub model FunASR-style output for Chinese, English, mixed speech, digits and full-width punctuation. The English, mixed, digit and punctuation cases fail on main ('helloworldhowareyou' == 'hello world how are you') and all pass now. The existing Chinese tests are unchanged and still pass.

uv run pytest tests/test_paraformer_transcription_events.py -q
15 passed

uv run pytest tests/ -q
4189 passed, 13 skipped

uv run ruff check src/ tests/, uv run ruff format --check src/ tests/ and uv run mypy src/ pass.

I did not run Big Bench Audio. Its default stack uses Parakeet for STT, so it would not exercise Paraformer, and running it with Paraformer needs the FunASR models. The change only touches the text the handler returns.

Diff: 38 lines (+36 / -2) across 2 files Reviewer: 1AbdullahButt Review duration: 9515m
All Vouch review confidence checks passed
Residual risk 0.03 = Change Risk (0.26) × (1 − Review Confidence (0.89)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.26 · 38 lines diff across 2 files
0.26
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.89 · 1 substantive comment(s)
0.89
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
89%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.219
Real PR Conversation Timeline
3 items
1AbdullahButt 1AbdullahButt commented on Nov 27, 2026 16:48 UTC
Reviewer

The English fix is right, but the regex only covers Han-Han pairs, so digits and punctuation in Chinese output pick up stray spaces. I ran tests/test_paraformer_transcription_events.py on the PR head in Docker: 12 passed. I then fed token lists through FunASR 1.4.29's own sentence_postprocess. Without timestamps it already returns 我喜欢python编程 and hello world, so it only joins tokens with spaces on the timestamp path (" ".join(real_word_lists)). On that path, the regex at src/speech_to_speech/STT/paraformer_handler.py:22 turns 我 有 3 个 into 我有 3 个 and 今 天 , 好 。 into 今天 , 好 。. The old .replace(" ", "") produced 我有3个 and 今天,好。, so any digit or full-width punctuation token the model emits now keeps its spaces.

Suggestions:

  • Invert the rule: drop whitespace unless it sits between two Latin/digit words, e.g. (?<![A-Za-z0-9'])\s+|\s+(?![A-Za-z0-9']). That gives the same output as FunASR's non-timestamp path, so the transcript doesn't depend on which path the model took.

  • Add a digit case and a ,/。 case to the parametrize at tests/test_paraformer_transcription_events.py:135.

  • Optional: paraformer_handler.py:62 (warmup) still uses .replace(" ", ""). The result is discarded, but sharing one helper would keep the two in sync.
  • Shizoqua Shizoqua commented on Nov 27, 2026 17:10 UTC
    Author

    Thanks, you're right. I'd missed that only the timestamp path adds the spaces. Pushed 22fbf5a with your rule (keep spaces only between Latin/digit words), added the digit and punctuation cases, and the warmup now uses the same helper.

    Reviewers
    Assignees
    Shizoqua Shizoqua
    Labels
    risk: low confidence: 89.1% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 26.4% (LOW) · Higher = larger blast radius
    26.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 89.1% · Lower = rushed or shallow review
    89.1%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 2.9% · Safe to merge
    2.9%