Does anyone know how textblob sentiment is working? I know it is working based on Pattern but I could not find any article or document explain how pattern assigns polarity value to a sentence.
-
http://stackoverflow.com/a/34519114/5575289 I think this link explains what you need. – Alikbar Apr 29 '17 at 12:06
-
The answer by gench should be indicated as the right answer while the one by DhruvPathak is partial. – Arnold Vialfont Apr 18 '21 at 11:58
2 Answers
Here is the code of textblog sentiment module: https://github.com/sloria/TextBlob/blob/90cc87ab0f9e25f37379079840ec43aba59af440/textblob/en/sentiments.py
As you can see, it has a training set with preclassified movie reviews, when you give a new text for analysis, it uses NaiveBayes classifier to classify the new text's polarity in pos
and neg
probabilities.

- 42,059
- 16
- 116
- 175
By default, it calculates average polarity and subjectivity over each word in a given text using a dictionary of adjectives and their hand-tagged scores. It actually uses pattern library for that, which takes the individual word scores from sentiwordnet.
If you call sentiment scores by specifying NaiveBayesAnalyzer such as
TextBlob("The movie was excellent!", analyzer=NaiveBayesAnalyzer())
then it will calculate the sentiment score by NaiveBayesAnalyzer trained on a dataset of movie reviews.

- 1,063
- 1
- 11
- 17
-
1This should be indicated as the right answer while the one by DhruvPathak is partial. Here is a link to several issues addressing this point on the Github of the library: github.com/sloria/TextBlob/issues/344#issuecomment-732193942 – Arnold Vialfont Apr 18 '21 at 11:56
-
I second @ArnoldVialfont on this. gench's answer seems to be the complete and correct one. – Mihaela Grigore Jun 01 '21 at 10:33