I'm trying to work on the airline tweets datasets, and I've explored several possibilities for that. I saw some other tutorials where people used a count matrix (from sklearn CountVectorizer) and then used a CNN on it with fairly good results. However, I'm having better results with a basic ANN (3*100 Dense layers) with a Tf-IDF matrix as input (from sklearn TfidfVectorizer), so I'd like to join the two: a CNN with a Tf-Idf matrix as input. I am able to do it this way:
model = Sequential()
model.add(layers.Embedding(input_dim=input_shape[1], output_dim=200, input_length=input_shape[1]))
model.add(layers.Conv1D(128, 5, activation='relu', input_shape=(90051, 1)))
[rest of model]
but I'd like to remove the embedding layer, as I don't thinks it helps a lot with a tf-idf matrix (might be wrong, but I'd like to try). However when I run this:
model = Sequential()
model.add(layers.Conv1D(128, 5, activation='relu', input_shape=(90051, 1)))
model building and compiling works well, but on fitting I got the following error:
ValueError: Error when checking input: expected conv1d_3_input to have 3 dimensions, but got array with shape (10248, 90051)
I tried reshaping the data as stated on this SO answer like this:
tt = np.reshape(transformed, (transformed.shape[0], transformed.shape[1], 1))
print(tt.shape)
tt = transformed
tt.shape = (transformed.shape[0], transformed.shape[1], 1)
print(tt.shape)
but the data shape stays unchanged after numpy reshaping (no idea why).
So could someone please point me at why am I doing wrong ? Is this a bad idea from the beginning, or should I leave the embedding layer (results are not that good), or should I try the reshaping differently ? Thanks a lot for your help