MCPcopy Create free account
hub / github.com/espnet/espnet / RNNDecoder

Class RNNDecoder

espnet2/asr/decoder/rnn_decoder.py:82–336  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80
81
82class RNNDecoder(AbsDecoder):
83 @typechecked
84 def __init__(
85 self,
86 vocab_size: int,
87 encoder_output_size: int,
88 rnn_type: str = "lstm",
89 num_layers: int = 1,
90 hidden_size: int = 320,
91 sampling_probability: float = 0.0,
92 dropout: float = 0.0,
93 context_residual: bool = False,
94 replace_sos: bool = False,
95 num_encs: int = 1,
96 att_conf: dict = get_default_kwargs(build_attention_list),
97 ):
98 # FIXME(kamo): The parts of num_spk should be refactored more more more
99 if rnn_type not in {"lstm", "gru"}:
100 raise ValueError(f"Not supported: rnn_type={rnn_type}")
101
102 super().__init__()
103 eprojs = encoder_output_size
104 self.dtype = rnn_type
105 self.dunits = hidden_size
106 self.dlayers = num_layers
107 self.context_residual = context_residual
108 self.sos = vocab_size - 1
109 self.eos = vocab_size - 1
110 self.odim = vocab_size
111 self.sampling_probability = sampling_probability
112 self.dropout = dropout
113 self.num_encs = num_encs
114
115 # for multilingual translation
116 self.replace_sos = replace_sos
117
118 self.embed = torch.nn.Embedding(vocab_size, hidden_size)
119 self.dropout_emb = torch.nn.Dropout(p=dropout)
120
121 self.decoder = torch.nn.ModuleList()
122 self.dropout_dec = torch.nn.ModuleList()
123 self.decoder += [
124 (
125 torch.nn.LSTMCell(hidden_size + eprojs, hidden_size)
126 if self.dtype == "lstm"
127 else torch.nn.GRUCell(hidden_size + eprojs, hidden_size)
128 )
129 ]
130 self.dropout_dec += [torch.nn.Dropout(p=dropout)]
131 for _ in range(1, self.dlayers):
132 self.decoder += [
133 (
134 torch.nn.LSTMCell(hidden_size, hidden_size)
135 if self.dtype == "lstm"
136 else torch.nn.GRUCell(hidden_size, hidden_size)
137 )
138 ]
139 self.dropout_dec += [torch.nn.Dropout(p=dropout)]

Callers 9

test_RNNDecoder_backwardFunction · 0.90
get_decoderFunction · 0.90
test_rnn_decoderFunction · 0.90
test_rnn_typeFunction · 0.90
__init__Method · 0.90

Calls

no outgoing calls

Tested by 9

test_RNNDecoder_backwardFunction · 0.72
get_decoderFunction · 0.72
test_rnn_decoderFunction · 0.72
test_rnn_typeFunction · 0.72
__init__Method · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…