I am trying to use a keras 1D CNN to classify 300-dimensional vectors as either 1 or 0 based on a training set of around 2600 vectors. Each vector represents a document (based on gensim's doc2vec). Right now, here is the model:
def initialize_model(self, lr=0.01):
"""Initialize the neural network.
@type self: Pydeology
@type lr: float
Learning rate.
@rtype: None
"""
self.model = Sequential()
self.model.add(Conv1D(n_filters, kernel_size, padding='valid',
input_shape=(n_samples, input_dim, 1),
activation='relu', strides=strides))
self.model.add(MaxPooling1D(pool_size=2, strides=None, padding='valid'))
self.model.add(Dropout(0.2))
self.model.add(Conv1D(n_filters, kernel_size, padding='valid',
activation='relu', strides=strides))
self.model.add(MaxPooling1D(pool_size=2, strides=None, padding='valid'))
self.model.add(Dropout(0.2))
self.model.add(Dense(1, activation='sigmoid'))
self.model.compile(optimizer=Adam(lr), loss='binary_crossentropy',
print(self.model.summary())
Where self refers to a class I've created to contain the data arrays and the neural network itself. I then get the following error when I run the program:
ValueError: Input 0 is incompatible with layer conv1d_1: expected ndim=3, found ndim=4
What might I be doing wrong?
Thanks!