Introduction to Sentiment Analysis Python Library : TextBlob

An Overview of Sentiment Analysis Python Library - TextBlob featured image

Once again today , DataScienceLearner is back with an awesome Natural Language Processing Library .If you are looking for an easy solution in sentiment extraction , You can not stop yourself from being excited . Yes ! We are here with an amazing article on sentiment Analysis Python Library TextBlob . If you read this article till ending  , You will be able to implement Sentiment extractor at your own  . So Lets enjoy the party –

Introduction to TextBlob

TextBlob is a python Library which stands on the NLTK .It works as a framework  for almost all necessary task , we need in Basic NLP ( Natural Language Processing ) . Apart from it , TextBlob  has some advance features like –

sentiment analysis python TextBlob
sentiment analysis python TextBlob

1.Sentiment Extraction

2.Spelling Correction

3.Translation and detection of Language .

Installation of TextBlob-

Installation is not a big deal here . If you are already using Anaconda , You have to run these command to install TextBlob .Go to Anaconda Prompt and enter

  1.           pip install -i https://pypi.anaconda.org/pypi/simple textblob-de
sentiment analysis python 2
sentiment analysis python 2

2.       You need to download corpus First to train the Model of TextBlob . You can achieve it using the following command-

 python -m textblob.download_corpora

sentiment analysis python 3
sentiment analysis python 3

You have end up with installation if you are using Anaconda.   If you want to install it from source (GitHub) or any other medium go for the detail documentation on TextBlob Installation Guide here.

Steps for Sentiment Analysis Python using TextBlob-

In General you need to train your Model for Any Machine Learning based Application whether it is NLP based or something else  . In this case for sentiment extraction , You have to follow so many meta steps like basic NLP ( Lemmatization , POS tagging , NER implementation ) followed by neural Network Training and implementation.You also need  plenty amount of Labled data set.

I think you are worried about data set  Right? . Do not worry TextBlob is here to automate all these steps here .Actually TextBlob provides  an already trend Model in the form of API .You can directly import it and use it as a function into your code .  In fact  if you need to look at the data set , Just remember the second command you run while installation –

python -m textblob.download_corpora

It downloads the corpus for training . Now I will explain you how can you use TextBlob into the your code-

To Import TextBlob python packages , You need a single line command for this.

>>>from textblob import TextBlob            // import of TextBlob Packages 

TextBlob has two sentiment analyzer . First is PatternAnalyzer and second is NaiveBayesAnalyzer . The default implementation is PatternAnalyzer but you can override it by passing the other implementation in constructor like this

 

sentiment analysis python code
sentiment analysis python code

using  the above written line  ( Sentiment Analysis Python code ) , You can achieve your sentiment score . 

sentiment analysis python code output
sentiment analysis python code output

The above image shows , How the TextBlob sentiment model provides the output .It gives the positive probability score and negative probability score . On the basis of this probability score , Machine can decide the classification boundary for classification .

Alright then Its time to make our hands dirty with basic NLP in TextBlob-

Tokenization –

sentiment analysis python code output
sentiment analysis python code output1

TextBlob can Tokenize the paragraphs into different sentences and words . I don’t thing apart from the above attached image , You do not need anything else to understand Tokenization .

Noun Phrases Extraction using TextBlob –

Noun is  basically name of person , things and various places . In most of the cases , We use it as Entity . It is also one the most important NLP utility in Dependency parsing .  Lets extract different nouns from a sentence using TextBlob –

sentiment analysis python code output2
sentiment analysis python code output 2

Part-of-Speech Tagging using TextBlob –

using ( TextBlob_Obj.tags) , you can easily Tag part of speech with your sentences . Here is the example for you –

sentiment analysis python code output3
sentiment analysis python code output 3

N-Grams with TextBlob –

Here N is basically a number . I mean,  N-Gram is basically chunk of words in group .For deep understanding of N -Gram , Lets have an example-

sentiment analysis python code output 4
sentiment analysis python code output 4

 

According to me , I have mentioned all important Tools , Functions and commands to run TextBlob for your NLP tasks . Apart from it if you need more explanation in any of the section , Just go for its official documentation TextBlog  .

Few Recommendation –

If you are  just a beginner in this stream , Go for two foundation article –

  1. How to become a Data scientist ?
  2. What is Machine Learning ?

These two article will clear all basic queries to this field .  In case of any assistance in Python , take the help from this easy article – ” Python essentials in 5 minutes

End Notes –

So we have covered End to end Sentiment Analysis Python code using TextBlob  .  Data set behind the TextBlob sentiment analysis is Movies reviews on Twitter .Social media is a good source for unstructured data these days  . Plenty of new post and tweets comes every minutes . Here if know NLP stuffs , You can convert these raw data into meaningful information .

For Customer service , Marketing research sentiment analysis is a major success  Tool . Accuracy is the  only challenge here . Any Machine Learning Model is not  perfect . So Data set designing is one of the important issue here . All Top Most Business companies are looking towards Artificial Intelligent into their Product and services . Google is changing the world with its powerful NLP strength . In the same time you can also use NLP techniques into your code with TextBlob .

TextBlog’s major strength is its easy syntax and documentation . Anyone can adopt it easily . You can also customize the Model of TextBlob  as per your requirement .

So guys How did you find this article ? In the end of the article , I request you to write your suggestion to improve this article . We appreciate our readers  for their  suggestions in our previous articles. If you find DataScienceLearner  interesting and easy to understand , Please subscribe us . You can also follow us on Twitter and like on FaceBook . We love to create updated content on data science and AI for you.  You can also suggest interesting future topics for article on Data science . We promise to write back for you .

Data Science Learner Team

Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for signup. A Confirmation Email has been sent to your Email Address.

Something went wrong.

Meet Abhishek ( Chief Editor) , a data scientist with major expertise in NLP and Text Analytics. He has worked on various projects involving text data and have been able to achieve great results. He is currently manages Datasciencelearner.com, where he and his team share knowledge and help others learn more about data science.
 
Thank you For sharing.We appreciate your support. Don't Forget to LIKE and FOLLOW our SITE to keep UPDATED with Data Science Learner