File size: 1,305 Bytes
1a62c90 d801d73 1a62c90 d801d73 9f6e2f8 1a62c90 e334270 1a62c90 107d15e 904421a 107d15e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
from transformers import pipeline
classifier = pipeline("text-classification",
model='bhadresh-savani/distilbert-base-uncased-emotion',
return_all_scores=True)
def get_emotion(text='No text yet'):
prediction = classifier(text)[0]
result = sorted(prediction, key=lambda x: x['score'])[::-1]
return result
sentiment_map = {'anger': 'neg', 'sadness': 'neg', 'fear': 'neg',
'joy': 'pos', 'love': 'pos', 'surprise': 'pos'}
good_arcs = ['neg - pos', 'pos - neg']
great_arcs = ['pos - neg - pos', 'neg - pos - neg']
def get_sentiment_arc_evaluation(emotions):
sentiment_arc = []
for emo in emotions:
sentiment = sentiment_map[emo]
if sentiment_arc and sentiment_arc[-1] == sentiment:
continue
sentiment_arc.append(sentiment)
sentiment_arc_str = ' - '.join(sentiment_arc)
if sentiment_arc_str in great_arcs:
return 'What a great plot! Excellent! π'
elif sentiment_arc_str in good_arcs:
return 'Story plot seems nice! But you can do better. π'
elif len(sentiment_arc) < 2:
return "No judgment, but... The plot might be too simple! π€"
else:
return "The plot seems complicated. π€ But maybe I am just too stupid to understand!"
|