def pad(input_seqs, sequence_lengths, pad_token=0, pad_len=None):
    """
    Pad a batch to max_sequence_length along the second dimension
    Args:
        • input_seqs: a list of sequences
        • sequence_lengths: a list of sequence length
        • pad_token: token used for padding
        • pad_len: maximum lengths to be padded to
    Returns:
        • padded
    """
    if pad_len:
        max_length = pad_len
    else:
        max_length = max(sequence_lengths)
    padded = [input_seq + [pad_token] * (max_length - sequence_length) 
              for (input_seq, sequence_length)
              in zip(input_seqs, sequence_lengths)]
    return padded