def get_validation_minibatch(
    src, trg, index, batch_size, src_word2id, trg_word2id
):
    """Prepare minibatch.

    Args:
        src(list): source data.
        trg(list): target data.
        index(int): index for the file.
        batch_size(int): batch size.
        src_word2id(list): Word to index for source.
        trg_word2id(list): Word to index for target.

    Returns:
        Dict for seq2seq model.
    """
    src_lines = [
        ["<s>"] + line + ["</s>"] for line in src[index : index + batch_size]
    ]

    trg_lines = [
        ["<s>"] + line + ["</s>"] for line in trg[index : index + batch_size]
    ]

    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)

    input_lines_src = [
        [src_word2id[w] if w in src else src_word2id["<unk>"] for w in line]
        + [src_word2id["<pad>"]] * (max_src_len - len(line))
        for line in sorted_src_lines
    ]

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

    output_lines_trg = [
        [
            trg_word2id[w] if w in trg_word2id else trg_word2id["<unk>"]
            for w in line[1:]
        ]
        + [trg_word2id["<pad>"]] * (max_trg_len - len(line))
        for line in sorted_trg_lines
    ]
    # For pytroch 0.4
    with torch.no_grad():
        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)
        # ).squeeze().cuda()
        sorted_src_lens = (
            Variable(torch.LongTensor(sorted_src_lens))
            .view(len(sorted_src_lens))
            .cuda()
        )
    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:
        src(list): source data.
        trg(list): target data.
        index(int): index for the file.
        batch_size(int): batch size.
        src_word2id(list): Word to index for source.
        trg_word2id(list): Word to index for target.

    Returns:
        Dict for seq2seq model.
    
utils_nlp/models/gensen/utils.py