Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: emotions thresholds #219

Merged
merged 3 commits into from
Nov 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions skills/emotion_skill/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,23 @@
class EmotionSkillScenario:
def __init__(self, steps, jokes, advices, logger):
self.emotion_precision = {
"anger": 0.6,
"anger": 0.8,
"fear": 0.8,
"joy": 0.8,
"love": 0.8,
"sadness": 0.8,
"surprise": 0.7,
"neutral": 0,
}
self.emotion_thresholds = {
"anger": 0.99999,
"fear": 0.5,
"joy": 0.5,
"love": 0.5,
"sadness": 0.6,
"surprise": 0.5,
"neutral": 0.5,
}
self.steps = steps
self.jokes = jokes
self.advices = advices
Expand All @@ -54,13 +63,17 @@ def _get_user_emotion(self, annotated_user_phrase, discard_emotion=None):
self.regexp_sad = True
logger.info(f"Sadness detected by regexp in {annotated_user_phrase['text']}")
return "sadness"
most_likely_emotion = None

most_likely_emotion = "neutral"
emotion_probs = get_emotions(annotated_user_phrase, probs=True)
if discard_emotion in emotion_probs:
emotion_probs.pop(discard_emotion)
most_likely_prob = max(emotion_probs.values())
for emotion in emotion_probs.keys():
if emotion_probs.get(emotion, 0) == most_likely_prob:
if (
emotion_probs.get(emotion, 0) == most_likely_prob
and emotion_probs.get(emotion, 0) >= self.emotion_thresholds[emotion]
):
most_likely_emotion = emotion
return most_likely_emotion

Expand Down