我正在使用训练 spacy NER 从简历中提取技能信息。但错误是
在 NER 模型中找不到名称为“U-SKILL”的过渡
训练数据:
[(u"我有 2 年的 Python 经验", {"entities": [(30, 35, "SKILL")]})]
代码 :
other_pipes = [pipe for pipe in nlp.pipe_names if pipe != "ner"]
with nlp.disable_pipes(*other_pipes):
optimizer = nlp.begin_training()
for i in range(10):
random.shuffle(train_data)
for text, annotations in train_data:
nlp.update([text], [annotations], sgd=optimizer)```
Error Traceback:
```Traceback (most recent call last):
File "<ipython-input-1-b5f869eaaf43>", line 1, in <module>
runfile('/home/abhishek/Desktop/Monster/Resume_Parser/MI_Resume/skills_ner.py', wdir='/home/abhishek/Desktop/Monster/Resume_Parser/MI_Resume')
File "/usr/lib/python3/dist-packages/spyder/utils/site/sitecustomize.py", line 705, in runfile
execfile(filename, namespace)
File "/usr/lib/python3/dist-packages/spyder/utils/site/sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "/home/abhishek/Desktop/Monster/Resume_Parser/MI_Resume/skills_ner.py", line 234, in <module>
nlp.update([text], [annotations], sgd=optimizer)
File "/home/abhishek/.local/lib/python3.6/site-packages/spacy/language.py", line 452, in update
proc.update(docs, golds, sgd=get_grads, losses=losses, **kwargs)
File "nn_parser.pyx", line 413, in spacy.syntax.nn_parser.Parser.update
File "nn_parser.pyx", line 516, in spacy.syntax.nn_parser.Parser._init_gold_batch
File "ner.pyx", line 106, in spacy.syntax.ner.BiluoPushDown.preprocess_gold
File "ner.pyx", line 165, in spacy.syntax.ner.BiluoPushDown.lookup_transition
KeyError: "[E022] Could not find a transition with the name 'U-SKILL' in the NER model."```
最佳答案
我最近在训练我自己的自定义 NER 模型时遇到了同样的错误消息。由于您没有显示整个代码片段,我不确定它是否是由同一问题引起的。就我而言,我在实体识别器中引入的新标签都是小写的,这实际上是一个非常愚蠢的错误。
for label in entity_types:
ner.add_label(label.upper())
一旦我使用
str.upper()
确保我添加的所有新标签都是大写的(即“技能”而不是“技能”),错误就消失了。 .您可能应该引用 https://spacy.io/usage/training#ner以及关于添加新实体类型的示例。
关于python-3.x - 使用 Spacy 训练 NER 从 Resume 中提取技能。过渡中的 U-entity_name 是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55726926/