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

Method score

espnet2/asr/decoder/rnn_decoder.py:284–336  ·  view source on GitHub ↗
(self, yseq, state, x)

Source from the content-addressed store, hash-verified

282 )
283
284 def score(self, yseq, state, x):
285 # to support mutiple encoder asr mode, in single encoder mode,
286 # convert torch.Tensor to List of torch.Tensor
287 if self.num_encs == 1:
288 x = [x]
289
290 att_idx, z_list, c_list = state["workspace"]
291 vy = yseq[-1].unsqueeze(0)
292 ey = self.dropout_emb(self.embed(vy)) # utt list (1) x zdim
293 if self.num_encs == 1:
294 att_c, att_w = self.att_list[att_idx](
295 x[0].unsqueeze(0),
296 [x[0].size(0)],
297 self.dropout_dec[0](state["z_prev"][0]),
298 state["a_prev"],
299 )
300 else:
301 att_w = [None] * (self.num_encs + 1) # atts + han
302 att_c_list = [None] * self.num_encs # atts
303 for idx in range(self.num_encs):
304 att_c_list[idx], att_w[idx] = self.att_list[idx](
305 x[idx].unsqueeze(0),
306 [x[idx].size(0)],
307 self.dropout_dec[0](state["z_prev"][0]),
308 state["a_prev"][idx],
309 )
310 h_han = torch.stack(att_c_list, dim=1)
311 att_c, att_w[self.num_encs] = self.att_list[self.num_encs](
312 h_han,
313 [self.num_encs],
314 self.dropout_dec[0](state["z_prev"][0]),
315 state["a_prev"][self.num_encs],
316 )
317 ey = torch.cat((ey, att_c), dim=1) # utt(1) x (zdim + hdim)
318 z_list, c_list = self.rnn_forward(
319 ey, z_list, c_list, state["z_prev"], state["c_prev"]
320 )
321 if self.context_residual:
322 logits = self.output(
323 torch.cat((self.dropout_dec[-1](z_list[-1]), att_c), dim=-1)
324 )
325 else:
326 logits = self.output(self.dropout_dec[-1](z_list[-1]))
327 logp = F.log_softmax(logits, dim=1).squeeze(0)
328 return (
329 logp,
330 dict(
331 c_prev=c_list[:],
332 z_prev=z_list[:],
333 a_prev=att_w,
334 workspace=(att_idx, z_list, c_list),
335 ),
336 )

Callers 1

Calls 3

rnn_forwardMethod · 0.95
sizeMethod · 0.80
log_softmaxMethod · 0.45

Tested by 1