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 blank_penalty for offline transducer #542

Merged
merged 5 commits into from
Jan 25, 2024
Merged

add blank_penalty for offline transducer #542

merged 5 commits into from
Jan 25, 2024

Conversation

chiiyeh
Copy link
Contributor

@chiiyeh chiiyeh commented Jan 24, 2024

Fix #541
Tested with sherpa-onnx-offline. High penalty will force out more words.

Copy link
Collaborator

@csukuangfj csukuangfj left a comment

Choose a reason for hiding this comment

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

Thanks! Left some minor comments. Otherwise, it looks good to me.

const float *p_logit = logit.GetTensorData<float>();
float *p_logit = logit.GetTensorMutableData<float>();
if (blank_penalty_ > 0.0) {
p_logit[0] -= blank_penalty_; // assuming blank id is 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shall we also consider the case when batch_size > 1 ?

p_logit[0] is only for the first utterance.

We need to process

p_logit[vocab_size*i + 0]
// for in range(n)

You can move this if statement into the for statement below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

@@ -862,6 +876,7 @@ def create_recognizer(args) -> sherpa_onnx.OfflineRecognizer:
max_active_paths=args.max_active_paths,
hotwords_file=args.hotwords_file,
hotwords_score=args.hotwords_score,
blank_penalty=args.blank_penalty,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you also update


to add an extra argument

blank_penalty: float = 0

and also add docstring for it?

Note that you need to pass the argument to

recognizer_config = OfflineRecognizerConfig(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!
I also noticed there is no docstring for the hotwords params, as well as the max_active_paths was not propagated into the OfflineRecognizerConfig. Should I raise two seperate PR to fix these?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should I raise two seperate PR to fix these?

Yes, please do that in a separate PR. Thanks!

@csukuangfj
Copy link
Collaborator

By the way, please merge the master branch into your current branch so the CI can pass.

@csukuangfj
Copy link
Collaborator

Could you fix the c++ code style check?
https://github.com/k2-fsa/sherpa-onnx/actions/runs/7648706009/job/20842763975#step:4:38

Check last commit
sherpa-onnx/csrc/math.h:100:  Lines should be <= 80 characters long  [whitespace/line_length] [2]
Done processing sherpa-onnx/csrc/math.h
Total errors found: 1
[FAILED] sherpa-onnx/csrc/math.h
Error: Process completed with exit code 1

You can run

pip install clang-format
cd /path/to/sherpa-onnx
./scripts/check_style_cpplint.sh
./scripts/check_style_cpplint.sh 1
./scripts/check_style_cpplint.sh 2

to check the style locally.

@csukuangfj
Copy link
Collaborator

Thank you for your first-time contribution!

@csukuangfj csukuangfj merged commit 3bb3849 into k2-fsa:master Jan 25, 2024
171 of 179 checks passed
XiaYucca pushed a commit to XiaYucca/sherpa-onnx that referenced this pull request Jan 9, 2025
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.

Adding blank penalty
2 participants