sentiment_analysis / engine.py
yashaswini278's picture
Upload 3 files
48ae580
raw
history blame
637 Bytes
from transformers import pipeline
class SentimentAnalyzer:
def __init__(self) -> None:
self.analyzer = pipeline("sentiment-analysis", model = "distilbert-base-uncased-finetuned-sst-2-english")
def score_sentiment(self, sentence: str) -> float:
return self.analyzer(sentence)[0]
def get_sentiment(self, sentence: str) -> str:
sentiment_score = self.score_sentiment(sentence)
return sentiment_score['label']
if __name__ == "__main__":
sentence = "This place is good"
sentiment_analyzer = SentimentAnalyzer()
print(sentiment_analyzer.get_sentiment(sentence))