从 Spacy 2.3.1 迁移到 3.0.1

Migrating from Spacy 2.3.1 to 3.0.1

此代码在使用 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)

例外情况是:

ValueError at /scispacy/label_text/ [E966] nlp.add_pipe now takes the string name of the registered component factory, not a callable component. Expected string, but got <scispacy.linking.EntityLinker object at 0x000001B5297A7610> (name: 'None').

  • If you created your component with nlp.create_pipe('name'): remove nlp.create_pipe and call nlp.add_pipe('name') instead.

  • If you passed in a component like TextCategorizer(): call nlp.add_pipe with the string name instead, e.g. nlp.add_pipe('textcat').

  • If you're using a custom component: Add the decorator @Language.component (for function components) or @Language.factory (for class components / factories) to your custom component and assign it a name, e.g. @Language.component('your_name'). You can then run nlp.add_pipe('your_name') to add it to the pipeline.

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

UmlsEntityLinker 确实是来自 scispacy 的自定义组件。

看起来 v3 等效项是:

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

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