Skip to content
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

pytorch版本的softmax下206行的args.label2id['[SEP]'] #67

Open
hanxi0511 opened this issue Nov 2, 2021 · 6 comments
Open

pytorch版本的softmax下206行的args.label2id['[SEP]'] #67

hanxi0511 opened this issue Nov 2, 2021 · 6 comments
Assignees

Comments

@hanxi0511
Copy link

keyerror '[SEP]'

@linjun-pt
Copy link

我也遇到这个错误,怎么解决的?

@hanxi0511
Copy link
Author

hanxi0511 commented Nov 16, 2021

楼上没搞清楚在乱说,首先要搞清楚[SEP]是句子末尾的标记符号,其对应的label是[END],具体可在ner_seq.py 文件中看到。这里应该填写的是[SEP]对应的label,即[END],而不是直接填写[SEP]

我知道有start和end标签,但是softmax分类的模型在做评估的时候句子末尾是没有[END]的,在跑模型的时候设置[END]会无法判断句子结束从而导致不更新acc和re,评估结果都是0,我在做打印输出的时候看到了句子结尾都是补全的0,所以我才投机取巧默认遇到padding的0就是句子结束,我承认我这是投机取巧但是也不是乱说啊,我只是一个刚接触NLP的菜鸡研究生,只是把自己的解决办法说了出来我也不是故意在这坑人的

@pcx-pcx
Copy link

pcx-pcx commented Nov 17, 2021

楼上没搞清楚在乱说,首先要搞清楚[SEP]是句子末尾的标记符号,其对应的label是[END],具体可在ner_seq.py 文件中看到。这里应该填写的是[SEP]对应的label,即[END],而不是直接填写[SEP]

我知道有start和end标签,但是softmax分类的模型在做评估的时候句子末尾是没有[END]的,在跑模型的时候设置[END]会无法判断句子结束从而导致不更新acc和re,评估结果都是0,我在做打印输出的时候看到了句子结尾都是补全的0,所以我才投机取巧默认遇到padding的0就是句子结束,我承认我这是投机取巧但是也不是乱说啊,我只是一个刚接触NLP的菜鸡研究生,只是把自己的解决办法说了出来我也不是故意在这坑人的

不好意思哈,鲁莽了,请忽略我之前讲的话哈。其实这里metric要更新的话,条件应该是到real句子(未padding的句子)末尾最后一个token,也即[END],所以需要用到batch中的real句子长度信息,这个其实已经在batch[4]里面记录了,详细可以看ner_seq.py中的convert_examples_to_features函数和collate_fn函数的输出

@pcx-pcx
Copy link

pcx-pcx commented Nov 17, 2021 via email

@wuzhanglin123
Copy link

206行改成 elif j == batch[4].cpu().numpy().tolist()[i] - 1:

@JinFish
Copy link

JinFish commented Sep 15, 2022

代码里 token [SEP]对应的是O标签,当然找不到[SEP]标签。
tokens += [sep_token]
label_ids += [label_map['O']]
segment_ids = [sequence_a_segment_id] * len(tokens)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants