def pad_batch(batch, max_len=<NUM_LIT:0>, type="<STR_LIT:int>"):
batch_size = len(batch)<EOL>max_sent_len = int(np.max([len(x) for x in batch]))<EOL>if max_len > <NUM_LIT:0> and max_len < max_sent_len:<EOL><INDENT>max_sent_len = max_len<EOL><DEDENT>if type == "<STR_LIT:float>":<EOL><INDENT>idx_matrix = np.zeros((batch_size, max_sent_len), dtype=np.float32)<EOL><DEDENT>else:<EOL><INDENT>idx_matrix = np.zeros((batch_size, max_sent_len), dtype=np.int)<EOL><DEDENT>for idx1, i in enumerate(batch):<EOL><INDENT>for idx2, j in enumerate(i):<EOL><INDENT>if idx2 >= max_sent_len:<EOL><INDENT>break<EOL><DEDENT>idx_matrix[idx1, idx2] = j<EOL><DEDENT><DEDENT>idx_matrix = torch.tensor(idx_matrix)<EOL>mask_matrix = torch.tensor(torch.eq(idx_matrix.data, <NUM_LIT:0>))<EOL>return idx_matrix, mask_matrix<EOL>
Pad the batch into matrix

    :param batch: The data for padding.
    :type batch: list of word index sequences
    :param max_len: Max length of sequence of padding.
    :type max_len: int
    :param type: mask value type.
    :type type: str
    :return: The padded matrix and correspoing mask matrix.
    :rtype: pair of torch.Tensors with shape (batch_size, max_sent_len)