Skip to content

Instantly share code, notes, and snippets.

@avakn5
Created July 20, 2022 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avakn5/1abdf328d57fa7714ce73b1f28088cf6 to your computer and use it in GitHub Desktop.
Save avakn5/1abdf328d57fa7714ce73b1f28088cf6 to your computer and use it in GitHub Desktop.
#implementing the Vader Sentiment Analysis, handily for almost the totality of the simple sentiment analysis
import nltk
nltk.download('vader_lexicon')
from nltk.sentiment.vader import SentimentIntensityAnalyzer
def sentiment_scores(sentence):
# Create a SentimentIntensityAnalyzer object.
sid_obj = SentimentIntensityAnalyzer()
# the sentiment dictionary contains pos, neg, neu, and compound scores.
sentiment_dict = sid_obj.polarity_scores(sentence)
print(sentiment_dict['neg']*100)
print(sentiment_dict['neu']*100)
print(sentiment_dict['pos']*100)
def sentiment_dictneg(phrase):
sid_obj = SentimentIntensityAnalyzer()
sentiment_dict = sid_obj.polarity_scores(phrase)
return sentiment_dict['neg']*100
def sentiment_dictneu(phrase):
sid_obj = SentimentIntensityAnalyzer()
sentiment_dict = sid_obj.polarity_scores(phrase)
return sentiment_dict['neu']*100
def sentiment_dictpos(phrase):
sid_obj = SentimentIntensityAnalyzer()
sentiment_dict = sid_obj.polarity_scores(phrase)
return sentiment_dict['pos']*100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment