Commit 53138e69 authored by drevicko's avatar drevicko Committed by GitHub
Browse files

Estimate VAD by weighted average

Does a weighted average of centroids.

If intensity sums to zero for a category, a 'neutral' category is used or 0 if it's not present. I'm not 100% sure this is the best approach, and the name of the "neutral" category perhaps should use some convention?

Note that if there are no categories present, then no VAD (or other dimensional) estimate is returned. It may be better to use the neutral centroid if it's present in this case also.
parent 1302b0b9
from senpy.plugins import EmotionConversionPlugin
from senpy.models import EmotionSet, Emotion, Error
from collections import defaultdict
import logging
logger = logging.getLogger(__name__)
......@@ -37,14 +38,22 @@ class CentroidConversion(EmotionConversionPlugin):
def _forward_conversion(self, original):
"""Sum the VAD value of all categories found."""
res = Emotion()
totalIntensities = defaultdict(float)
for e in original.onyx__hasEmotion:
category = e.onyx__hasEmotionCategory
intensity = e.get("onyx__hasEmotionIntensity",1)
if category in self.centroids:
totalIntensities[category] += intensity
for dim, value in self.centroids[category].items():
res[dim] += value
res[dim] += value * intensity
except Exception:
res[dim] = value
res[dim] = value * intensity
for dim,intensity in totalIntensities.items():
if intensity != 0:
res[dim] /= intensity
res[dim] = self.centroids.get('neutral', {dim:0})[dim]
return res
def _backwards_conversion(self, original):
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment