def sequence_mask(seq_ids, valid_lengths):
    """
    Args:
        seq_ids (Tensor):
            The whole sequence index, a tensor with a shape of [batch_size, sequence_length].
        valid_lengths (Tensor):
            The valid length of every sequence, a tensor with a shape of [batch_size].
    Returns:
        Tensor: Returns the output sequence mask `mask`.
        Its dtype is `bool` and has a shape of [batch_size, sequence_length].
    """
    lengths_exp = valid_lengths.unsqueeze(1)
    mask = seq_ids < lengths_exp

    return mask