MCPcopy Create free account
hub / github.com/apple/ml-pointersect / construct_last_vectors

Function construct_last_vectors

cdslib/core/nn/nn_utils.py:274–291  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

272
273
274def 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
294def construct_onehot_vectors(labels: torch.Tensor, total_classes: int) -> torch.Tensor:

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected