(x)
return e_x / np.expand_dims(e_x.sum(axis=-1), axis=-1)
Compute softmax values for each sets of scores in x.
Compute softmax values for each sets of scores in x.
Compute softmax values for each sets of scores in x .
def softmax(x):
    """Compute softmax values for each sets of scores in x."""
    e_x = np.exp(x - np.expand_dims(np.max(x, axis=-1), axis=-1))
    return e_x / np.expand_dims(e_x.sum(axis=-1), axis=-1) # only difference
def softmax ( x ) : e_x = np . exp ( x - np . expand_dims ( np . max ( x , axis = - 1 ) , axis = - 1 ) ) return e_x / np . expand_dims ( e_x . sum ( axis = - 1 ) , axis = - 1 ) # only difference