首页 > 解决方案 > 使用 Spacy 训练 NER 从简历中提取技能。过渡中的 U-entity_name 是什么意思

问题描述

我正在使用训练 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."```

标签: python-3.xspacyinformation-extractionnamed-entity-recognition

解决方案


我最近在训练自己的自定义 NER 模型时遇到了同样的错误消息。由于您没有显示整个代码段,因此我不确定它是否是由同一问题引起的。就我而言,我在实体识别器中引入的新标签都是小写的,这实际上是一个非常愚蠢的错误。

for label in entity_types:
    ner.add_label(label.upper())

一旦我使用str.upper().

您可能还应该参考https://spacy.io/usage/training#ner以及添加新实体类型的示例。


推荐阅读