llSourcell/LSTM_Networks

Typos in code

Opened this issue · 4 comments

for i range(1, self.rl+1): should be for i in range(1, self.rl+1):

self.oa[i] self.sigmoid(np.dot(self.w, hs)) should be self.oa[i] = self.sigmoid(np.dot(self.w, hs))

def LoadText(): had a space before it that caused an error. The following lines in the function had

similar issues

When I run the last part I get:

`ValueError Traceback (most recent call last)
in ()
12 for i in range(1, iterations):
13 #compute predicted next word
---> 14 RNN.forwardProp()
15 #update all our weights using our error
16 error = RNN.backProp()

in forwardProp(self)
53 for i in range(1, self.rl+1):
54 self.LSTM.x = np.hstack((self.ha[i-1], self.x))
---> 55 cs, hs, f, c, o = self.LSTM.forwardProp()
56 #store computed cell state
57 self.ca[i] = cs

ValueError: too many values to unpack (expected 5)
`

Replace the forwardProp function to:

def forwardProp(self):
    #loop through recurrences - start at 1 so the 0th entry of all arrays will be an array of 0's
    for i in range(1, self.rl+1):
        #set input for LSTM cell, combination of input (previous output) and previous hidden state
        self.LSTM.x = np.hstack((self.ha[i-1], self.x))
        #run forward prop on the LSTM cell, retrieve cell state and hidden state
        cs, hs, f, inp, c, o = self.LSTM.forwardProp()
        #store input
        maxI = np.argmax(self.x)
        self.x = np.zeros_like(self.x)
        self.x[maxI] = 1
        self.ia[i] = self.x #Use np.argmax?
        #store cell state
        self.ca[i] = cs
        #store hidden state
        self.ha[i] = hs
        self.af[i] = f
        self.ai[i] = inp
        self.ac[i] = c
        self.ao[i] = o
        #calculate output by multiplying hidden state with weight matrix
        self.oa[i] = self.sigmoid(np.dot(self.w, hs))
        self.x = self.eo[i-1]
    #return all outputs    
    return self.oa

Hi,guys ,I think there is something missed in this sentence: "dphs = np.dot(dc, self.c)[:self.ys] + np.dot(do, self.o)[:self.ys] + np.dot(di, self.i)[:self.ys] + np.dot(df, self.f)[:self.ys]". It should be :
dphs = np.dot(np.dot(dc, dtangent(c)), self.c)[:self.ys] +
np.dot(np.dot(do, dsigmoid(o)), self.o)[:self.ys] +
np.dot(np.dot(di, dsigmoid(i)), self.i)[:self.ys] +
np.dot(np.dot(df, dsigmoid(f)), self.f)[:self.ys]

I don't know if I understand wrong? hope you guys can help with that, thanks!