2
$\begingroup$

I am getting the error:

Input 0 is incompatible with layer lstm_1: expected ndim=3, found ndim=2

Using the model:

X = np.reshape(x_train_tfidf.shape[0], 1, x_train_tfidf.shape[1])
print(X.shape)
model.add(LSTM(30, return_sequences=True,
               input_shape=X))

model.add(Flatten())
model.add(Dropout(0.25))
model.add(Dense(100,activation = 'relu'))
model.add(Dropout(0.25))
model.add(Dense(1,activation='sigmoid'))
$\endgroup$
4
  • $\begingroup$ Have a look at your dimensions before building your network.. $\endgroup$
    – Aditya
    Apr 23, 2018 at 16:59
  • $\begingroup$ @Aditya x_train_tfidf (35000,1000), x_test (15000,1000) $\endgroup$
    – Midnight
    Apr 23, 2018 at 17:21
  • $\begingroup$ @Aditya so? you know? $\endgroup$
    – Midnight
    Apr 23, 2018 at 19:03
  • 1
    $\begingroup$ With X = np.reshape(x_train_tfidf.shape[0], 1, x_train_tfidf.shape[1]) and input_shape=X, it looks like you are telling the LSTM layer that the input size is the input tensor itself, not its shape. docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html $\endgroup$ Sep 23, 2018 at 21:09

2 Answers 2

4
$\begingroup$

It's probably this way..(not sure , give it a try)

Iputs needs to be reshaped to be [samples, time steps, features]

so

TrainX= np.reshape(TrainX,(TrainX.shape[0], 1, TrainX.shape[1]))

You need to passin the actual vector also?

$\endgroup$
1
$\begingroup$

import numpy as np np.expand_dims(X, axis = 0)

#This adds an additional dimension to your data without changing the value of your matrix.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.