Code
nlp
import nltk
from nltk.sentiment.vader import SentimentIntensityAnalyzer
nltk.download("vader_lexicon", quiet=True)
sia = SentimentIntensityAnalyzer()
text = "I absolutely love this product! Best purchase ever."
print(sia.polarity_scores(text))
for text in ["It was okay.", "This is terrible and broken.", "I love it!"]:
print(text, sia.polarity_scores(text)["compound"])
# HuggingFace transformer sentiment
from transformers import pipeline
clf = pipeline("sentiment-analysis",
model="distilbert/distilbert-base-uncased-finetuned-sst-2-english")
results = clf(["I love this!", "I hate this."])
for r in results:
print(r)
# TextBlob polarity
from textblob import TextBlob
print(TextBlob("The movie was not bad at all.").sentiment)