0

此代码在使用 Spacy 2.3.1 时按预期工作,但在使用 Spacy 3.0.1 时在第三行抛出异常(我们还将 scispacy 从 .0.2.5 更新到 0.4.0:

entity_linker = UmlsEntityLinker(resolve_abbreviations=True)
nlp = spacy.load('en_core_sci_sm')
nlp.add_pipe(entity_linker)

例外是:

/scispacy/label_text/ [E966] 处的 ValueErrornlp.add_pipe现在采用已注册组件工厂的字符串名称,而不是可调用组件。预期的字符串,但在 0x000001B5297A7610> 处得到 <scispacy.linking.EntityLinker 对象>(名称:“无”)。

  • 如果您使用以下命令创建了组件nlp.create_pipe('name'):删除 nlp.create_pipe 并nlp.add_pipe('name')改为调用。

  • 如果您传入了一个组件,例如TextCategorizer()nlp.add_pipe使用字符串名称调用,例如 nlp.add_pipe('textcat')

  • 如果您正在使用自定义组件:将装饰器@Language.component(用于功能组件)或@Language.factory (用于类组件/工厂)添加到您的自定义组件并为其分配一个名称,例如@Language.component('your_name'). 然后,您可以运行 nlp.add_pipe('your_name')以将其添加到管道中。

我没有使用自定义组件。建议?

4

1 回答 1

1

UmlsEntityLinker确实是来自scispacy.

看起来 v3 等效项是:

nlp.add_pipe("scispacy_linker", config={"resolve_abbreviations": True, "linker_name": "umls"})

请参阅:https ://github.com/allenai/scispacy#example-usage-1

于 2021-03-08T10:36:32.383 回答