dennybritz / rnn-tutorial-rnnlm

Recurrent Neural Network Tutorial, Part 2 - Implementing a RNN in Python and Theano

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NameError: name 'softmax' is not defined

Xnsam opened this issue · 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

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