New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A question in crf.py #365
Comments
start字符和end字符的分数是单独通过start_scores和end_scores来计算的,因为在include_start_end_trans参数为False的时候,我们不考虑start和end字符,如果采用您说的这种方式,实现这个比较麻烦。所以我们就把start和end的分数计算从trans_scores中单独分离出来了。 |
谢谢您的回复。 替换为 |
感觉没有错位。这里应该是由于有两种不同的视角造成的,第一个视角是(我们的实现):[第i个字符的发射分数+第i个字符转移到第1个字符的分数]来得到第i个字符的分数,然后sum所有的i,这种做法会在最后一个时刻无法计算,因为最后一个时刻不再有i+1的跳转分数。第二个视角是(您的做法),就是[第i个字符的发射分数+(第i+1个字符的分数+第i个字符跳转到第i+1个字符的分数)],但实作的时候是通过把第0个单独拿出来(也就是您做法里面的emit_score[0]),然后sum所有的第i+1个字符的分数+第i个字符跳转到第i+1个字符的分数。这两种应该是等价的。 |
补充一下 @yhcc 的回答。对于一个长度为N的序列,有 N 个发射分数和 N-1 个转移分数 (N个点和中间N-1条边)。而我们求的 score 其实就是这些分数求和。因为是求和,所以先加谁后加谁都是可以的。您这里使用另一种方式实现了这个求和,理论上可以有很多种实现方式,都是等价的。 |
感谢您的解答 |
您好,我发现在decoder的crf.py的代码中,第263行是这样写的
score = trans_score + emit_score[:seq_len - 1, :]
其中的trans_score大小为[seq_len-1, batch_size],trans_score[0][0]代表第0个句子的第0个字符到第1个字符的转移得分;
而emit_score[:seq_len - 1, :]的大小为[seq_len-1, batch_size],emit_score[0, 0]代表第0个句子第0个字符的发射得分;
但是第0个句子第0个字符的转移得分不应该是start字符到第0个字符的score么?请问这里为什么不写成
score = trans_score + emit_score[1:, :]
呢感谢您的解答~
The text was updated successfully, but these errors were encountered: