def transition_mask(vocab, span_type, s_idx, e_idx, pad_idx=None): """Create a mask to enforce span sequence transition constraints. Returns a Tensor with valid transitions as a 0 and invalid as a 1 for easy use with `masked_fill` """ np_mask = transition_mask_np(vocab, span_type, s_idx, e_idx, pad_idx=pad_idx) return torch.from_numpy(np_mask) == 0
def transition_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. """ mask = transition_mask_np(vocab, span_type, s_idx, e_idx, pad_idx).T inv_mask = (mask == 0).astype(np.float32) return tf.constant(mask), tf.constant(inv_mask)
def transition_mask(vocab, span_type, s_idx, e_idx, pad_idx): mask = transition_mask_np(vocab, span_type, s_idx, pad_idx) inv_mask = (mask == 0).astype(np.float32) return mask, inv_mask