Apply delay penalty on k2 ctc loss#669
Merged
yaozengwei merged 29 commits intok2-fsa:masterfrom Nov 28, 2022
Merged
Conversation
Collaborator
Author
|
I train the models on full-librispeech for 25 epochs, and decode with
|
baileyeet
pushed a commit
to reazon-research/icefall
that referenced
this pull request
Jul 16, 2025
* add init files * fix bug, apply delay penalty * fix decoding code and getting timestamps * add option applying delay penalty on ctc log-prob * fix bug of streaming decoding * minor change for bpe-based case * add test_model.py * add README.md * add CI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR supports to apply delay penalty on k2 ctc loss, to reduce the symbol delay. The encoder is streaming conformer model.
We provide two methods of delay penalty here:
(1) Add penalty scores on encoder ctc outputs after log-softmax. Use param
--nnet-delay-penaltyintrain.py.(2) Add penalty scores on ctc decoding lattice. Use param
--delay-penaltyintrain.py. It requires k2-fsa/k2#1086 in k2.For method (1), we want to add lambda * torch.arange(T) to the ctc blank probs (after log-softmax), to encourage blanks to align to later and encourage non-blank symbols to align earlier. However, it would also encourage blank over non-blanks. This is not what we want. This effect will be stronger for longer utterances, where the penalty scores lambda * torch.arange(T) get too large. To minimize the above "repeat-penalizing effect", we first split utterances into shorter sub-utterances, for purpose of adding the "arange" expression. We can declare that there is a sub-utterance boundary every time the blank prob is >= 0.99, for instance. Specifically, we
(1) compute a mask that is 1 when blank_prob >= 0.99 (or t==0);
(2) compute cummax_out = torch.cummax(torch.arange(T) * mask)
(3) compute the sawtooth-like "blank-bonus" values: penalty = torch.arange(T) - cummax_out
(4) add penalty * lambda to ctc blank probs (after log-softmax).
For method (2), we add penalty scores (frame offset relative to the middle frame, scaled by lambda) on the non-repeat and non-blank arcs in ctc decoding lattice, which are at the frames when the non-blank symbols are firstly emitted. It is the same as we did in transducer loss (see https://arxiv.org/pdf/2211.00490.pdf).