construct time-shifted version of the ground-truth to be used as teacher-forcing input where out[t] = gt_vector[t-1] :param gt_vectors: (seq_len, batch, dim_feature) :return: (seq_len, batch, dim_feature)
(gt_vectors, delay=1)
| 272 | |
| 273 | |
| 274 | def construct_last_vectors(gt_vectors, delay=1): |
| 275 | """ |
| 276 | construct time-shifted version of the ground-truth to be used as teacher-forcing input |
| 277 | where out[t] = gt_vector[t-1] |
| 278 | :param gt_vectors: (seq_len, batch, dim_feature) |
| 279 | :return: (seq_len, batch, dim_feature) |
| 280 | """ |
| 281 | |
| 282 | if delay == 0: |
| 283 | return gt_vectors # not cloned |
| 284 | |
| 285 | assert len(gt_vectors.shape) == 2 or len(gt_vectors.shape) == 3 |
| 286 | if len(gt_vectors.shape) == 2: |
| 287 | gt_vectors = gt_vectors.unsqueeze(2) |
| 288 | |
| 289 | out = torch.zeros_like(gt_vectors) |
| 290 | out[delay:] = gt_vectors[0:-delay] # cloned |
| 291 | return out |
| 292 | |
| 293 | |
| 294 | def construct_onehot_vectors(labels: torch.Tensor, total_classes: int) -> torch.Tensor: |
no outgoing calls
no test coverage detected