spaCyTextBlob
Easy sentiment analysis for spaCy using TextBlob. Now supports spaCy 3.0!
Installation
First install spacytextblob from PyPi
pip install spacytextblob
TextBlob requires some data to be downloaded before getting started.
python -m textblob.download_corpora
spaCy requires that you download a model to get started.
python -m spacy download en_core_web_sm
Quick start
First add spaCyTextBlob to the spaCy pipeline
>>> import spacy
>>> from spacytextblob.spacytextblob import SpacyTextBlob
>>>
>>> nlp = spacy.load('en_core_web_sm')
>>> nlp.add_pipe("spacytextblob")
>>>
>>> # pipeline contains component name
>>> print(nlp.pipe_names)
['tok2vec', 'tagger', 'parser', 'ner', 'attribute_ruler', 'lemmatizer', 'spacytextblob']
Then run text through the nlp pipeline as you normally would
>>> text = "I had a really horrible day. It was the worst day ever!" >>> doc = nlp(text) >>> print('Polarity:', doc._.polarity) Polarity: -1.0 >>> print('Subjectivity:', doc._.subjectivity) Subjectivity: 1.0 >>> print('Assessments:', doc._.assessments) Assessments: [(['really', 'horrible'], -1.0, 1.0, None), (['worst', '!'], -1.0, 1.0, None)]