Python NLP
About Lesson

In this Python NLP lesson we are going to learn about Python NLP TextBlob library, as we have already learned about NLTK library, now you can do the same functionalities using TextBlob, so TextBlob is a Python (2 and 3) library for processing textual data. It provides a simple API for diving into common natural language processing (NLP) tasks such as part-of-speech tagging, noun phrase extraction, sentiment analysis, classification, translation, and more.

 

 

These are the features for TextBlob.

  • Noun phrase extraction
  • Part-of-speech tagging
  • Sentiment analysis
  • Classification (Naive Bayes, Decision Tree)
  • Tokenization (splitting text into words and sentences)
  • Word and phrase frequencies
  • Parsing
  • n-grams
  • Word inflection (pluralization and singularization) and lemmatization
  • Spelling correction
  • Add new models or languages through extensions
  • WordNet integration

 

 

Installation

First of all you need to install TextBlob, you can use pip for the installation.

 

 

Tokenization

So using tokenization we can break TextBlobs into words or sentences. so first let’s check word tokenization.

 

 

 

So in the above example we have used word tokenization, if you run the code this will be the result.

 

 

For the sentences tokenization you can use this code.

 

 

This will be the result.

 

 

 

Also you can make a word singular or plural in TextBlob.

 

 

 

Run the code this is the result.

 

 

Also you can do pluralize a word.

 

 

TextBlob Lemmatization

Now let’s work on lemmatization.

 

 

 

This will be the result.

 

 

Also we can give Parts of Speech in our lemmatize.

 

 

TextBlob Spell Correction

We can do spell correction in TextBlob.

 

 

TextBlob Noun Phrase Extraction

 

 

TextBlob Parts of Speech Tagging(POS)

Now we want to learn about POS tagging in TextBlox, Part-of-speech tags can be accessed through the tags property.

 

 

 

 

If you run the code this will be the result.

 

 

TextBlob N-Grams

As we have already learned that Ngrams are the combination of multiple words, now let’s create an example.

 

 

 

If you run the code you can see that we have two consecutive words.

 

 

 

TextBlob Sentiment Analysis

Sentiment Analysis is used as the process of determining the sentiments behind the character sequence, it may be used whether the speaker or the person expressing the textual thoughts is in happy or sad mode. the sentiment property returns a namedtuple of the form Sentiment(polarity, subjectivity). the polarity score is a float within the range [-1.0, 1.0]. The subjectivity is a float within the range [0.0, 1.0] where 0.0 is very objective and 1.0 is very subjective.

 

 

 

 

TextBlob Language Translation

Let’s create an example of language translation in textblob, in this code we have a Turkish text, first we want to detect the language.

 

 

If you run the code this will be the result.

 

 

Now we can translate this from Turkish to English.

 

 

This will be the result.

 

 

Thank you for visiting my website! If you enjoyed the free courses, please consider supporting my works on Patreon.
Exercise Files
No Attachment Found
No Attachment Found