首页 > 解决方案 > 使用 cutom spacy ner 模型训练实体链接器模型时出错

问题描述

我已经用 spacy 的en_core_web_sm模型训练了一个实体链接器(EL)模型,没有任何问题。但是当我使用自定义 NER 模型训练 EL 模型时,我收到一条错误消息。我该如何解决这个问题?将“sentencizer”组件添加到管道并不能解决问题。

错误:

AttributeError: 'NoneType' object has no attribute 'as_doc'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\work\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\work\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy\__main__.py", line 45, in <module>
    cli.main()
  File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 430, in main
    run()
  File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 267, in run_file
    runpy.run_path(options.target, run_name=compat.force_str("__main__"))
  File "C:\Users\work\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "C:\Users\work\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "C:\Users\work\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\work\AppData\Local\Programs\Python\Python37\Spacy_NEL_Models\en_el_ambigue\en_el_ambigue\en_el_ambigue.py", line 123, in <module>
    nlp.update(texts, annotations, drop=0.2, losses = losses, sgd=optimizer,)
  File "C:\Users\work\AppData\Local\Programs\Python\Python37\lib\site-packages\spacy\language.py", line 519, in update
    proc.update(docs, golds, sgd=get_grads, losses=losses, **kwargs)
  File "pipes.pyx", line 1237, in spacy.pipeline.pipes.EntityLinker.update
RuntimeError: [E030] Sentence boundaries unset. You can add the 'sentencizer' component to the pipeline with: nlp.add_pipe(nlp.create_pipe('sentencizer')) Alternatively, add the dependency parser, or set sentence boundaries by setting doc[i].is_sent_start.

标签: spacy

解决方案


推荐阅读