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

[wenet] support context biasing in bin/recognize.py #2136

Merged
merged 1 commit into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion wenet/bin/recognize.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ def main():
num_decoding_left_chunks=args.num_decoding_left_chunks,
ctc_weight=args.ctc_weight,
simulate_streaming=args.simulate_streaming,
reverse_weight=args.reverse_weight)
reverse_weight=args.reverse_weight,
context_graph=context_graph)
for i, key in enumerate(keys):
for mode, hyps in results.items():
content = [char_dict[w] for w in hyps[i].tokens]
Expand Down
6 changes: 4 additions & 2 deletions wenet/transformer/asr_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
attention_rescoring, DecodeResult)
from wenet.utils.common import (IGNORE_ID, add_sos_eos, th_accuracy,
reverse_pad_list)
from wenet.utils.context_graph import ContextGraph


class ASRModel(torch.nn.Module):
Expand Down Expand Up @@ -192,6 +193,7 @@ def decode(
ctc_weight: float = 0.0,
simulate_streaming: bool = False,
reverse_weight: float = 0.0,
context_graph: ContextGraph = None,
) -> Dict[str, List[DecodeResult]]:
""" Decode input speech

Expand Down Expand Up @@ -234,15 +236,15 @@ def decode(
ctc_probs, encoder_lens)
if 'ctc_prefix_beam_search' in methods:
ctc_prefix_result = ctc_prefix_beam_search(ctc_probs, encoder_lens,
beam_size)
beam_size, context_graph)
results['ctc_prefix_beam_search'] = ctc_prefix_result
if 'attention_rescoring' in methods:
# attention_rescoring depends on ctc_prefix_beam_search nbest
if 'ctc_prefix_beam_search' in results:
ctc_prefix_result = results['ctc_prefix_beam_search']
else:
ctc_prefix_result = ctc_prefix_beam_search(
ctc_probs, encoder_lens, beam_size)
ctc_probs, encoder_lens, beam_size, context_graph)
results['attention_rescoring'] = attention_rescoring(
self, ctc_prefix_result, encoder_out, encoder_lens, ctc_weight,
reverse_weight)
Expand Down
Loading