def pad(batch, fill=0):
    """ Pad a mini-batch of sequence samples to maximum length of this batch.

    :param batch: list of list
    :param fill: word index to pad, default 0.
    :return batch: a padded mini-batch
    """
    max_length = max([len(x) for x in batch])
    for idx, sample in enumerate(batch):
        if len(sample) < max_length:
            batch[idx] = sample + ([fill] * (max_length - len(sample)))
    return batch