Encode input sequences. Args: x: Encoder input features. (B, T_in, F) x_len: Encoder input features lengths. (B,) Returns: x: Encoder outputs. (B, T_out, D_enc) x_len: Encoder outputs lenghts. (B,)
(
self,
x: torch.Tensor,
x_len: torch.Tensor,
)
| 1067 | return self.encoders.reset_streaming_cache(left_context, device) |
| 1068 | |
| 1069 | def forward( |
| 1070 | self, |
| 1071 | x: torch.Tensor, |
| 1072 | x_len: torch.Tensor, |
| 1073 | ) -> Tuple[torch.Tensor, torch.Tensor]: |
| 1074 | """Encode input sequences. |
| 1075 | Args: |
| 1076 | x: Encoder input features. (B, T_in, F) |
| 1077 | x_len: Encoder input features lengths. (B,) |
| 1078 | Returns: |
| 1079 | x: Encoder outputs. (B, T_out, D_enc) |
| 1080 | x_len: Encoder outputs lenghts. (B,) |
| 1081 | """ |
| 1082 | short_status, limit_size = check_short_utt(self.embed.subsampling_factor, x.size(1)) |
| 1083 | |
| 1084 | if short_status: |
| 1085 | raise TooShortUttError( |
| 1086 | f"has {x.size(1)} frames and is too short for subsampling " |
| 1087 | + f"(it needs more than {limit_size} frames), return empty results", |
| 1088 | x.size(1), |
| 1089 | limit_size, |
| 1090 | ) |
| 1091 | |
| 1092 | mask = make_source_mask(x_len).to(x.device) |
| 1093 | |
| 1094 | if self.unified_model_training: |
| 1095 | if self.training: |
| 1096 | chunk_size = ( |
| 1097 | self.default_chunk_size |
| 1098 | + torch.randint(-self.jitter_range, self.jitter_range + 1, (1,)).item() |
| 1099 | ) |
| 1100 | else: |
| 1101 | chunk_size = self.default_chunk_size |
| 1102 | x, mask = self.embed(x, mask, chunk_size) |
| 1103 | pos_enc = self.pos_enc(x) |
| 1104 | chunk_mask = make_chunk_mask( |
| 1105 | x.size(1), |
| 1106 | chunk_size, |
| 1107 | left_chunk_size=self.left_chunk_size, |
| 1108 | device=x.device, |
| 1109 | ) |
| 1110 | x_utt = self.encoders( |
| 1111 | x, |
| 1112 | pos_enc, |
| 1113 | mask, |
| 1114 | chunk_mask=None, |
| 1115 | ) |
| 1116 | x_chunk = self.encoders( |
| 1117 | x, |
| 1118 | pos_enc, |
| 1119 | mask, |
| 1120 | chunk_mask=chunk_mask, |
| 1121 | ) |
| 1122 | |
| 1123 | olens = mask.eq(0).sum(1) |
| 1124 | if self.time_reduction_factor > 1: |
| 1125 | x_utt = x_utt[:, :: self.time_reduction_factor, :] |
| 1126 | x_chunk = x_chunk[:, :: self.time_reduction_factor, :] |
nothing calls this directly
no test coverage detected