Score. Args: yseq: TODO. state: TODO. x: TODO.
(self, yseq, state, x)
| 345 | ) |
| 346 | |
| 347 | def score(self, yseq, state, x): |
| 348 | # to support mutiple encoder asr mode, in single encoder mode, |
| 349 | # convert torch.Tensor to List of torch.Tensor |
| 350 | """Score. |
| 351 | |
| 352 | Args: |
| 353 | yseq: TODO. |
| 354 | state: TODO. |
| 355 | x: TODO. |
| 356 | """ |
| 357 | if self.num_encs == 1: |
| 358 | x = [x] |
| 359 | |
| 360 | att_idx, z_list, c_list = state["workspace"] |
| 361 | vy = yseq[-1].unsqueeze(0) |
| 362 | ey = self.dropout_emb(self.embed(vy)) # utt list (1) x zdim |
| 363 | if self.num_encs == 1: |
| 364 | att_c, att_w = self.att_list[att_idx]( |
| 365 | x[0].unsqueeze(0), |
| 366 | [x[0].size(0)], |
| 367 | self.dropout_dec[0](state["z_prev"][0]), |
| 368 | state["a_prev"], |
| 369 | ) |
| 370 | else: |
| 371 | att_w = [None] * (self.num_encs + 1) # atts + han |
| 372 | att_c_list = [None] * self.num_encs # atts |
| 373 | for idx in range(self.num_encs): |
| 374 | att_c_list[idx], att_w[idx] = self.att_list[idx]( |
| 375 | x[idx].unsqueeze(0), |
| 376 | [x[idx].size(0)], |
| 377 | self.dropout_dec[0](state["z_prev"][0]), |
| 378 | state["a_prev"][idx], |
| 379 | ) |
| 380 | h_han = torch.stack(att_c_list, dim=1) |
| 381 | att_c, att_w[self.num_encs] = self.att_list[self.num_encs]( |
| 382 | h_han, |
| 383 | [self.num_encs], |
| 384 | self.dropout_dec[0](state["z_prev"][0]), |
| 385 | state["a_prev"][self.num_encs], |
| 386 | ) |
| 387 | ey = torch.cat((ey, att_c), dim=1) # utt(1) x (zdim + hdim) |
| 388 | z_list, c_list = self.rnn_forward(ey, z_list, c_list, state["z_prev"], state["c_prev"]) |
| 389 | if self.context_residual: |
| 390 | logits = self.output(torch.cat((self.dropout_dec[-1](z_list[-1]), att_c), dim=-1)) |
| 391 | else: |
| 392 | logits = self.output(self.dropout_dec[-1](z_list[-1])) |
| 393 | logp = F.log_softmax(logits, dim=1).squeeze(0) |
| 394 | return ( |
| 395 | logp, |
| 396 | dict( |
| 397 | c_prev=c_list[:], |
| 398 | z_prev=z_list[:], |
| 399 | a_prev=att_w, |
| 400 | workspace=(att_idx, z_list, c_list), |
| 401 | ), |
| 402 | ) |
no test coverage detected