rnn-tutorial-rnnlm icon indicating copy to clipboard operation
rnn-tutorial-rnnlm copied to clipboard

NameError: name 'softmax' is not defined

Open Xnsam opened this issue 7 years ago • 1 comments

Hi,

Thank you for the great tutorial. I got stuck here, o[t]= softmax(self.V.dot(s[t])) Inside the forward_propagation function definition NameError: name 'softmax' is not defined

I tried implementing a function called 'softmax'

def softmax(x):
	e_x = np.exp(x-np.max(x))
	return e_x / e_x.sum()

def softmax(x):
	w = np.array(x)
	maxes = np.amax(w, axis=0)
	e = np.exp(w-maxes)
	s = e / np.sum(e, axis=0)
	return s

and but it does n't work i get the exception ValueError: could not broadcast input array from shape (8000) into shape (100)

also tried o[t]= Th.nnet.softmax(self.V.dot(s[t]))

but got the following error ValueError: setting an array element with a sequence.

please somebody help

Xnsam avatar Aug 17 '17 10:08 Xnsam

Use this: def softmax(z): return np.exp(z)/((np.exp(z)).sum())

abhish311 avatar Aug 26 '17 13:08 abhish311