Here is my input
x_train.shape # (12, 7) 12 observations each of length 7
x_train # dtype('int32')
Here's the architecture I'd like to achieve:
I'd like a kernel of size 3 convolved over the sequence. From keras documentation at https://keras.io/layers/convolutional/
"When using this layer as the first layer in a model, provide an input_shape argument (tuple of integers or None, e.g. (10, 128) for sequences of 10 vectors of 128-dimensional vectors, or (None, 128) for variable-length sequences of 128-dimensional vectors."
Honestly I'm having a hard time understanding their logic. Here's my attempt
docs_sequence = Input(shape=(7,), dtype='float32') # Longest document is 7 words
convolution = Conv1D(filters = 1, # only 1 convolution
kernel_size = 3, # tri grams
strides = 1,
input_shape = (1, 7),
padding = 'valid',
activation = 'relu')(docs_sequence)
output = Dense(1, activation='sigmoid')(convolution)
cnn_model = Model(inputs = docs_sequence, outputs = [output])
cnn_model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
and I'm consistently getting
ValueError: Input 0 is incompatible with layer conv1d_30: expected ndim=3, found ndim=2