Skip to content

fix(seaco): filter hotword candidates per utterance in a batch - #3977

Open
Arthur031221 wants to merge 3 commits into
modelscope:mainfrom
Arthur031221:fix/seaco-hotword-filter-per-utterance
Open

Arthur031221 wants to merge 3 commits into
modelscope:mainfrom
Arthur031221:fix/seaco-hotword-filter-per-utterance

Conversation

@Arthur031221

Copy link
Copy Markdown
Contributor

Summary

With 50 or more hotwords, SeacoParaformer (paraformer-zh) ranked the hotword candidates on the first item of a batch and used that list for every item. If you decoded a file list, or long audio through VAD on GPU, you could silently lose hotwords, and the same audio gave different text depending on what it was batched with. Each utterance is now ranked on its own tokens, with padded positions masked.

Type of change

  • Bug fix

Validation

python -m pytest tests/test_seaco_hotword_filter_batch.py fails on main and passes here.

I also ran the seaco paraformer-large weights with 201 hotwords and [asr_example_zh.wav, asr_example_hotword.wav] as one batch. On main the hotword name spoken in the second file gets a wrong character. Here it's correct, same as when that file is decoded alone.

  • python -m compileall funasr examples tests

User impact

Long hotword lists keep working under batched decoding. Single-file output doesn't change.

Notes for reviewers

The ONNX graph in export_meta.py also ranks on hotword_scores[0]. I left it alone here because changing it needs a re-export.

Assisted by Claude/Codex.

With more than nfilter hotwords, the candidate set was ranked from the first
item of the batch and reused for the others, so their hotwords could be
dropped. Rank each utterance on its own token positions instead.

@LauraGPT LauraGPT 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.

Confirmed that ranking each utterance separately fixes a real batching problem. One boundary in the same selection step still drops a user hotword: the last embedding (no bias) competes in top-k and is then appended again. This also happened on main; it is not a new regression introduced by your per-utterance change.

At the default limit, a user supplying exactly 50 distinct hotwords should not lose any: there are 50 real slots plus the no-bias slot. With the current head I get 49 distinct user entries plus two copies of no-bias. In the small regression below the actual rows are [1,5,5] and [3,5,5]; the expected rows are [0,1,5] and [2,3,5].

I checked the actual GPU retrieval path with two synthetic unequal-duration 16 kHz waveforms, separately and in both batch orders. The reference ranks only real entries using each utterance's valid frames from the last ASF cross-attention layer, then appends no-bias once. Matches out of six utterance results at each vocabulary size:

User hotwords main 84b92dd main + this PR main + PR + suggestions
49 (filter bypassed) 6 6 6
50 0 0 6
61 2 3 6

With 61 hotwords all four batched rows on the PR agreed with their solo candidate sets; on main only one did. The two suggestions preserve that improvement and remove the duplicate. With both applied, the four related test modules passed (28/28) on the exact PR head and separately on the current-main integration.

Scope: offline NVIDIA L20Z, real frontend, encoder, CIF predictor, LSTM hotword encoder and six-layer ASF decoder; seeded, reduced-size weights. These are candidate-selection results, not recognition accuracy or independent validation of the published checkpoint. ONNX export was not changed or tested here.

Comment thread funasr/models/seaco_paraformer/model.py Outdated
dec_filter = torch.topk(hotword_scores, min(nfilter, num_hot_word - 1))[1].tolist()
add_filter = dec_filter
add_filter.append(len(hw_list_pad) - 1)
dec_filter = torch.topk(hotword_scores, min(nfilter, num_hot_word - 1))[1]

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.

Rank the real hotwords only. Inside this branch, nfilter is already less than num_hot_word (which includes the sentinel).

Suggested change
dec_filter = torch.topk(hotword_scores, min(nfilter, num_hot_word - 1))[1]
# Reserve the final no-bias entry; only genuine hotwords compete for top-k.
dec_filter = hotword_scores[:, :-1].topk(nfilter, dim=-1).indices

alone = _candidates([short]) + _candidates([long])
self.assertEqual(alone, [[0, 1, 5], [2, 3, 5]])
self.assertEqual(_candidates([short, long]), alone)
self.assertEqual(_candidates([long, short]), alone[::-1])

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.

Both utterances below give the no-bias entry a high attention score; each must still retain two real hotwords.

Suggested change
self.assertEqual(_candidates([long, short]), alone[::-1])
self.assertEqual(_candidates([long, short]), alone[::-1])
def test_no_bias_does_not_consume_a_real_hotword_slot(self):
# Entry 5 is no-bias. It ranks first, but is appended separately.
first = [5, 5, 5, 1, 0]
second = [5, 5, 2, 3]
self.assertEqual(_candidates([first, second]), [[0, 1, 5], [2, 3, 5]])

Arthur031221 and others added 2 commits December 2, 2026 09:06
The no-bias embedding is the last row, it competed with the user
hotwords for a top-k slot and was then appended again. With exactly
nfilter hotwords one of them was dropped and no-bias appeared twice.
Rank only the real hotwords and append no-bias once.

Co-authored-by: LauraGPT <18321252+LauraGPT@users.noreply.github.com>
Co-authored-by: LauraGPT <18321252+LauraGPT@users.noreply.github.com>
@Arthur031221

Copy link
Copy Markdown
Contributor Author

Applied both suggestions as separate commits with you as co-author. The top-k now ranks only the real hotwords, and the no-bias row is appended once.

The new test fails on the previous head with [[1, 5, 5], [3, 5, 5]] against the expected [[0, 1, 5], [2, 3, 5]], and passes with the change. The seaco and hotword tests in tests/ give 25 passed and 6 skipped on CPU.

This branch has not been deployed

No deployments
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