import torch


def get_mask(seq_len, lengths):
    """
        Get pad mask
        :param seq_len: int, padded length of data tensor
        :param lengths: Tensor of long (batch_size), valid length of each data tensor
        :returns: Tensor of bool (batch_size, seq_len), False means data, and True means pad
            [F F F T T T]
    """
    device = lengths.device
    # batch_size
    batch_size = lengths.size(0)
    # seq_len
    pos_index = torch.arange(seq_len).to(device)
    # batch_size * seq_len
    mask = pos_index.unsqueeze(0).expand(batch_size, -1) >= lengths.unsqueeze(-1)
    return mask