Skip to content

Fix streaming paraformer feature frontend drift from its training config - #3821

Merged
csukuangfj merged 1 commit into
k2-fsa:masterfrom
slipstr34m:fix/online-paraformer-feat-config
Jul 29, 2026
Merged

csukuangfj merged 1 commit into
k2-fsa:masterfrom
slipstr34m:fix/online-paraformer-feat-config

Conversation

@slipstr34m

@slipstr34m slipstr34m commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The offline paraformer configures the feature frontend the model was trained with (offline-recognizer-paraformer-impl.h:210-217):

void InitFeatConfig() {
  // Paraformer models assume input samples are in the range
  // [-32768, 32767], so we set normalize_samples to false
  config_.feat_config.normalize_samples = false;
  config_.feat_config.window_type = "hamming";
  config_.feat_config.high_freq = 0;
  config_.feat_config.snip_edges = true;
}

The online paraformer sets only normalize_samples, in both constructors, so streaming decoding runs on the fbank defaults (povey window, high_freq=-400, snip_edges=false) while the model's upstream config.yaml (modelscope speech_paraformer, online variant) specifies window: hamming. We noticed this while running the streaming and offline paraformer on the same audio: the streaming output was consistently worse, and the frontend difference turned out to be the reason. A user in #3511 found the same drift and worked around it with --high-freq=0 --snip-edges=true --window-type=hamming. Related: #3511.

Fix

Give the online impl the same private InitFeatConfig() and call it from both constructors. The gap dates to 6038e2a (#263), which copied the offline paraformer's then-current frontend handling; 25f0a10 (#1148) later upgraded only the offline impl.

Tested

New test_streaming_paraformer in test_online_recognizer.py decodes test_wavs/2.wav of sherpa-onnx-streaming-paraformer-bilingual-zh-en (greedy search, deterministic):

before: 这个是平繁的啊不认识接下来 frequently 苹繁的
after:  这个是频繁的啊不认识接下来 frequently 频繁的

The audio says 频繁 twice; the default frontend misrecognizes it both times. Individual tokens on other utterances can flip either way, but aggregate accuracy improves (about 10 errors fixed on a 4-minute zh recording, converging toward the offline paraformer's output on the same audio). The test fails on master without this change and passes with it; the full test_online_recognizer.py suite passes with no new skips. ./scripts/check_style_cpplint.sh passes.

Only touches online-recognizer-paraformer-impl.h and its Python test; the offline paraformer and all other online recognizers are untouched.

Summary by CodeRabbit

  • Bug Fixes

    • Improved Paraformer streaming speech recognition feature configuration for more consistent audio processing.
  • Tests

    • Added coverage for streaming Paraformer recognition with bilingual Chinese-English transcription.
    • Validates decoding results against an expected transcript.

The offline paraformer sets hamming window, high_freq=0 and
snip_edges=true (InitFeatConfig, added in k2-fsa#1148) to match the FunASR
training frontend, but the online paraformer still used the fbank
defaults (povey window, high_freq=-400, snip_edges=false), degrading
streaming accuracy. Related: k2-fsa#3511
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jul 29, 2026
@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 262ef5fd-860e-4745-994e-a7d8b32465ee

📥 Commits

Reviewing files that changed from the base of the PR and between 2744aa2 and 2e4c91c.

📒 Files selected for processing (2)
  • sherpa-onnx/csrc/online-recognizer-paraformer-impl.h
  • sherpa-onnx/python/tests/test_online_recognizer.py

📝 Walkthrough

Walkthrough

Paraformer feature extraction settings are centralized in InitFeatConfig(), and both constructors use it. A streaming Paraformer Python test now decodes a padded wave file and verifies the expected bilingual transcription.

Changes

Paraformer streaming recognition

Layer / File(s) Summary
Centralized feature configuration
sherpa-onnx/csrc/online-recognizer-paraformer-impl.h
Both constructors call InitFeatConfig(), which sets normalization, window type, high-frequency cutoff, and edge-snipping options.
Streaming recognition regression test
sherpa-onnx/python/tests/test_online_recognizer.py
Adds a conditional streaming Paraformer test that feeds padded audio, decodes to completion, and asserts the bilingual transcript.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: size:M

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: aligning the streaming Paraformer frontend with its training configuration.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@csukuangfj csukuangfj left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants