In [ ]:
'''
http://eli.thegreenplace.net/2016/the-softmax-function-and-its-derivative/
'''
In [3]:
import numpy as np
In [8]:
def softmax_overflow(x):
exps = np.exp(x)
return exps / np.sum(exps)
In [11]:
softmax_overflow([1000, 2000, 5000])
Out[11]:
In [12]:
def softmax(x):
shiftx = x - np.max(x)
exps = np.exp(shiftx)
return exps / np.sum(exps)
In [13]:
softmax([1000, 2000, 5000])
Out[13]:
In [ ]: