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,
)
| 330 | tie_word_embedding=tie_word_embedding) |
| 331 | |
| 332 | def forward( |
| 333 | self, |
| 334 | memory: torch.Tensor, |
| 335 | memory_mask: torch.Tensor, |
| 336 | ys_in_pad: torch.Tensor, |
| 337 | ys_in_lens: torch.Tensor, |
| 338 | r_ys_in_pad: torch.Tensor, |
| 339 | reverse_weight: float = 0.0, |
| 340 | ) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]: |
| 341 | """Forward decoder. |
| 342 | Args: |
| 343 | memory: encoded memory, float32 (batch, maxlen_in, feat) |
| 344 | memory_mask: encoder memory mask, (batch, 1, maxlen_in) |
| 345 | ys_in_pad: padded input token ids, int64 (batch, maxlen_out) |
| 346 | ys_in_lens: input lengths of this batch (batch) |
| 347 | r_ys_in_pad: padded input token ids, int64 (batch, maxlen_out), |
| 348 | used for right to left decoder |
| 349 | reverse_weight: used for right to left decoder |
| 350 | Returns: |
| 351 | (tuple): tuple containing: |
| 352 | x: decoded token score before softmax (batch, maxlen_out, |
| 353 | vocab_size) if use_output_layer is True, |
| 354 | r_x: x: decoded token score (right to left decoder) |
| 355 | before softmax (batch, maxlen_out, vocab_size) |
| 356 | if use_output_layer is True, |
| 357 | olens: (batch, ) |
| 358 | """ |
| 359 | l_x, _, olens = self.left_decoder(memory, memory_mask, ys_in_pad, |
| 360 | ys_in_lens) |
| 361 | r_x = torch.tensor(0.0) |
| 362 | if reverse_weight > 0.0: |
| 363 | r_x, _, olens = self.right_decoder(memory, memory_mask, |
| 364 | r_ys_in_pad, ys_in_lens) |
| 365 | return l_x, r_x, olens |
| 366 | |
| 367 | def forward_one_step( |
| 368 | self, |
nothing calls this directly
no outgoing calls
no test coverage detected