Forward decoder. Args: memory: encoded memory, float32 (batch, maxlen_in, feat) memory_mask: encoder memory mask, (batch, 1, maxlen_in) ys_in_pad: padded input token ids, int64 (batch, maxlen_out) ys_in_lens: input lengths of this batch (batch
(
self,
memory: torch.Tensor,
memory_mask: torch.Tensor,
ys_in_pad: torch.Tensor,
ys_in_lens: torch.Tensor,
r_ys_in_pad: torch.Tensor,
reverse_weight: float = 0.0,
)
| 428 | n_expert_activated=n_expert_activated) |
| 429 | |
| 430 | def forward( |
| 431 | self, |
| 432 | memory: torch.Tensor, |
| 433 | memory_mask: torch.Tensor, |
| 434 | ys_in_pad: torch.Tensor, |
| 435 | ys_in_lens: torch.Tensor, |
| 436 | r_ys_in_pad: torch.Tensor, |
| 437 | reverse_weight: float = 0.0, |
| 438 | ) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]: |
| 439 | """Forward decoder. |
| 440 | Args: |
| 441 | memory: encoded memory, float32 (batch, maxlen_in, feat) |
| 442 | memory_mask: encoder memory mask, (batch, 1, maxlen_in) |
| 443 | ys_in_pad: padded input token ids, int64 (batch, maxlen_out) |
| 444 | ys_in_lens: input lengths of this batch (batch) |
| 445 | r_ys_in_pad: padded input token ids, int64 (batch, maxlen_out), |
| 446 | used for right to left decoder |
| 447 | reverse_weight: used for right to left decoder |
| 448 | Returns: |
| 449 | (tuple): tuple containing: |
| 450 | x: decoded token score before softmax (batch, maxlen_out, |
| 451 | vocab_size) if use_output_layer is True, |
| 452 | r_x: x: decoded token score (right to left decoder) |
| 453 | before softmax (batch, maxlen_out, vocab_size) |
| 454 | if use_output_layer is True, |
| 455 | olens: (batch, ) |
| 456 | """ |
| 457 | l_x, _, olens = self.left_decoder(memory, memory_mask, ys_in_pad, |
| 458 | ys_in_lens) |
| 459 | r_x = torch.tensor(0.0) |
| 460 | if reverse_weight > 0.0: |
| 461 | r_x, _, olens = self.right_decoder(memory, memory_mask, |
| 462 | r_ys_in_pad, ys_in_lens) |
| 463 | return l_x, r_x, olens |
| 464 | |
| 465 | def forward_one_step( |
| 466 | self, |
nothing calls this directly
no outgoing calls
no test coverage detected