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.
pull/29/head
drevicko 7 years ago committed by GitHub
parent 1302b0b93c
commit 53138e6942

@ -1,5 +1,6 @@
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():
try:
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
else:
res[dim] = self.centroids.get('neutral', {dim:0})[dim]
return res
def _backwards_conversion(self, original):

Loading…
Cancel
Save