def get_parallel_minibatch(
        self, corpus_idx, index, batch_size, max_len_src, max_len_trg
    ):
        """Prepare minibatch.

        Args:
            corpus_idx(int): Corpus Index.
            index(int): Index.
            batch_size(int): Batch Size.
            max_len_src(int): Max length for resource.
            max_len_trg(int): Max length ofr target.

        Returns: minibatch of src-trg pairs(dict).

        """
        src_lines = [
            ["<s>"] + line[: max_len_src - 2] + ["</s>"]
            for line in self.src[corpus_idx]["data"][
                index : index + batch_size
            ]
        ]

        trg_lines = [
            ["<s>"] + line[: max_len_trg - 2] + ["</s>"]
            for line in self.trg[corpus_idx]["data"][
                index : index + batch_size
            ]
        ]

        """Sort sentences by decreasing length within a minibatch for
        `torch.nn.utils.packed_padded_sequence`"""
        src_lens = [len(line) for line in src_lines]
        sorted_indices = np.argsort(src_lens)[::-1]

        sorted_src_lines = [src_lines[idx] for idx in sorted_indices]
        sorted_trg_lines = [trg_lines[idx] for idx in sorted_indices]

        sorted_src_lens = [len(line) for line in sorted_src_lines]
        sorted_trg_lens = [len(line) for line in sorted_trg_lines]

        max_src_len = max(sorted_src_lens)
        max_trg_len = max(sorted_trg_lens)

        # Map words to indices
        input_lines_src = [
            [
                self.src[corpus_idx]["word2id"][w]
                if w in self.src[corpus_idx]["word2id"]
                else self.src[corpus_idx]["word2id"]["<unk>"]
                for w in line
            ]
            + [self.src[corpus_idx]["word2id"]["<pad>"]]
            * (max_src_len - len(line))
            for line in sorted_src_lines
        ]

        input_lines_trg = [
            [
                self.trg[corpus_idx]["word2id"][w]
                if w in self.trg[corpus_idx]["word2id"]
                else self.trg[corpus_idx]["word2id"]["<unk>"]
                for w in line[:-1]
            ]
            + [self.trg[corpus_idx]["word2id"]["<pad>"]]
            * (max_trg_len - len(line))
            for line in sorted_trg_lines
        ]

        output_lines_trg = [
            [
                self.trg[corpus_idx]["word2id"][w]
                if w in self.trg[corpus_idx]["word2id"]
                else self.trg[corpus_idx]["word2id"]["<unk>"]
                for w in line[1:]
            ]
            + [self.trg[corpus_idx]["word2id"]["<pad>"]]
            * (max_trg_len - len(line))
            for line in sorted_trg_lines
        ]

        # Cast lists to torch tensors
        input_lines_src = Variable(torch.LongTensor(input_lines_src)).cuda()
        input_lines_trg = Variable(torch.LongTensor(input_lines_trg)).cuda()
        output_lines_trg = Variable(torch.LongTensor(output_lines_trg)).cuda()
        sorted_src_lens = (
            Variable(torch.LongTensor(sorted_src_lens), volatile=True)
            .squeeze()
            .cuda()
        )

        # Return minibatch of src-trg pairs
        return {
            "input_src": input_lines_src,
            "input_trg": input_lines_trg,
            "output_trg": output_lines_trg,
            "src_lens": sorted_src_lens,
            "type": "seq2seq",
        }
Prepare minibatch.

        Args:
            corpus_idx(int): Corpus Index.
            index(int): Index.
            batch_size(int): Batch Size.
            max_len_src(int): Max length for resource.
            max_len_trg(int): Max length ofr target.

        Returns: minibatch of src-trg pairs(dict).

        
utils_nlp/models/gensen/utils.py