Created
March 30, 2023 23:00
-
-
Save john-adeojo/09cd66aba53ce8b721bc9ae3df83883e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sentiment analyser, specify model | |
analyzer = SentimentAnalyzer('cardiffnlp/twitter-roberta-base-sentiment-latest') | |
# Get sentiment analysis | |
tweets_with_sentiment = analyzer.get_sentiment(tweets_df) | |
# emotion analyser, specify model | |
analyzer = SentimentAnalyzer('cardiffnlp/twitter-roberta-base-emotion', emotion=True) | |
# Get emotion analysis | |
tweets_with_sentiment = analyzer.get_sentiment(tweets_with_sentiment) | |
# Generate emotion and sentiment distributions at the user_id level | |
sentiment_ratios = pd.crosstab( | |
index=tweets_with_sentiment['user_id'], | |
columns= tweets_with_sentiment['sentiment'], | |
normalize='index' | |
).reset_index() | |
emotion_ratios = pd.crosstab( | |
index=tweets_with_sentiment['user_id'], | |
columns= tweets_with_sentiment['emotion'], | |
normalize='index' | |
).reset_index() | |
ratios_emotion_sentiment = emotion_ratios.merge(sentiment_ratios, on='user_id') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment