Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lm decode for the Python API. #353

Merged
merged 4 commits into from
Oct 13, 2023
Merged

Conversation

kamirdin
Copy link
Contributor

No description provided.

	Shouldn't double lm_log_prob when merge same prefix path
@@ -17,11 +17,6 @@ void Hypotheses::Add(Hypothesis hyp) {
hyps_dict_[key] = std::move(hyp);
} else {
it->second.log_prob = LogAdd<double>()(it->second.log_prob, hyp.log_prob);

if (it->second.lm_log_prob != 0 && hyp.lm_log_prob != 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason to remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

here two decoding paths that have the same prefix and we need to merge them into one path,
we can refer the Python implementation at here :https://github.com/k2-fsa/icefall/blob/2b3c5d799f3a585dc22071a9148424ff77aefd47/egs/librispeech/ASR/pruned_transducer_stateless2/beam_search.py#L843

python implementation perform (path1_am_prob * path1_lm_prob ) + (path2_am_prob * path2_lm_prob )
Since paths with the same prefix must have the same language model probability, we can simplify the calculation to 【path1_lm_prob * ( path1_am_prob + path2_am_prob )】

If we don't remove it , we actually perform (path1_am_prob + path2_am_prob ) * ( path1_lm_prob + path2_lm_prob)
simplified to 【 2 * path1_lm_prob * ( path1_am_prob + path2_am_prob )】

I have tested two opensource test set and compared result :

  双人对话 中英混句
lm-shallow_fusion_0.1 15.18% 22.26%
lm-shallow_fusion_0.1_bug_fix 15.03% 21.99%

test set reference :
https://www.openslr.org/123/
https://magichub.com/cn/competition/code-switching-asr-challenge/

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the detailed explanation!

python-api-examples/online-decode-files.py Outdated Show resolved Hide resolved
sherpa-onnx/python/sherpa_onnx/online_recognizer.py Outdated Show resolved Hide resolved
@csukuangfj
Copy link
Collaborator

Thanks for your contribution!

@csukuangfj csukuangfj merged commit 4771c92 into k2-fsa:master Oct 13, 2023
134 of 144 checks passed
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