1

I am trying to build a neural network using Keras but am getting the error:

ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 25168 but received input with shape (None, 34783)

I defined the model to be:

model = Sequential()
model.add(Dense(1024, input_dim = len(X), activation = 'relu'))
model.add(Dense(6, activation='softmax'))

In this, X is the result of using scikit-learn it's CountVectorizer() (after it is trained) as follows:

X = count_vectorizer.transform(X).todense()

Is there any method to fix this? Looking around I found that I might need to reshape the data, however I have no idea how and where.

0

1 Answer 1

1

You are using as input_dim the sample dimensionality: len(X) (the same as X.shape[0]) which is wrong.

Keras expects as input the number of dimensions of the features which, in your case of 2D input, is X.shape[-1]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.