Beispiel #1
0
 def get_tokens(self, idxs: torch.IntTensor) -> torch.LongTensor:
     idxs = (g[0] for g in it.groupby(idxs))
     if self.criterion_type == CriterionType.CTC:
         idxs = filter(lambda x: x != self.blank, idxs)
     elif self.criterion_type == CriterionType.ASG:
         idxs = filter(lambda x: x >= 0, idxs)
         idxs = unpack_replabels(list(idxs), self.tgt_dict,
                                 self.maxreplabel)
     return torch.LongTensor(list(idxs))
Beispiel #2
0
 def get_tokens(self, idxs):
     """Normalize tokens by handling CTC blank, ASG replabels, etc."""
     idxs = (g[0] for g in it.groupby(idxs))
     if self.criterion_type == CriterionType.CTC:
         idxs = filter(lambda x: x != self.blank, idxs)
     elif self.criterion_type == CriterionType.ASG:
         idxs = filter(lambda x: x >= 0, idxs)
         idxs = unpack_replabels(list(idxs), self.tgt_dict, self.max_replabel)
     return torch.LongTensor(list(idxs))