def _make_color(words, thesvd): feats = [('left', 'HasColor', word) for word in words] try: # words = [x for x in words if abs(how_colorful(x, thesvd)) > 0.001] adhoc = make_category(thesvd, concepts=words) except KeyError: return (128, 128, 128) mix = _get_color_mix(adhoc, thesvd) new_color = (0,0,0) for color, weight in mix.items(): cur_color = tuple(item*weight for item in rgb[color]) new_color = tuple(a+b for a,b in zip(cur_color, new_color)) new_color = tuple(min(max(int(c), 0), 255) for c in new_color) return new_color
def how_colorful(word, thesvd): wordvc = thesvd.weighted_u[word,:] return wordvc.hat() * make_category(thesvd, concepts=rgb.keys())