python-3.x - 使用 Spacy 训练 NER 从 Resume 中提取技能。过渡中的 U-entity_name 是什么意思

标签 python-3.x spacy information-extraction named-entity-recognition

我正在使用训练 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/

相关文章:

python - 如何在网站上运行 python 脚本?

python-3.x - 在 python 中使用协程。如何链接两个协程

python-3.x - 使用 Spacy Textcat 自定义损失函数

python - Spacy无法安装在使用pypy创建的virtualenv中

python正则表达式或单个字符与spacy模式匹配

python-3.x - 在python包中查找某些方法和函数的所有用法

python - Twitch IRC 聊天机器人成功连接但未检测到命令

nlp - 人与城市/州的关系抽取

python - PDF Parsing Using Python - 提取格式化文本和纯文本

python - 使用 Python 从文本中提取信息到结构化数据