Forward pass for training. Args: text: Text tensor or string input. punc: TODO. text_lengths: Length of each text sample. punc_lengths: Lengths of punc. vad_indexes: TODO. vad_indexes
(
self,
text: torch.Tensor,
punc: torch.Tensor,
text_lengths: torch.Tensor,
punc_lengths: torch.Tensor,
vad_indexes: Optional[torch.Tensor] = None,
vad_indexes_lengths: Optional[torch.Tensor] = None,
)
| 260 | return nll, text_lengths |
| 261 | |
| 262 | def forward( |
| 263 | self, |
| 264 | text: torch.Tensor, |
| 265 | punc: torch.Tensor, |
| 266 | text_lengths: torch.Tensor, |
| 267 | punc_lengths: torch.Tensor, |
| 268 | vad_indexes: Optional[torch.Tensor] = None, |
| 269 | vad_indexes_lengths: Optional[torch.Tensor] = None, |
| 270 | ): |
| 271 | """Forward pass for training. |
| 272 | |
| 273 | Args: |
| 274 | text: Text tensor or string input. |
| 275 | punc: TODO. |
| 276 | text_lengths: Length of each text sample. |
| 277 | punc_lengths: Lengths of punc. |
| 278 | vad_indexes: TODO. |
| 279 | vad_indexes_lengths: Lengths of vad_indexes. |
| 280 | """ |
| 281 | nll, y_lengths = self.nll(text, punc, text_lengths, punc_lengths, vad_indexes=vad_indexes) |
| 282 | ntokens = y_lengths.sum() |
| 283 | loss = nll.sum() / ntokens |
| 284 | stats = dict(loss=loss.detach()) |
| 285 | |
| 286 | # force_gatherable: to-device and to-tensor if scalar for DataParallel |
| 287 | loss, stats, weight = force_gatherable((loss, stats, ntokens), loss.device) |
| 288 | return loss, stats, weight |
| 289 | |
| 290 | def inference( |
| 291 | self, |
nothing calls this directly
no test coverage detected