Repository: espnet/espnet

Issue:
Old Docker Version failing recog_wav.sh due to a recent commit to support RNN-T decoding
The BeamSearchTransducer function in https://github.com/espnet/espnet/blob/master/espnet/asr/pytorch_backend/asr.py#L38

causes old docker versions to fail which do not have espnet-2 installed. 

@b-flo for the time being would it be okay to move this to - https://github.com/espnet/espnet/blob/master/espnet/asr/pytorch_backend/asr.py#L991

It seems like it's being used only for the RNN-T decoding.

Thanks
Sid


Discussion:
If I understand the issue correctly, it is caused by [AbsDecoder](https://github.com/espnet/espnet/blob/master/espnet/nets/beam_search_transducer.py#L48) and its import from espnet2 (`from espnet2.asr.decoder.abs_decoder import AbsDecoder`), right?

It should be replaced by `decoder: Union[TransducerDecoderInterface, torch.nn.Module]` and the import by `from espnet.nets.transducer_decoder_interface import TransducerDecoderInterface`. 

Sorry, it seems I forgot to remove that typing and import after we tried to do some unification between espnet1 and 2 for future port.

Resolving patch:
diff --git a/espnet/nets/beam_search_transducer.py b/espnet/nets/beam_search_transducer.py
--- a/espnet/nets/beam_search_transducer.py
+++ b/espnet/nets/beam_search_transducer.py
@@ -1,11 +1,6 @@
 """Search algorithms for transducer models."""
 
-from dataclasses import dataclass
-from typing import Any
-from typing import Dict
 from typing import List
-from typing import Optional
-from typing import Tuple
 from typing import Union
 
 import numpy as np
@@ -17,27 +12,9 @@
 from espnet.nets.pytorch_backend.transducer.utils import recombine_hyps
 from espnet.nets.pytorch_backend.transducer.utils import select_lm_state
 from espnet.nets.pytorch_backend.transducer.utils import substract
-from espnet2.asr.decoder.abs_decoder import AbsDecoder
-
-
-@dataclass
-class Hypothesis:
-    """Default hypothesis definition for beam search."""
-
-    score: float
-    yseq: List[int]
-    dec_state: Union[
-        Tuple[torch.Tensor, Optional[torch.Tensor]], List[torch.Tensor], torch.Tensor
-    ]
-    lm_state: Union[Dict[str, Any], List[Any]] = None
-
-
-@dataclass
-class NSCHypothesis(Hypothesis):
-    """Extended hypothesis definition for NSC beam search."""
-
-    y: List[torch.Tensor] = None
-    lm_scores: torch.Tensor = None
+from espnet.nets.transducer_decoder_interface import Hypothesis
+from espnet.nets.transducer_decoder_interface import NSCHypothesis
+from espnet.nets.transducer_decoder_interface import TransducerDecoderInterface
 
 
 class BeamSearchTransducer:
@@ -45,7 +22,7 @@ class BeamSearchTransducer:
 
     def __init__(
         self,
-        decoder: Union[AbsDecoder, torch.nn.Module],
+        decoder: Union[TransducerDecoderInterface, torch.nn.Module],
         joint_network: torch.nn.Module,
         beam_size: int,
         lm: torch.nn.Module = None,
diff --git a/espnet/nets/transducer_decoder_interface.py b/espnet/nets/transducer_decoder_interface.py
--- a/espnet/nets/transducer_decoder_interface.py
+++ b/espnet/nets/transducer_decoder_interface.py
@@ -1,5 +1,6 @@
 """Transducer decoder interface module."""
 
+from dataclasses import dataclass
 from typing import Any
 from typing import Dict
 from typing import List
@@ -9,8 +10,25 @@
 
 import torch
 
-from espnet.nets.beam_search_transducer import Hypothesis
-from espnet.nets.beam_search_transducer import NSCHypothesis
+
+@dataclass
+class Hypothesis:
+    """Default hypothesis definition for beam search."""
+
+    score: float
+    yseq: List[int]
+    dec_state: Union[
+        Tuple[torch.Tensor, Optional[torch.Tensor]], List[torch.Tensor], torch.Tensor
+    ]
+    lm_state: Union[Dict[str, Any], List[Any]] = None
+
+
+@dataclass
+class NSCHypothesis(Hypothesis):
+    """Extended hypothesis definition for NSC beam search."""
+
+    y: List[torch.Tensor] = None
+    lm_scores: torch.Tensor = None
 
 
 class TransducerDecoderInterface:


Test patch: