Example #1
0
def crf_mask(vocab, span_type, s_idx, e_idx, pad_idx=None):
    """Create a CRF mask.

    Returns a Tensor with valid transitions as a 0 and invalid as a 1 for easy use with `masked_fill`
    """
    np_mask = crf_m(vocab, span_type, s_idx, e_idx, pad_idx=pad_idx)
    return (torch.from_numpy(np_mask) == 0)
Example #2
0
def crf_mask(vocab, span_type, s_idx, e_idx, pad_idx=None):
    """Create a CRF Mask.

    Returns a mask with invalid moves as 0 and valid moves as 1.
    """
    return tf.constant(crf_m(vocab, span_type, s_idx, e_idx, pad_idx).T)