SamEdwardes / spacytextblob

A TextBlob sentiment analysis pipeline component for spaCy.
https://spacytextblob.netlify.app/
MIT License
54 stars 8 forks source link

Can't retrieve unregistered extension attribute 'blob'. #19

Open dsm-72 opened 2 years ago

dsm-72 commented 2 years ago

Copy pasted from tutorial

import spacy
from spacytextblob.spacytextblob import SpacyTextBlob

nlp = spacy.load('en_core_web_sm')
nlp.add_pipe('spacytextblob')
text = 'I had a really horrible day. It was the worst day ever! But every now and then I have a really good day that makes me happy.'
doc = nlp(text)
doc._.blob.polarity                            # Polarity: -0.125
doc._.blob.subjectivity                        # Subjectivity: 0.9
doc._.blob.sentiment_assessments.assessments   # Assessments: [(['really', 'horrible'], -1.0, 1.0, None), (['worst', '!'], -1.0, 1.0, None), (['really', 'good'], 0.7, 0.6000000000000001, None), (['happy'], 0.8, 1.0, None)]
doc._.blob.ngrams() 
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-30-b84122143817> in <module>
      6 text = 'I had a really horrible day. It was the worst day ever! But every now and then I have a really good day that makes me happy.'
      7 doc = nlp(text)
----> 8 doc._.blob.polarity                            # Polarity: -0.125
      9 doc._.blob.subjectivity                        # Subjectivity: 0.9
     10 doc._.blob.sentiment_assessments.assessments   # Assessments: [(['really', 'horrible'], -1.0, 1.0, None), (['worst', '!'], -1.0, 1.0, None), (['really', 'good'], 0.7, 0.6000000000000001, None), (['happy'], 0.8, 1.0, None)]

/opt/anaconda/anaconda3/envs/venv/lib/python3.6/site-packages/spacy/tokens/underscore.py in __getattr__(self, name)
     45     def __getattr__(self, name: str) -> Any:
     46         if name not in self._extensions:
---> 47             raise AttributeError(Errors.E046.format(name=name))
     48         default, method, getter, setter = self._extensions[name]
     49         if getter is not None:

AttributeError: [E046] Can't retrieve unregistered extension attribute 'blob'. Did you forget to call the `set_extension` method?
SamEdwardes commented 2 years ago

Can you please confirm the version of spacytextblob that you are using? From the command line you can run:

pip list

Note that ._.blob is new as of version 4.0.0 (https://spacytextblob.netlify.app/changelog/).

dsm-72 commented 2 years ago

@SamEdwardes I just pip installed it so assume latest? but turns out 3.0.1

SamEdwardes commented 2 years ago

Ok make sure you are using 4.0.0 and it should work. Does it work after upgrading?