Phil O
Phil O

Reputation: 1668

Migrating from Spacy 2.3.1 to 3.0.1

This code works as expected when using Spacy 2.3.1, but throws an exception on the third line when using Spacy 3.0.1 (we also updated scispacy from .0.2.5 to 0.4.0:

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

The exception is:

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.

I'm not using custom components. Suggestions?

Upvotes: 0

Views: 553

Answers (1)

aab
aab

Reputation: 11474

UmlsEntityLinker is indeed a custom component from scispacy.

It looks like the v3 equivalent is:

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

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

Upvotes: 1

Related Questions