I'm trying to use CNN for text classification (Using Keras). In most tutorials, they suggest using Conv1D
for that, but when I try to define the model, I get an Invalid Syntax
error.
These are the libraries I'm importing:
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import Flatten
from keras.layers.convolutional import Conv1D
from keras.layers.convolutional import MaxPooling1D
from keras.layers.embeddings import Embedding
from keras.preprocessing import sequence
This is the model definition:
model = Sequential()
model.add(Embedding(vocab_size, 32, input_length=max_length)
model.add(Conv1D(32, 3, activation='relu')) #This is where I'm getting the error
model.add(MaxPooling1D())
model.add(Flatten())
model.add(Dense(250, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
This is the error message:
File "<ipython-input-29-a0d7dea5e2b2>", line 3
model.add(Conv1D(32, 3, activation='relu'))
^
SyntaxError: invalid syntax
Can you tell me what did I do wrong, and how can I fix it?
Thanks.
You're missing a bracket:
model.add(Embedding(vocab_size, 32, input_length=max_length) ) <----