Skip to main content

A TextBlob sentiment analysis pipeline component for spaCy.

Project description

spacytextblob

PyPI version pytest PyPI - Downloads Netlify Status

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._.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.

Reference and Attribution

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spacytextblob-5.0.0.tar.gz (246.4 kB view details)

Uploaded Source

Built Distribution

spacytextblob-5.0.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file spacytextblob-5.0.0.tar.gz.

File metadata

  • Download URL: spacytextblob-5.0.0.tar.gz
  • Upload date:
  • Size: 246.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.4.20

File hashes

Hashes for spacytextblob-5.0.0.tar.gz
Algorithm Hash digest
SHA256 4bd0a7c65a0144dd286d88fae4ee3ebf9a82c0502e39449afcfb79b03c88ffbe
MD5 ec06ceb766317458b32aa67a751374b2
BLAKE2b-256 1c257b1406a8b9465f2febf9b1ec4dfd7928405373685407a36dc1e19b94dc94

See more details on using hashes here.

File details

Details for the file spacytextblob-5.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for spacytextblob-5.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1c1a76bc4d6888093495a85df073c7f243c47265801acff92151b0749e086e0c
MD5 78669c04b595f46304b0de6134012344
BLAKE2b-256 b42f50045552f49b0fbb860852f733d9f94a7fe72cb2206a3e5ec7917c5ffd04

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page