This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
Awesome and done in seconds!! #186
smoothrhymes616
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Here's my code built from a pandas dataframe called rdat with all the russian posts in a column called "post2"
from dostoevsky.tokenization import RegexTokenizer
from dostoevsky.models import FastTextSocialNetworkModel
using dostoevsky package for sentiment analysis
set the tokenizer
tokenizer = RegexTokenizer()
specify the model as RuSentiment with our specific tokenizer
model = FastTextSocialNetworkModel(tokenizer=tokenizer)
specify that our messages are a list made from rdat's post2 column
messages = list(rdat['post2'])
save sentiment results as a model object, also
results = model.predict(messages, k=2)
create an empty list to capture sentiment values
sentiment_list = []
populate the sentiment list with the results
for sentiment in results: sentiment_list.append(sentiment)
create empty list objects to capture sentiment values in the dataframe
neutral_list = []
negative_list = []
positive_list = []
speech_list = []
skip_list = []
iterate through the sentiment list and obtain boolean values for sentiment
for sentiment in sentiment_list:
neutral = sentiment.get('neutral')
negative = sentiment.get('negative')
positive = sentiment.get('positive')
if neutral is None:
neutral_list.append(0)
else:
neutral_list.append(sentiment.get('neutral'))
if negative is None:
negative_list.append(0)
else:
negative_list.append(sentiment.get('negative'))
if positive is None:
positive_list.append(0)
else:
positive_list.append(sentiment.get('positive'))
add the neutral sentiment column to the dataframe
rdat['neutral'] = neutral_list
add the negative sentiment column to the dataframe
rdat['negative'] = negative_list
add the positive sentiment column to the dataframe
rdat['positive'] = positive_list
save the rdat dataframe to file
rdat.to_csv('Russian_sentiment.csv')
Beta Was this translation helpful? Give feedback.
All reactions