spacytextblob
A TextBlob sentiment analysis pipeline component for spaCy.
Install
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
Quick Start
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)]
Quick Reference
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._.blobSpan._.blobToken._.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.
Reference and Attribution
- TextBlob
- negspaCy (for inspiration in writing pipeline and organizing repo)
- spaCy custom components
Metadata
Release files for spacytextblob 5.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| spacytextblob-5.1.0.tar.gz | 3.2 kB | Without provenance | Details for spacytextblob-5.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| spacytextblob-5.1.0-py3-none-any.whl | Python 3 | none | any | Details for spacytextblob-5.1.0-py3-none-any.whl |
Total release size: 6.9 kB
Release files / spacytextblob-5.1.0.tar.gz
| Download URL | spacytextblob-5.1.0.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c551aa3bacf16f8a70295987fc76f2878b131f8b105d7fdb0becfb21155b5b2f
|
|
BLAKE2b-256 checksum How to use checksums |
039a9d4f7e6699d52fb7ef54bab26944436b631e16c67ff4d579766122dbc603
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.5
|
Release files / spacytextblob-5.1.0-py3-none-any.whl
| Download URL | spacytextblob-5.1.0-py3-none-any.whl |
|---|---|
| Size | 3.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
04d0fe5ce808db3258c3828916bf3c63363e7717d121128fa4b6745be751d743
|
|
BLAKE2b-256 checksum How to use checksums |
671e39107736635220947785e438b9bfbe7da94e6b39dfac27719ebb4e9424c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.5
|
Security for spacytextblob 5.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.