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

Adding blank penalty #541

Closed
chiiyeh opened this issue Jan 23, 2024 · 4 comments · Fixed by #542
Closed

Adding blank penalty #541

chiiyeh opened this issue Jan 23, 2024 · 4 comments · Fixed by #542

Comments

@chiiyeh
Copy link
Contributor

chiiyeh commented Jan 23, 2024

Hi, I am interested to know if blank_penalty can be added as a parameter, given that it seems useful for reducing deletions error in some cases like k2-fsa/icefall#1130 (comment)?

@Triplecq
Copy link

Hi,

I could easily be wrong, but I think you can refer to this recipe: https://github.com/k2-fsa/icefall/blob/master/egs/aishell/ASR/zipformer/decode.py

  1. add this new parameter at line 289 as follows:
 parser.add_argument(
        "--blank-penalty",
        type=float,
        default=0.0,
        help="""
        The penalty applied on blank symbol during decoding.
        Note: It is a positive value that would be applied to logits like
        this `logits[:, 0] -= blank_penalty` (suppose logits.shape is
        [batch_size, vocab] and blank id is 0).
        """,
    )
  1. feed this new parameter to each decoding method, e.g. line 380:
blank_penalty=params.blank_penalty,

I hope it helps!

@csukuangfj
Copy link
Collaborator

Hi,

I could easily be wrong, but I think you can refer to this recipe: https://github.com/k2-fsa/icefall/blob/master/egs/aishell/ASR/zipformer/decode.py

  1. add this new parameter at line 289 as follows:
 parser.add_argument(
        "--blank-penalty",
        type=float,
        default=0.0,
        help="""
        The penalty applied on blank symbol during decoding.
        Note: It is a positive value that would be applied to logits like
        this `logits[:, 0] -= blank_penalty` (suppose logits.shape is
        [batch_size, vocab] and blank id is 0).
        """,
    )
  1. feed this new parameter to each decoding method, e.g. line 380:
blank_penalty=params.blank_penalty,

I hope it helps!

I think you are right, though it is in Python.

Similar code can be added to C++ in sherpa-onnx.

Is anyone willing to contribute? We could provide help with it.

@chiiyeh
Copy link
Contributor Author

chiiyeh commented Jan 24, 2024

I can try to add it in!

@csukuangfj
Copy link
Collaborator

I can try to add it in!

Thanks! Feel free to leave a message when you have any issues.

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 a pull request may close this issue.

3 participants