DerwenAI/pytextrank

Support with SpaCy 3.0

Lord-V15 opened this issue ยท 4 comments

Hey there, I use PyTextRank in my algorithm as a pipeline added to SpaCy.
Recently, SpaCy 3.0 was launched and I am trying to add this as a pipeline but am getting the following error :

ValueError: [E966] `nlp.add_pipe` now takes the string name of the registered component factory, not a callable component. Expected string, but got <bound method TextRank.PipelineComponent of <pytextrank.pytextrank.TextRank object at 0x7fe29710cee0>> (name: 'textrank').

- 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.

Can anyone help me understand how do I use the pytextrank.TextRank.PipelineComponent as a custom language component in spaCy 3.0 ?
I could downgrade to SpaCy 2.x but I'll have to upgrade at some point in the future.

Anyway, for others interested in this issue, here is the official way in the new method to add custom pipeline for textrank in SpaCy 3.0.x :

from spacy.language import Language
@Language.component("textrank")
def textrank(doc):
    tr = pytextrank.TextRank()
    doc = tr.PipelineComponent(doc)
    return doc
nlp.add_pipe("textrank", last=True)

@ceteri can you add this in the readme as the official way of adding textrank pipeline for SpaCy 3.0 as the older method doesn't work anymore. ๐Ÿ˜„

Thank you so much @Lord-V15 this helps lots!
I was just about to dive into updates for spaCy 3.0.x ๐Ÿ˜…

Developing spaCy 3.0 support now in the update branch, as WIP toward pytextrank v3.0