Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Make minlenratio effective#5581

Merged
siddhu001 merged 10 commits intoespnet:masterfrom
jctian98:decoding_bug
Dec 15, 2023
Merged

Make minlenratio effective#5581
siddhu001 merged 10 commits intoespnet:masterfrom
jctian98:decoding_bug

Conversation

@jctian98
Copy link
Collaborator

@jctian98 jctian98 commented Dec 6, 2023

What?

This is to respond to issues #5573 and #5580 to make the decoding hyper-parameter minlenratio effective in beam search

Previously the minlenratio and the variable minlen were calculated but not applied, which leads to the issue as described below:
Some models intend to predict the special symbol <eos> at the first several decoding steps. As long as the invalid <eos> remains in the top-k list, these invalid hypotheses are added to the ended hypothesis list. Since the invalid hypotheses are short, the accumulated posterior is also very high compared to other valid hypotheses with much longer text hypotheses. The invalid hypotheses are then selected in the finalization stage, most of which are empty strings. As a consequence, the overall decoding results would be empty or very short. The issue is more likely to be observed when beam size is large as the <eos> token is more likely to stay in the top-k list.

To overcome this issue, simply make the minlenratio hyperparameter effective by adding an if condition in the post_process function. Then pass a small heuristic value to it (e.g., 0.1). This will force all ended hypotheses to have a length of at least 10% of the input lengths. Although it's heuristic, it works well generally.

This PR also adds a length normalization feature for the beam search object. If activated, the best hypothesis is selected by the best token-level score rather than the accumulated score.

@mergify
Copy link
Contributor

mergify bot commented Dec 6, 2023

This pull request is now in conflict :(

@mergify mergify bot removed the conflicts label Dec 6, 2023
@codecov
Copy link

codecov bot commented Dec 6, 2023

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (1c55053) 70.62% compared to head (b34bc7b) 76.53%.

Files Patch % Lines
espnet/nets/batch_beam_search_online.py 75.00% 2 Missing ⚠️
espnet/nets/batch_beam_search_online_sim.py 66.66% 2 Missing ⚠️
espnet/nets/beam_search.py 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5581      +/-   ##
==========================================
+ Coverage   70.62%   76.53%   +5.91%     
==========================================
  Files         719      720       +1     
  Lines       66513    66623     +110     
==========================================
+ Hits        46972    50992    +4020     
+ Misses      19541    15631    -3910     
Flag Coverage Ξ”
test_configuration_espnet2 βˆ… <ΓΈ> (βˆ…)
test_integration_espnet1 62.92% <66.66%> (-0.01%) ⬇️
test_integration_espnet2 50.11% <70.00%> (+<0.01%) ⬆️
test_python_espnet1 19.08% <25.00%> (?)
test_python_espnet2 52.38% <75.00%> (-0.01%) ⬇️
test_utils 22.15% <ΓΈ> (ΓΈ)

Flags with carried forward coverage won't be shown. Click here to find out more.

β˜” View full report in Codecov by Sentry.
πŸ“’ Have feedback on the report? Share it here.

@sw005320 sw005320 added the Bugfix label Dec 6, 2023
@sw005320 sw005320 added this to the v.202312 milestone Dec 6, 2023
@sw005320
Copy link
Contributor

sw005320 commented Dec 6, 2023

LGTM!
Once you fix the CI error, I'll merge it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why it does not include the normalization?

Copy link
Collaborator Author

@jctian98 jctian98 Dec 14, 2023

Choose a reason for hiding this comment

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

I think the batch_beam_search class inherits the sort function from the beam_search class. So we don't need to handle this in the batch_beam_search class.

@sw005320
Copy link
Contributor

@siddhu001, can you check the case of negative minlenratio?
Would it be an expected behavior?

@sw005320
Copy link
Contributor

After @siddhu001's confirmation, I'll merge this PR.

@jctian98
Copy link
Collaborator Author

@siddhu001, can you check the case of negative minlenratio? Would it be an expected behavior?

It's good to test with the attention-only model, as the ctc can greatly calibrate the length estimation so minlenratio will not be tested properly.
Please let me know if there is any issue. Thanks @siddhu001

@siddhu001
Copy link
Collaborator

@siddhu001, can you check the case of negative minlenratio? Would it be an expected behavior?

Hi @sw005320,

Yes I believe the case of negative minlenratio is the expected behaviour. We follow a similar approach for negative maxlenratio (i.e. maxlenratio=-1*maxlenratio when maxlenratio<0)

@jctian98 thanks a lot for your efforts on this PR. This is very useful!

@siddhu001 siddhu001 merged commit c39ce51 into espnet:master Dec 15, 2023
@jctian98 jctian98 deleted the decoding_bug branch December 15, 2023 04:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants