Python Shorts — NLP Sentiment Analysis and Text Summary
What if you could do sentiment analysis and text summaries with Python and NLP without the need of expensive APIs from Amazon or Google? It is possible with TextBlob.
Welcome to Python Shorts.
This tutorial series will provide you with quick and simple solutions for different needs of your Python projects and to improve your knowledge.
What is TextBlob ?
TextBlob is a Python library for processing textual data which can perform common natural language processing (NLP) tasks such as part-of-speech tagging, noun phrase extraction, sentiment analysis, classification, translation, and more.
Some of it’s features include:
- Noun phrase extraction
- Sentiment analysis
- Classification (Naive Bayes, Decision Tree)
- Tokenization (splitting text into words and sentences)
- Word and phrase frequencies
- Word inflection (pluralization and singularization) and lemmatization
- Spelling correction
That’s a lot of features for a very simple to use library.
For this tutorial we are going to use the sentiment analysis to analyze a couple of reviews and noun phrase extraction to summarize an article.
Installing TextBlob
To install the TextBlob we just need to run the normal pip install commands and an extra download for library components:
$ pip install textblob
$ python -m textblob.download_corporaUsing TextBlob for Sentiment Analysis
Using TextBlob for sentiment analysis is very simple.
All that is needed is to feed out TextBlob with each of our reviews and perform the sentiment analysis.
This will return a named tuple of polarity and subjectivity score.
The polarity score is a float within the range [-1.0, 1.0]. This will give us our general positive or negative sentiment.
So anything above 1.0 is a positive feeling and anything below 0 is a negative feeling.
The subjectivity is a float within the range [0.0, 1.0] where 0.0 is very objective and 1.0 is very subjective.
Let’s check out our simple code:






