always use constraint mask
@@ -91,7 +91,8 @@ class ConditionalRandomField(torch.nn.Module):
# _constraint_mask indicates valid transitions (based on supplied constraints).
if constraints is None:
- self._constraint_mask = None
+ # All transitions are valid.
+ constraint_mask = torch.Tensor(num_tags, num_tags).fill_(1.)
else:
constraint_mask = torch.Tensor(num_tags, num_tags).fill_(0.)
for i, j in constraints:
@@ -246,9 +247,6 @@ class ConditionalRandomField(torch.nn.Module):
transitions = torch.Tensor(num_tags + 2, num_tags + 2).fill_(-10000.)
# Apply transition constraints
- if self._constraint_mask is None:
- constrained_transitions = self.transitions
- else:
constrained_transitions = (self.transitions * self._constraint_mask +
-10000.0 * (1 - self._constraint_mask))
