NLP_pytorch_project icon indicating copy to clipboard operation
NLP_pytorch_project copied to clipboard

crf调用报错

Open RileyShe opened this issue 2 years ago • 0 comments

"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] 再计算得分??

RileyShe avatar Mar 23 '22 07:03 RileyShe