Exemple #1
0
 def __call__(self, batch):
     inputs, targets, domains = self.get_inputs_and_targets(batch)
     inputs = self.pad(inputs)
     inputs = mktensor(inputs, device=self.device, dtype=torch.long)
     targets = mktensor(targets, device=self.device, dtype=torch.long)
     domains = mktensor(domains, device=self.device, dtype=torch.long)
     return inputs, targets.to(self.device), domains.to(self.device)
Exemple #2
0
 def __call__(self, batch):
     inputs, targets = self.get_inputs_and_targets(batch)
     inputs, _, segments, attention_masks = self.pad_and_mask(inputs)
     inputs = mktensor(inputs, device=self.device, dtype=torch.long)
     targets = mktensor(targets, device=self.device, dtype=torch.long)
     segments = mktensor(segments, device=self.device, dtype=torch.long)
     attention_masks = mktensor(attention_masks,
                                device=self.device,
                                dtype=torch.long)
     return inputs, targets.to(self.device), segments.to(
         self.device), attention_masks.to(self.device)
Exemple #3
0
 def __call__(self, batch):
     inputs, targets = map(list, zip(*batch))
     lengths = torch.tensor([len(s) for s in inputs], device=self.device)
     # Pad and convert to tensor
     inputs = (pad_sequence(inputs,
                            batch_first=True,
                            padding_value=self.pad_indx).to(self.device))
     targets = mktensor(targets, device=self.device, dtype=torch.long)
     return inputs, targets.to(self.device), lengths
    def __call__(self, batch):
        inputs, titles, targets = map(list, zip(*batch))
        number_of_sentences = torch.tensor([len(s) for s in inputs], device=self.device)
        length_of_sentences = ([torch.tensor([len(s) for s in inp]) for inp in inputs])

        inputs = [pad_sequence1(i, padding_len=150, batch_first=True, padding_value=0) for i in inputs]


        # Pad and convert to tensor
        inputs = (pad_sequence(inputs,
                               batch_first=True,
                               padding_value=self.pad_indx)
                  .to(self.device))
        length_of_sentences = pad_sequence1(length_of_sentences, padding_len=inputs.shape[1], batch_first=True, padding_value=1)
        
        lengths_title = torch.tensor([len(t) for t in titles], device=self.device)
        titles = (pad_sequence(titles,
                               batch_first=True,
                               padding_value=self.pad_indx)
                  .to(self.device))

        targets = mktensor(targets, device=self.device, dtype=torch.long)
        return inputs, titles, targets.to(self.device), number_of_sentences, length_of_sentences, lengths_title
Exemple #5
0
 def __call__(self, x):
     return mktensor(x, device=self.device, dtype=self.dtype)