def create_sequence(padding_mask, idx, pad_id=None):
    """
    Create a sequence filled with an index

    Args:
        padding_mask: padding mask of target sequence
        idx: filled value
        pad_id: index of pad

    Returns:
        - a long tensor that is of the same shape as padding_mask and filled with idx
    """
    seq = padding_mask.long()
    seq = seq.masked_fill(~padding_mask, idx)
    if pad_id is not None:
        seq = seq.masked_fill(padding_mask, pad_id)
    return seq