How can I use TextBlob with Spanish input for sentiment analysis?
I recently ran a sentiment analysis and polarity test on a sample of tweets with the keyword "elecciones." My results indicate that most have a subjectivity and polarity of 0 even when this is clearly not the case. I'm wondering if textblob is missing something because I didn't configure it properly to handle Spanish input? Is there another package or library that I should import to get more accurate subjectivity and polarity data in Spanish?
The sentiment analysis is trained on movie reviews in English, so you won't get expected results with Spanish input. There are adapters available for some langues (i.e. French), but I'm not aware of one for Spanish.
Hi. You can first translate to english. Of course it will not be as accurate, but is an option. I have a function like this:
def get_tweet_sentiment(self, tweet):
analysis = TextBlob(self.clean_tweet(tweet))
language = analysis.detect_language()
if language == 'en':
analysis_ready = analysis
else:
analysis_ready = analysis.translate(to='en')
if analysis_ready.sentiment.polarity > 0:
return 'positive'
elif analysis_ready.sentiment.polarity == 0:
return 'neutral'
else:
return 'negative'
Then first the text is translated and then analyzed for sentiment. You can also have your own set of classifiers. See the documentation here: https://textblob.readthedocs.io/en/dev/classifiers.html#classifiers