Args: x (batch, dim_input, seq_len) or (seq_len, batch, dim_input): input sequence batch_first (bool): whether the batch dimension is at the first (or the second dimension). Returns: (batch, dim_output, seq_len_out
(self, x, batch_first=True)
| 679 | return self.compute_receptive_fields()[-1] |
| 680 | |
| 681 | def forward(self, x, batch_first=True): |
| 682 | """ |
| 683 | Args: |
| 684 | x (batch, dim_input, seq_len) or (seq_len, batch, dim_input): |
| 685 | input sequence |
| 686 | batch_first (bool): |
| 687 | whether the batch dimension is at the first (or the second dimension). |
| 688 | |
| 689 | Returns: |
| 690 | (batch, dim_output, seq_len_out) or (seq_len, batch, dim_input) |
| 691 | """ |
| 692 | |
| 693 | if not batch_first: |
| 694 | # convert (seq_len, batch, dim_input) to (batch, dim_input, seq_len) |
| 695 | x = x.permute(1, 2, 0) |
| 696 | |
| 697 | # check if the input sequence length is enough |
| 698 | for i in range(len(self.main) - 1): |
| 699 | x = self.main[i](x) |
| 700 | if self.permute_for_norm: |
| 701 | x = x.permute(0, 2, 1) |
| 702 | x = self.layernorms[i](x) |
| 703 | if self.permute_for_norm: |
| 704 | x = x.permute(0, 2, 1) |
| 705 | x = self.main[-1](x) # (batch, dim_output, seq_len_out) |
| 706 | if self.output_add_nonlinearity: |
| 707 | if self.permute_for_norm: |
| 708 | x = x.permute(0, 2, 1) |
| 709 | x = self.layernorms[-1](x) |
| 710 | if self.permute_for_norm: |
| 711 | x = x.permute(0, 2, 1) |
| 712 | |
| 713 | if not batch_first: |
| 714 | # convert (batch, dim, seq_len) to (seq_len, batch, dim) |
| 715 | x = x.permute(2, 0, 1) |
| 716 | |
| 717 | return x |
nothing calls this directly
no outgoing calls
no test coverage detected