NLP_pytorch_project
NLP_pytorch_project copied to clipboard
crf调用报错
"crf.py", line 177, in _compute_score score = self.start_transitions[tags[0]] IndexError: index -100 is out of bounds for dimension 0 with size 5
上面是报错信息,但是-100 是label_id的padding值哦,理论上没啥问题吧。
score = self.start_transitions[tags[0]]
score += emissions[0, torch.arange(batch_size), tags[0]]
for i in range(1, seq_length):
# Transition score to next tag, only added if next timestep is valid (mask == 1)
# shape: (batch_size,)
score += self.transitions[tags[i - 1], tags[i]] * mask[i]
# Emission score for next tag, only added if next timestep is valid (mask == 1)
# shape: (batch_size,)
score += emissions[i, torch.arange(batch_size), tags[i]] * mask[i]
这部分代码中,为啥tags[0] 先不需要*mask[0] 再计算得分??