import math


def take_exp_of_dict_values_and_normalize(dict_):
    """dict_ is a dictionary of labels and values

    This function takes the exponential of each of the values
    and normalizes by the sum of the exponentials to get the
    probability of each label"""
    m = max(dict_.values())  # For log sum trick
    probs = {l: math.exp(v - m) for l, v in dict_.iteritems()}
    s = sum(probs.values())
    for l in probs:
        probs[l] /= s
    return probs