Spaces:
Runtime error
Runtime error
File size: 637 Bytes
48ae580 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
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))
|