使用Keras编译LSTM时出现断言错误

时间:2021-03-09 14:02:04

I have the following code:

我有以下代码:

max_features = 5000
maxlen = 140
model = Sequential()

model.add(Embedding(max_features, 128)) 
model.add(LSTM(128, activation = 'sigmoid', inner_activation =  'hard_sigmoid', return_sequences = False))
model.add(Dense(input_dim = 128, output_dim = 2, activation = 'softmax'))

optimizer = Adam(lr = 0.001, beta_1 = 0.9, beta_2 = 0.999, epsilon = 1e-8)
model.compile(loss = 'categorical_crossentropy', optimizer = optimizer)

model.fit(x_train, y_train, batch_size = 64, nb_epoch = 10, verbose = 2)

y_test_pred = model.predict_classes(x_test)

But everytime I run it, I get an error at the line

但每次我运行它时,我都会收到错误

model.compile(loss = 'categorical_crossentropy', optimizer = optimizer)

which states:

其中说明:

 AssertionError: The number of inputs given to the inner function of scan does not match the number of inputs given to scan.

Does anyone know what that means?

有谁知道这意味着什么?

1 个解决方案

#1


0  

Answer by OP:

OP回答:

I have fixed this problem, turns out it has something to do with an outdated Theano version. So if you are experiencing this problem, update your theano module!

我已经解决了这个问题,事实证明它与过时的Theano版本有关。因此,如果您遇到此问题,请更新您的theano模块!

#1


0  

Answer by OP:

OP回答:

I have fixed this problem, turns out it has something to do with an outdated Theano version. So if you are experiencing this problem, update your theano module!

我已经解决了这个问题,事实证明它与过时的Theano版本有关。因此,如果您遇到此问题,请更新您的theano模块!