0
$\begingroup$

How to properly perform sentiment analysis for text with 300-600 words? If I use TextBlob and clean my data and remove stopwords(extended words and comma backslash..etc) do I need to tokenize the text into sentence then into words then perform lemmatization then apply textblob to lemmatize data? because I think I read somewhere that textblob do all of these as well as pos tag when calling TextBlob() ?

$\endgroup$

1 Answer 1

0
$\begingroup$

A rule-based approach is a practical approach to analyzing text without training or using machine learning models. The result of this approach is a set of rules based on which the text is labelled as positive/negative/neutral. These rules are also known as lexicons. Hence, the Rule-based approach is called Lexicon based approach.

Widely used lexicon-based approaches are TextBlob, VADER, SentiWordNet.

Textblob

It is a simple python library that offers API access to different NLP tasks such as sentiment analysis, spelling correction, etc.

Textblob sentiment analyzer returns two properties for a given input sentence:

  • Polarity is a float that lies between [-1,1], -1 indicates negative sentiment and +1 indicates positive sentiments.
  • Subjectivity is also a float that lies in the range of [0,1]. Subjective sentences generally refer to personal opinion, emotion, or judgment.

because I think I read somewhere that textblob do all of these as well as pos tag when calling TextBlob() ?

And yes without any preprocessing, you can apply textblob or vader pre-trained models

from textblob import TextBlob

testimonial = TextBlob("The food was great!")
print(testimonial.sentiment)
Sentiment(polarity=1.0, subjectivity=0.75)
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer


analyzer = SentimentIntensityAnalyzer()
sentence = "The food was great!" 
vs = analyzer.polarity_scores(sentence)
print("{:-<65} {}".format(sentence, str(vs)))
{'compound': 0.6588, 'neg': 0.0, 'neu': 0.406, 'pos': 0.594}

But it is always recommended to clean and preprocess your text before applying the text blob or Vader, because they do only minimal preprocessing.

These are some basic text preprocessing steps:

  1. Lowercase / UpperCase
  2. Punctuation/special characters Removal
  3. Remove HTML Code and URL Links
  4. Spell Checks
  5. Tokenization
  6. Removing Stop Words
  7. Normalization
    • Stemming or Lemmatization
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.