I find that in the code of crf.py the parameter _constrain is initialized by the code.
I think the code is below:
if allowed_transitions is None:
constrain = torch.zeros(num_tags + 2, num_tags + 2)
else:
constrain = torch.full((num_tags + 2, num_tags + 2), fill_value=-10000.0, dtype=torch.float)
has_start = False
has_end = False
for from_tag_id, to_tag_id in allowed_transitions:
constrain[from_tag_id, to_tag_id] = 0
if from_tag_id==num_tags:
has_start = True
if to_tag_id==num_tags+1:
has_end = True
if not has_start:
constrain[num_tags, :].fill_(0)
if not has_end:
constrain[:, num_tags+1].fill_(0)
self._constrain = nn.Parameter(constrain, requires_grad=False)
But the parameters of crf.py are initialized by this line of code. It seems that the parameter _constrain would be initialized again and be overwritten by the new value.
I find that in the code of crf.py the parameter
_constrain
is initialized by the code.I think the code is below:
But the parameters of
crf.py
are initialized by this line of code. It seems that the parameter_constrain
would be initialized again and be overwritten by the new value.I guess the code of the initializing method is below:
Is it logical?