I am trying to feed my TFIDF vector into an LSTM model.
TfidfVectorizer(ngram_range=(1,2), use_idf=True, analyzer='word', max_features = 5000)
Here's the Vector shapes
train_vector.shape = (22895, 5000)
test_vector.shape = (5724, 5000)
I am defining a model like below:
model = models.Sequential()
model.add(layers.LSTM(64, input_shape=(5000, 1), activation='relu'))
model.add(layers.Dropout(0.2))
model.add(layers.Dense(32, activation='relu'))
model.add(layers.Dropout(0.2))
model.add(layers.Dense(1, activation='sigmoid'))
Other Parameters
model.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit(train_vector, y_train, validation_data=(test_vector, y_test), epochs=10, batch_size=1024)
Tensorflow is being used here.
I am getting this error
ValueError: Input 0 of layer sequential_2 is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: (None, 5000)
I am trying to reshape the arrays, but the errors are still showing. I know LSTM needs 3D array. So how can I shape my arrays in a way that can be fed into LSTM???