Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
A TextBlob sentiment analysis pipeline component for spaCy.
Install spacytextblob from PyPi.
pip install spacytextblob
TextBlob requires additional data to be downloaded before getting started.
python -m textblob.download_corpora
spaCy also requires that you download a model to get started.
python -m spacy download en_core_web_sm
spacytextblob allows you to access all of the attributes created of the textblob.TextBlob
class but within the spaCy framework. The code below will demonstrate how to use spacytextblob on a simple string.
import spacy
from spacytextblob.spacytextblob import SpacyTextBlob
nlp = spacy.load('en_core_web_sm')
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."
nlp.add_pipe("spacytextblob")
doc = nlp(text)
print(doc._.blob.polarity)
# -0.125
print(doc._.blob.subjectivity)
# 0.9
print(doc._.blob.sentiment_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)]
In comparison, here is how the same code would look using TextBlob
:
from textblob import TextBlob
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."
blob = TextBlob(text)
print(blob.sentiment_assessments.polarity)
# -0.125
print(blob.sentiment_assessments.subjectivity)
# 0.9
print(blob.sentiment_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)]
spacytextblob performs sentiment analysis using the TextBlob library. Adding spacytextblob to a spaCy nlp pipeline creates a new extension attribute for the Doc
, Span
, and Token
classes from spaCy.
Doc._.blob
Span._.blob
Token._.blob
The ._.blob
attribute contains all of the methods and attributes that belong to the textblob.TextBlob
class Some of the common methods and attributes include:
._.blob.polarity
: a float within the range [-1.0, 1.0].._.blob.subjectivity
: a float within the range [0.0, 1.0] where 0.0 is very objective and 1.0 is very subjective.._.blob.sentiment_assessments.assessments
: a list of polarity and subjectivity scores for the assessed tokens.See the textblob docs for the complete listing of all attributes and methods that are available in ._.blob
.
FAQs
A TextBlob sentiment analysis pipeline component for spaCy.
We found that spacytextblob demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.