-
Notifications
You must be signed in to change notification settings - Fork 19.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to implement a conv layer with different filter sizes (Zhang & Wallace 2015) ? #6547
Comments
Apply different convolutional layers on the same input and merge their outputs? |
I'm in the middle of figuring this out myself. Here's what I think is necessary.
Have a look at the following for inspiration: Let me know if you've made any progress, and I'll do the same. |
Here's what I ended up doing, which appears to be doing the right thing, but I'm still new enough to Keras that I haven't figured out how to introspect this properly to make sure... submodels = []
for kw in (3, 4, 5): # kernel sizes
submodel = Sequential()
submodel.add(Embedding(len(word_index) + 1,
EMBEDDING_DIM,
weights=[embedding_matrix],
input_length=MAX_SEQUENCE_LENGTH,
trainable=False))
submodel.add(Conv1D(FILTERS,
kw,
padding='valid',
activation='relu',
strides=1))
submodel.add(GlobalMaxPooling1D())
submodels.append(submodel)
big_model = Sequential()
big_model.add(Merge(submodels, mode="concat"))
big_model.add(Dense(HIDDEN_DIMS))
big_model.add(Dropout(P_DROPOUT))
big_model.add(Activation('relu'))
big_model.add(Dense(1))
big_model.add(Activation('sigmoid'))
print('Compiling model')
big_model.compile(loss='binary_crossentropy',
optimizer='adam',
metrics=['accuracy']) |
I was trying to fit your implementation but got: Any idea? |
Yes, this is what I meant about "replicating the inputs"...sorry, I should have included the hist = big_model.fit([x_train, x_train, x_train],
y_train,
batch_size=BATCH_SIZE,
epochs=EPOCHS,
validation_data=([x_val, x_val, x_val], y_val),
callbacks=callbacks) You can see...I have |
thank you for sharing that! |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs, but feel free to re-open a closed issue if needed. |
The same problem seems to be addressed and solved in this issue using the |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs, but feel free to re-open a closed issue if needed. |
Closing as this is resolved |
In the above code as @fmailhot mentioned. When I tried to compile it says there is no Layer named Merge(). |
I had the same problem with the Merge() function |
I tried to this however I got an error message "list indices must be integers or slices, not ListWrapper". And I didn't use Merge but Concatenate instead... Does anyone have a solution to this issue? |
Hello,
I'm trying to reproduce the CNN architecture proposed in this paper, which has the following 1-CNN-layer architecture with two of each of the varying filter sizes (+ global maxpooling and dropout):
![screen shot 2017-05-09 at 00 49 10](https://cloud.githubusercontent.com/assets/11842615/25828679/df9dc5c6-3451-11e7-9792-c8fa32dd920f.png)
Is there a way to implement this architecture in Keras?
Best,
ben0it8
The text was updated successfully, but these errors were encountered: