def prepare(self, samples_list, gpu=False):
        """Add start_letter to samples as inp, target same as samples"""
        all_samples = torch.cat(samples_list, dim=0).long()
        target = all_samples
        inp = torch.zeros(all_samples.size()).long()
        inp[:, 0] = self.start_letter
        inp[:, 1:] = target[:, :self.max_seq_len - 1]

        label = torch.zeros(all_samples.size(0)).long()
        for idx in range(len(samples_list)):
            start = sum([samples_list[i].size(0) for i in range(idx)])
            label[start: start + samples_list[idx].size(0)] = idx

        # shuffle
        perm = torch.randperm(inp.size(0))
        inp = inp[perm].detach()
        target = target[perm].detach()
        label = label[perm].detach()

        if gpu:
            return inp.cuda(), target.cuda(), label.cuda()
        return inp, target, label
Add start_letter to samples as inp, target same as samples
utils/cat_data_loader.py