Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keras LSTM neural net: TypeError: LSTM() missing 1 required positional argument: 'Y'

I'm trying to train a LSTM neural net using Keras (version 2.2.0) and TensorFlow (version 1.1.0). I know that there are more recent TensorFlow versions but unfortunately I'm having some issues installing them. However, I don't believe that my problem is related to the TensorFlow version.

This is how my Keras code looks like:

[...] from keras.layers import Dense, Dropout, LeakyReLU, LSTM, Activation, Dense, Dropout, Input, Embedding

def LSTM(X,Y):
    inputDimension = len(X[0])
    inputSize = len(X)
    
    # create the model
    model = Sequential()
    model.add(Embedding(input_length=inputDimension,input_dim=inputDimension,output_dim=256))
    model.add(LSTM(100))
    model.add(Dropout(0.2))
    model.add(Dense(1, activation='sigmoid'))
    model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
    model.fit(X,Y,epochs=3,batch_size=64)
    return model

Whenever I try to run it, I end up with the following error message:

Traceback (most recent call last):

File "Main.py", line 208, in lstmModel = ann.LSTM(scaledTrainingX,trainingY)
File "ann.py", line 158, in LSTM model.add(LSTM(100))
TypeError: LSTM() missing 1 required positional argument: 'Y'

I found this question on StackOverflow but the solution suggested there doesn't help because I'm not using a generator to train my network.

Any help to get this network to run would be highly appreciated. Thank you very much.

like image 575
Hagbard Avatar asked Oct 17 '22 15:10

Hagbard


1 Answers

The function LSTM(X,Y) in which you create your model is shadowing the Keras LSTM layer. So when you call:

model.add(LSTM(100))

you're indeed calling the function that you defined. You need to rename this function to something else.

like image 73
rvinas Avatar answered Oct 20 '22 22:10

rvinas