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

Method forward

espnet2/asr/decoder/rnn_decoder.py:171–253  ·  view source on GitHub ↗
(self, hs_pad, hlens, ys_in_pad, ys_in_lens, strm_idx=0)

Source from the content-addressed store, hash-verified

169 return z_list, c_list
170
171 def forward(self, hs_pad, hlens, ys_in_pad, ys_in_lens, strm_idx=0):
172 # to support mutiple encoder asr mode, in single encoder mode,
173 # convert torch.Tensor to List of torch.Tensor
174 if self.num_encs == 1:
175 hs_pad = [hs_pad]
176 hlens = [hlens]
177
178 # attention index for the attention module
179 # in SPA (speaker parallel attention),
180 # att_idx is used to select attention module. In other cases, it is 0.
181 att_idx = min(strm_idx, len(self.att_list) - 1)
182
183 # hlens should be list of list of integer
184 hlens = [list(map(int, hlens[idx])) for idx in range(self.num_encs)]
185
186 # get dim, length info
187 olength = ys_in_pad.size(1)
188
189 # initialization
190 c_list = [self.zero_state(hs_pad[0])]
191 z_list = [self.zero_state(hs_pad[0])]
192 for _ in range(1, self.dlayers):
193 c_list.append(self.zero_state(hs_pad[0]))
194 z_list.append(self.zero_state(hs_pad[0]))
195 z_all = []
196 if self.num_encs == 1:
197 att_w = None
198 self.att_list[att_idx].reset() # reset pre-computation of h
199 else:
200 att_w_list = [None] * (self.num_encs + 1) # atts + han
201 att_c_list = [None] * self.num_encs # atts
202 for idx in range(self.num_encs + 1):
203 # reset pre-computation of h in atts and han
204 self.att_list[idx].reset()
205
206 # pre-computation of embedding
207 eys = self.dropout_emb(self.embed(ys_in_pad)) # utt x olen x zdim
208
209 # loop for an output sequence
210 for i in range(olength):
211 if self.num_encs == 1:
212 att_c, att_w = self.att_list[att_idx](
213 hs_pad[0], hlens[0], self.dropout_dec[0](z_list[0]), att_w
214 )
215 else:
216 for idx in range(self.num_encs):
217 att_c_list[idx], att_w_list[idx] = self.att_list[idx](
218 hs_pad[idx],
219 hlens[idx],
220 self.dropout_dec[0](z_list[0]),
221 att_w_list[idx],
222 )
223 hs_pad_han = torch.stack(att_c_list, dim=1)
224 hlens_han = [self.num_encs] * len(ys_in_pad)
225 att_c, att_w_list[self.num_encs] = self.att_list[self.num_encs](
226 hs_pad_han,
227 hlens_han,
228 self.dropout_dec[0](z_list[0]),

Callers

nothing calls this directly

Calls 8

zero_stateMethod · 0.95
rnn_forwardMethod · 0.95
to_deviceFunction · 0.90
make_pad_maskFunction · 0.90
sizeMethod · 0.80
appendMethod · 0.80
argmaxMethod · 0.80
resetMethod · 0.45

Tested by

no test coverage detected