def decode_one_batch(params: AttributeDict, model: nn.Module, HLG: Optional[k2.Fsa], H: Optional[k2.Fsa], bpe_model: Optional[spm.SentencePieceProcessor], batch: dict, word_table: k2.SymbolTable, sos_id: int, eos_id: int, G: Optional[k2.Fsa]=None) -> Dict[(str, List[List[str]])]:
    'Decode one batch and return the result in a dict. The dict has the\n    following format:\n\n        - key: It indicates the setting used for decoding. For example,\n               if no rescoring is used, the key is the string `no_rescore`.\n               If LM rescoring is used, the key is the string `lm_scale_xxx`,\n               where `xxx` is the value of `lm_scale`. An example key is\n               `lm_scale_0.7`\n        - value: It contains the decoding result. `len(value)` equals to\n                 batch size. `value[i]` is the decoding result for the i-th\n                 utterance in the given batch.\n    Args:\n      params:\n        It\'s the return value of :func:`get_params`.\n\n        - params.method is "1best", it uses 1best decoding without LM rescoring.\n        - params.method is "nbest", it uses nbest decoding without LM rescoring.\n        - params.method is "nbest-rescoring", it uses nbest LM rescoring.\n        - params.method is "whole-lattice-rescoring", it uses whole lattice LM\n          rescoring.\n\n      model:\n        The neural model.\n      HLG:\n        The decoding graph. Used only when params.method is NOT ctc-decoding.\n      H:\n        The ctc topo. Used only when params.method is ctc-decoding.\n      bpe_model:\n        The BPE model. Used only when params.method is ctc-decoding.\n      batch:\n        It is the return value from iterating\n        `lhotse.dataset.K2SpeechRecognitionDataset`. See its documentation\n        for the format of the `batch`.\n      word_table:\n        The word symbol table.\n      sos_id:\n        The token ID of the SOS.\n      eos_id:\n        The token ID of the EOS.\n      G:\n        An LM. It is not None when params.method is "nbest-rescoring"\n        or "whole-lattice-rescoring". In general, the G in HLG\n        is a 3-gram LM, while this G is a 4-gram LM.\n    Returns:\n      Return the decoding result. See above description for the format of\n      the returned dict.\n    '
    if (HLG is not None):
        device = HLG.device
    else:
        device = H.device
    feature = batch['inputs']
    assert (feature.ndim == 3)
    feature = feature.to(device)
    supervisions = batch['supervisions']
    (nnet_output, memory, memory_key_padding_mask) = model(feature, supervisions)
    supervision_segments = torch.stack((supervisions['sequence_idx'], (supervisions['start_frame'] // params.subsampling_factor), (supervisions['num_frames'] // params.subsampling_factor)), 1).to(torch.int32)
    if (H is None):
        assert (HLG is not None)
        decoding_graph = HLG
    else:
        assert (HLG is None)
        assert (bpe_model is not None)
        decoding_graph = H
    lattice = get_lattice(nnet_output=nnet_output, decoding_graph=decoding_graph, supervision_segments=supervision_segments, search_beam=params.search_beam, output_beam=params.output_beam, min_active_states=params.min_active_states, max_active_states=params.max_active_states, subsampling_factor=params.subsampling_factor)
    if (params.method == 'ctc-decoding'):
        best_path = one_best_decoding(lattice=lattice, use_double_scores=params.use_double_scores)
        token_ids = get_texts(best_path)
        hyps = bpe_model.decode(token_ids)
        hyps = [s.split() for s in hyps]
        key = 'ctc-decoding'
        return {key: hyps}
    if (params.method == 'nbest-oracle'):
        best_path = nbest_oracle(lattice=lattice, num_paths=params.num_paths, ref_texts=supervisions['text'], word_table=word_table, nbest_scale=params.nbest_scale, oov='<UNK>')
        hyps = get_texts(best_path)
        hyps = [[word_table[i] for i in ids] for ids in hyps]
        key = f'oracle_{params.num_paths}_nbest_scale_{params.nbest_scale}'
        return {key: hyps}
    if (params.method in ['1best', 'nbest']):
        if (params.method == '1best'):
            best_path = one_best_decoding(lattice=lattice, use_double_scores=params.use_double_scores)
            key = 'no_rescore'
        else:
            best_path = nbest_decoding(lattice=lattice, num_paths=params.num_paths, use_double_scores=params.use_double_scores, nbest_scale=params.nbest_scale)
            key = f'no_rescore-nbest-scale-{params.nbest_scale}-{params.num_paths}'
        hyps = get_texts(best_path)
        hyps = [[word_table[i] for i in ids] for ids in hyps]
        return {key: hyps}
    assert (params.method in ['nbest-rescoring', 'whole-lattice-rescoring', 'attention-decoder'])
    lm_scale_list = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7]
    lm_scale_list += [0.8, 0.9, 1.0, 1.1, 1.2, 1.3]
    lm_scale_list += [1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0]
    if (params.method == 'nbest-rescoring'):
        best_path_dict = rescore_with_n_best_list(lattice=lattice, G=G, num_paths=params.num_paths, lm_scale_list=lm_scale_list, nbest_scale=params.nbest_scale)
    elif (params.method == 'whole-lattice-rescoring'):
        best_path_dict = rescore_with_whole_lattice(lattice=lattice, G_with_epsilon_loops=G, lm_scale_list=lm_scale_list)
    elif (params.method == 'attention-decoder'):
        rescored_lattice = rescore_with_whole_lattice(lattice=lattice, G_with_epsilon_loops=G, lm_scale_list=None)
        best_path_dict = rescore_with_attention_decoder(lattice=rescored_lattice, num_paths=params.num_paths, model=model, memory=memory, memory_key_padding_mask=memory_key_padding_mask, sos_id=sos_id, eos_id=eos_id, nbest_scale=params.nbest_scale)
    else:
        assert False, f'Unsupported decoding method: {params.method}'
    ans = dict()
    if (best_path_dict is not None):
        for (lm_scale_str, best_path) in best_path_dict.items():
            hyps = get_texts(best_path)
            hyps = [[word_table[i] for i in ids] for ids in hyps]
            ans[lm_scale_str] = hyps
    else:
        for lm_scale in lm_scale_list:
            ans['empty'] = [([] * lattice.shape[0])]
    return ans
Decode one batch and return the result in a dict. The dict has the
following format:

    - key: It indicates the setting used for decoding. For example,
           if no rescoring is used, the key is the string `no_rescore`.
           If LM rescoring is used, the key is the string `lm_scale_xxx`,
           where `xxx` is the value of `lm_scale`. An example key is
           `lm_scale_0.7`
    - value: It contains the decoding result. `len(value)` equals to
             batch size. `value[i]` is the decoding result for the i-th
             utterance in the given batch.
Args:
  params:
    It's the return value of :func:`get_params`.

    - params.method is "1best", it uses 1best decoding without LM rescoring.
    - params.method is "nbest", it uses nbest decoding without LM rescoring.
    - params.method is "nbest-rescoring", it uses nbest LM rescoring.
    - params.method is "whole-lattice-rescoring", it uses whole lattice LM
      rescoring.

  model:
    The neural model.
  HLG:
    The decoding graph. Used only when params.method is NOT ctc-decoding.
  H:
    The ctc topo. Used only when params.method is ctc-decoding.
  bpe_model:
    The BPE model. Used only when params.method is ctc-decoding.
  batch:
    It is the return value from iterating
    `lhotse.dataset.K2SpeechRecognitionDataset`. See its documentation
    for the format of the `batch`.
  word_table:
    The word symbol table.
  sos_id:
    The token ID of the SOS.
  eos_id:
    The token ID of the EOS.
  G:
    An LM. It is not None when params.method is "nbest-rescoring"
    or "whole-lattice-rescoring". In general, the G in HLG
    is a 3-gram LM, while this G is a 4-gram LM.
Returns:
  Return the decoding result. See above description for the format of
  the returned dict.
def decode_one_batch(params: AttributeDict, model: nn.Module, HLG: Optional[k2.Fsa], H: Optional[k2.Fsa], bpe_model: Optional[spm.SentencePieceProcessor], batch: dict, word_table: k2.SymbolTable, sos_id: int, eos_id: int, G: Optional[k2.Fsa]=None) -> Dict[(str, List[List[str]])]:
    'Decode one batch and return the result in a dict. The dict has the\n    following format:\n\n        - key: It indicates the setting used for decoding. For example,\n               if no rescoring is used, the key is the string `no_rescore`.\n               If LM rescoring is used, the key is the string `lm_scale_xxx`,\n               where `xxx` is the value of `lm_scale`. An example key is\n               `lm_scale_0.7`\n        - value: It contains the decoding result. `len(value)` equals to\n                 batch size. `value[i]` is the decoding result for the i-th\n                 utterance in the given batch.\n    Args:\n      params:\n        It\'s the return value of :func:`get_params`.\n\n        - params.method is "1best", it uses 1best decoding without LM rescoring.\n        - params.method is "nbest", it uses nbest decoding without LM rescoring.\n        - params.method is "nbest-rescoring", it uses nbest LM rescoring.\n        - params.method is "whole-lattice-rescoring", it uses whole lattice LM\n          rescoring.\n\n      model:\n        The neural model.\n      HLG:\n        The decoding graph. Used only when params.method is NOT ctc-decoding.\n      H:\n        The ctc topo. Used only when params.method is ctc-decoding.\n      bpe_model:\n        The BPE model. Used only when params.method is ctc-decoding.\n      batch:\n        It is the return value from iterating\n        `lhotse.dataset.K2SpeechRecognitionDataset`. See its documentation\n        for the format of the `batch`.\n      word_table:\n        The word symbol table.\n      sos_id:\n        The token ID of the SOS.\n      eos_id:\n        The token ID of the EOS.\n      G:\n        An LM. It is not None when params.method is "nbest-rescoring"\n        or "whole-lattice-rescoring". In general, the G in HLG\n        is a 3-gram LM, while this G is a 4-gram LM.\n    Returns:\n      Return the decoding result. See above description for the format of\n      the returned dict.\n    '
    if (HLG is not None):
        device = HLG.device
    else:
        device = H.device
    feature = batch['inputs']
    assert (feature.ndim == 3)
    feature = feature.to(device)
    supervisions = batch['supervisions']
    (nnet_output, memory, memory_key_padding_mask) = model(feature, supervisions)
    supervision_segments = torch.stack((supervisions['sequence_idx'], (supervisions['start_frame'] // params.subsampling_factor), (supervisions['num_frames'] // params.subsampling_factor)), 1).to(torch.int32)
    if (H is None):
        assert (HLG is not None)
        decoding_graph = HLG
    else:
        assert (HLG is None)
        assert (bpe_model is not None)
        decoding_graph = H
    lattice = get_lattice(nnet_output=nnet_output, decoding_graph=decoding_graph, supervision_segments=supervision_segments, search_beam=params.search_beam, output_beam=params.output_beam, min_active_states=params.min_active_states, max_active_states=params.max_active_states, subsampling_factor=params.subsampling_factor)
    if (params.method == 'ctc-decoding'):
        best_path = one_best_decoding(lattice=lattice, use_double_scores=params.use_double_scores)
        token_ids = get_texts(best_path)
        hyps = bpe_model.decode(token_ids)
        hyps = [s.split() for s in hyps]
        key = 'ctc-decoding'
        return {key: hyps}
    if (params.method == 'nbest-oracle'):
        best_path = nbest_oracle(lattice=lattice, num_paths=params.num_paths, ref_texts=supervisions['text'], word_table=word_table, nbest_scale=params.nbest_scale, oov='<UNK>')
        hyps = get_texts(best_path)
        hyps = [[word_table[i] for i in ids] for ids in hyps]
        key = f'oracle_{params.num_paths}_nbest_scale_{params.nbest_scale}'
        return {key: hyps}
    if (params.method in ['1best', 'nbest']):
        if (params.method == '1best'):
            best_path = one_best_decoding(lattice=lattice, use_double_scores=params.use_double_scores)
            key = 'no_rescore'
        else:
            best_path = nbest_decoding(lattice=lattice, num_paths=params.num_paths, use_double_scores=params.use_double_scores, nbest_scale=params.nbest_scale)
            key = f'no_rescore-nbest-scale-{params.nbest_scale}-{params.num_paths}'
        hyps = get_texts(best_path)
        hyps = [[word_table[i] for i in ids] for ids in hyps]
        return {key: hyps}
    assert (params.method in ['nbest-rescoring', 'whole-lattice-rescoring', 'attention-decoder'])
    lm_scale_list = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7]
    lm_scale_list += [0.8, 0.9, 1.0, 1.1, 1.2, 1.3]
    lm_scale_list += [1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0]
    if (params.method == 'nbest-rescoring'):
        best_path_dict = rescore_with_n_best_list(lattice=lattice, G=G, num_paths=params.num_paths, lm_scale_list=lm_scale_list, nbest_scale=params.nbest_scale)
    elif (params.method == 'whole-lattice-rescoring'):
        best_path_dict = rescore_with_whole_lattice(lattice=lattice, G_with_epsilon_loops=G, lm_scale_list=lm_scale_list)
    elif (params.method == 'attention-decoder'):
        rescored_lattice = rescore_with_whole_lattice(lattice=lattice, G_with_epsilon_loops=G, lm_scale_list=None)
        best_path_dict = rescore_with_attention_decoder(lattice=rescored_lattice, num_paths=params.num_paths, model=model, memory=memory, memory_key_padding_mask=memory_key_padding_mask, sos_id=sos_id, eos_id=eos_id, nbest_scale=params.nbest_scale)
    else:
        assert False, f'Unsupported decoding method: {params.method}'
    ans = dict()
    if (best_path_dict is not None):
        for (lm_scale_str, best_path) in best_path_dict.items():
            hyps = get_texts(best_path)
            hyps = [[word_table[i] for i in ids] for ids in hyps]
            ans[lm_scale_str] = hyps
    else:
        for lm_scale in lm_scale_list:
            ans['empty'] = [([] * lattice.shape[0])]
    return ans