Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I use TextBlob with Spanish input for sentiment analysis? #209

Open
MathildaEliza opened this issue May 22, 2018 · 2 comments
Open

Comments

@MathildaEliza
Copy link

MathildaEliza commented May 22, 2018

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?

@jschnurr
Copy link
Collaborator

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.

@richardjorge84
Copy link

richardjorge84 commented Apr 12, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants