Skip to content

Commit

Permalink
fix: emotions thresholds (#219)
Browse files Browse the repository at this point in the history
* fix: emotions thresholds

* fix: emotions thresholds

* fix: confs and thresholds
  • Loading branch information
dilyararimovna authored Nov 25, 2022
1 parent 455b720 commit 528e7c4
Showing 1 changed file with 16 additions and 3 deletions.
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

0 comments on commit 528e7c4

Please sign in to comment.