-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Streamable Conformer-Transducer ASR model for LibriSpeech #2140
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
Merged
TParcollet
merged 84 commits into
speechbrain:unstable-v0.6
from
asumagic:streaming-asr-v2
Dec 18, 2023
Merged
Changes from all commits
Commits
Show all changes
84 commits
Select commit
Hold shift + click to select a range
cedfd46
Introduce DCT+DCConv logic
asumagic b59accb
DDP fix?
asumagic 9241781
Batch of changes and things brought back
asumagic a504541
Streaming fixes (successfully trains)
asumagic 008055b
WIP streaming code
asumagic 4fc70f4
WIP functional streaming code
asumagic 4a7e95f
Fix left context
asumagic 83616a1
Fix formatting
asumagic 9b3a0d3
Cleanups and docs in streaming utils
asumagic 4ee692f
Better comment hparams, change seed back to orig, improve naming
asumagic b459187
uncomment averaging stuff; it was some ipython issue
asumagic fa5edea
Remove pin_memory as it was not beneficial
asumagic ed36776
More cleanups, comments on context stuff
asumagic a256508
More comments and TODOs
asumagic 0e69129
encode_streaming docstring
asumagic d05a771
Dirty TransducerBeamSearcher change for streaming GS
asumagic afb96db
Fix precommit
asumagic 6585ae8
Fix encoders that do not support chunk_size
asumagic 98d0ddf
Pre-commit again
asumagic c23435f
Make chunk_size type consistent
asumagic dd264a6
Fix formatting of doctest in split_wav_lens
asumagic 107688e
Remove outdated TODO
asumagic 8b88dc9
Add hasattr streaming to retain model backcompat
asumagic c4c730d
Cleanup doc and naming for transducer_greedy_decode
asumagic a02ed5f
Cite paper for chunked attention
asumagic be92a12
Remove lost comment
asumagic 382b97b
Update comment in self-attention
asumagic 12f89bf
Don't apply masked fill fix in the non-bool mask case
asumagic ee444a0
Added TODO README update
asumagic 1013c71
Revert change to custom_tgt_module; patching model instead
asumagic 10ff215
Remove added entry in README
asumagic b16754f
Fix streaming conformer conv mismatch
asumagic e5785d8
More conformer conv adjustments
asumagic 9633156
Adjust context size
asumagic c1fbb8f
Remove outdated comment
asumagic 7446706
Fixed causal conformer decoder
asumagic 1f91e85
Fix linting
asumagic d96a92e
Gate `custom_tgt_module` creation behind the presence of decoder layers
asumagic ddb6d5b
Re-enable checkpoint averaging
asumagic 6ce59c3
Change averaged ckpt count to 10
asumagic 4f52a6f
Add new model results to README
asumagic de7d997
WIP refactor: Introduce DCTConfig dataclass
asumagic d9b6f88
Improved notice in README
asumagic ffb820c
Merge branch 'unstable-v0.6' into streaming-asr-v2
asumagic 11fec0c
Formatting and linting fixes
asumagic 65255c8
Attempt at fixing circular import?
asumagic 0ec5417
utils can't depend on core it seems; move dct
asumagic 61606ac
Whoops, missed file
asumagic fe38e5b
Add DCT test, fix issues
asumagic c2fc373
Remove now obsolete yaml variables for streaming
asumagic 2d31242
Formatting
asumagic faa79e9
Add dummy dct_config parameter to keep unsupported encoders working
asumagic 90f1367
Linting fix
asumagic bcc6b2c
Fix typo
asumagic 2577cc6
Add note on runtime autocast accuracy
asumagic 0c8e382
Fix very bad typo from refactor in YAML
asumagic db73114
Fix hasattr streaming check
asumagic 74496e6
Remove legacy comment
asumagic 4558232
Fix left context size calculation in new mask code
asumagic 8da79f3
Fix causal models in TransformerASR
asumagic bd9f506
Remove comment on high-level inference code
asumagic 0a49c01
YAML formatting + commenting dynchunktrain stuff
asumagic 28cfbb6
Remove outdated comment about DCConv left contexts
asumagic 246b8b4
Remove commented out debug prints from TransformerASR
asumagic 49e73ec
Move DCT into utils again
asumagic 2faf306
Rename all(?) mentions of DCT to explicit dynamic chunk training
asumagic c577c5b
Clarify padding logic
asumagic 176f1d8
Remove now-useless _do_conv, fix horrible formatting
asumagic f17470e
Slightly fix formatting further
asumagic 86850ad
Add docstrings to forward_streaming methods
asumagic 392ed08
Add a reference on Dynamic Chunk Training
asumagic 721f147
Rework conformer docstring docs
asumagic a459180
Update conformer author list, fix doc formatting for authors
asumagic b2f6b5c
Fix trailing whitespace in conformer
asumagic 86b8bba
Improved comments in Conformer.forward
asumagic 9c63fe2
Added random dynchunktrain sampler example
asumagic eee3752
More explicit names for mask functions in TransformerASR
asumagic 17d4f5f
Added docstring example on encode_streaming
asumagic ccc00f6
Pre-commit fix
asumagic dbcdf9a
Fix typo in conformer
asumagic eb67e1a
Initial streaming integration test
asumagic f6213ec
Precommit fix
asumagic 56c69ff
Fix indent in YAML
asumagic e70bb1d
More consistent spelling in streaming integration test
asumagic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -135,7 +135,9 @@ def forward(self, tn_output): | |
| hyps = self.searcher(tn_output) | ||
| return hyps | ||
|
|
||
| def transducer_greedy_decode(self, tn_output): | ||
| def transducer_greedy_decode( | ||
| self, tn_output, hidden_state=None, return_hidden=False | ||
| ): | ||
| """Transducer greedy decoder is a greedy decoder over batch which apply Transducer rules: | ||
| 1- for each time step in the Transcription Network (TN) output: | ||
| -> Update the ith utterance only if | ||
|
|
@@ -149,18 +151,43 @@ def transducer_greedy_decode(self, tn_output): | |
| Output from transcription network with shape | ||
| [batch, time_len, hiddens]. | ||
|
|
||
| hidden_state : (torch.Tensor, torch.Tensor) | ||
| Hidden state to initially feed the decode network with. This is | ||
| useful in conjunction with `return_hidden` to be able to perform | ||
| beam search in a streaming context, so that you can reuse the last | ||
| hidden state as an initial state across calls. | ||
|
|
||
| return_hidden : bool | ||
| Whether the return tuple should contain an extra 5th element with | ||
| the hidden state at of the last step. See `hidden_state`. | ||
|
|
||
| Returns | ||
| ------- | ||
| torch.tensor | ||
| Tuple of 4 or 5 elements (if `return_hidden`). | ||
|
|
||
| First element: List[List[int]] | ||
| List of decoded tokens | ||
|
|
||
| Second element: torch.Tensor | ||
| Outputs a logits tensor [B,T,1,Output_Dim]; padding | ||
| has not been removed. | ||
|
|
||
| Third element: None | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then why do we return it?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To match the beam search API, AFAIK. This is not new, though, it was just undocumented before. |
||
| nbest; irrelevant for greedy decode | ||
|
|
||
| Fourth element: None | ||
|
asumagic marked this conversation as resolved.
|
||
| nbest scores; irrelevant for greedy decode | ||
|
|
||
| Fifth element: Present if `return_hidden`, (torch.Tensor, torch.Tensor) | ||
| Tuple representing the hidden state required to call | ||
| `transducer_greedy_decode` where you left off in a streaming | ||
| context. | ||
| """ | ||
| hyp = { | ||
| "prediction": [[] for _ in range(tn_output.size(0))], | ||
| "logp_scores": [0.0 for _ in range(tn_output.size(0))], | ||
| } | ||
| # prepare BOS = Blank for the Prediction Network (PN) | ||
| hidden = None | ||
| input_PN = ( | ||
| torch.ones( | ||
| (tn_output.size(0), 1), | ||
|
|
@@ -169,8 +196,13 @@ def transducer_greedy_decode(self, tn_output): | |
| ) | ||
| * self.blank_id | ||
| ) | ||
| # First forward-pass on PN | ||
| out_PN, hidden = self._forward_PN(input_PN, self.decode_network_lst) | ||
|
|
||
| if hidden_state is None: | ||
| # First forward-pass on PN | ||
| out_PN, hidden = self._forward_PN(input_PN, self.decode_network_lst) | ||
| else: | ||
| out_PN, hidden = hidden_state | ||
|
|
||
| # For each time step | ||
| for t_step in range(tn_output.size(1)): | ||
| # do unsqueeze over since tjoint must be have a 4 dim [B,T,U,Hidden] | ||
|
|
@@ -210,13 +242,19 @@ def transducer_greedy_decode(self, tn_output): | |
| have_update_hyp, selected_hidden, hidden | ||
| ) | ||
|
|
||
| return ( | ||
| ret = ( | ||
| hyp["prediction"], | ||
| torch.Tensor(hyp["logp_scores"]).exp().mean(), | ||
| None, | ||
| None, | ||
| ) | ||
|
|
||
| if return_hidden: | ||
| # append the `(out_PN, hidden)` tuple to ret | ||
| ret += ((out_PN, hidden,),) | ||
|
|
||
| return ret | ||
|
|
||
| def transducer_beam_search_decode(self, tn_output): | ||
| """Transducer beam search decoder is a beam search decoder over batch which apply Transducer rules: | ||
| 1- for each utterance: | ||
|
|
||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.