dmmiller612 / bert-extractive-summarizer

Easy to use extractive text summarization with BERT
MIT License
1.38k stars 305 forks source link

ValueError: [E966] `nlp.add_pipe` now takes the string name of the registered component factory, not a callable component. #95

Closed maky-hnou closed 3 years ago

maky-hnou commented 3 years ago

I just installed bert-extractive-summarizer using pip install bert-extractive-summarizer (Python3).
Then I wanted to try some examples, I run this command from summarizer import Summarizer But I got this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/lenovo/.virtualenvs/nlp/lib/python3.6/site-packages/summarizer/__init__.py", line 1, in <module>
    from summarizer.model_processors import Summarizer, TransformerSummarizer
  File "/home/lenovo/.virtualenvs/nlp/lib/python3.6/site-packages/summarizer/model_processors.py", line 11, in <module>
    class ModelProcessor(object):
  File "/home/lenovo/.virtualenvs/nlp/lib/python3.6/site-packages/summarizer/model_processors.py", line 27, in ModelProcessor
    sentence_handler: SentenceHandler = SentenceHandler(),
  File "/home/lenovo/.virtualenvs/nlp/lib/python3.6/site-packages/summarizer/sentence_handler.py", line 10, in __init__
    self.nlp.add_pipe(self.nlp.create_pipe('sentencizer'))
  File "/home/lenovo/.virtualenvs/nlp/lib/python3.6/site-packages/spacy/language.py", line 748, in add_pipe
    raise ValueError(err)
ValueError: [E966] `nlp.add_pipe` now takes the string name of the registered component factory, not a callable component. Expected string, but got <spacy.pipeline.sentencizer.Sentencizer object at 0x7fd8702b3b48> (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.

Here are the packages that are already installed alongside with bert-extractive-summarizer:

bert-extractive-summarizer==0.6.1
blis==0.7.4
bpemb==0.3.2
breadability==0.1.20
catalogue==2.0.1
certifi==2020.12.5
chardet==4.0.0
click==7.1.2
cloudpickle==1.6.0
contextvars==2.4
cycler==0.10.0
cymem==2.0.5
dataclasses==0.8
decorator==4.4.2
Deprecated==1.2.11
docopt==0.6.2
filelock==3.0.12
flair==0.7
fr-core-news-lg @ https://github.com/explosion/spacy-models/releases/download/fr_core_news_lg-3.0.0/fr_core_news_lg-3.0.0-py3-none-any.whl
fr-core-news-md @ https://github.com/explosion/spacy-models/releases/download/fr_core_news_md-3.0.0/fr_core_news_md-3.0.0-py3-none-any.whl
fr-core-news-sm @ https://github.com/explosion/spacy-models/releases/download/fr_core_news_sm-3.0.0/fr_core_news_sm-3.0.0-py3-none-any.whl
fr-dep-news-trf @ https://github.com/explosion/spacy-models/releases/download/fr_dep_news_trf-3.0.0/fr_dep_news_trf-3.0.0-py3-none-any.whl
ftfy==5.8
future==0.18.2
gdown==3.12.2
gensim==3.8.3
hyperopt==0.2.5
idna==2.10
immutables==0.14
importlib-metadata==3.4.0
Janome==0.4.1
Jinja2==2.11.3
joblib==1.0.0
kiwisolver==1.3.1
konoha==4.6.2
langdetect==1.0.8
lxml==4.6.2
MarkupSafe==1.1.1
matplotlib==3.3.4
mpld3==0.3
murmurhash==1.0.5
networkx==2.5
nltk==3.5
numpy==1.19.5
overrides==3.0.0
packaging==20.9
pathy==0.3.4
Pillow==8.1.0
preshed==3.0.5
protobuf==3.14.0
pycountry==20.7.3
pydantic==1.7.3
pyparsing==2.4.7
PySocks==1.7.1
python-dateutil==2.8.1
regex==2020.11.13
requests==2.25.1
sacremoses==0.0.43
scikit-learn==0.24.1
scipy==1.5.4
segtok==1.5.10
sentencepiece==0.1.91
six==1.15.0
smart-open==3.0.0
spacy==3.0.0
spacy-alignments==0.7.2
spacy-legacy==3.0.1
spacy-transformers==1.0.1
sqlitedict==1.7.0
srsly==2.4.0
sumy==0.8.1
tabulate==0.8.7
thinc==8.0.1
threadpoolctl==2.1.0
tokenizers==0.9.3
torch==1.7.1
torchcontrib==0.0.2
tqdm==4.56.0
transformers==3.5.1
typer==0.3.2
typing-extensions==3.7.4.3
urllib3==1.26.3
wasabi==0.8.2
wcwidth==0.2.5
wrapt==1.12.1
zipp==3.4.0

Could it be an incompatibility with the new spacy version?

127 commented 3 years ago

Have the same issue

AMahfodh commented 3 years ago

Encountered the same issue, which's due to using a newer version of spaCy v3 instead of v2. I've locally fixed the error with two minor changes in coreference_handler.py under the directory (../site-packages/summarizer).

Just modify lines 10 & 24 as follows:

self.nlp.add_pipe(self.nlp.create_pipe('sentencizer')) to

self.nlp.add_pipe("sentencizer")

return [c.string.strip() for c in doc.sents if max_length > len(c.string.strip()) > min_length] to

return [c.text.strip() for c in doc.sents if max_length > len(c.text.strip()) > min_length]

Hope this help

fcernafukuzaki commented 3 years ago

@AMahfodh I changed file "sentence_handler.py" in the same directory and it works for me.

GuilleVENT commented 3 years ago

I haven't been able to solve this. Can you guys push an update with support for spacy v3? @AMahfodh

dmmiller612 commented 3 years ago

This has been on my list, but not really sure how to proceed, due to some libraries not being compatible with spacy 3.0 (like neural coref). I can update the sentence handler for now to try to work with 3.0 and fall back to 2.0.

dmmiller612 commented 3 years ago

Master currently has spacy 3 support as of this afternoon. I will push to pypi soon.

dmmiller612 commented 3 years ago

It has now been merged to pypi. To use, install bert-extractive-summarizer==0.7.0

maky-hnou commented 3 years ago

Thank you @dmmiller612