remove max pooling from models for better infromation flow

This commit is contained in:
René Knaebel 2017-07-28 17:25:08 +02:00
parent 18b60e1754
commit c1535b941b

View File

@ -1,6 +1,7 @@
import keras
from keras.engine import Input, Model
from keras.layers import Embedding, Conv1D, GlobalMaxPooling1D, Dense, Dropout, TimeDistributed, MaxPool1D
from keras.layers import Embedding, Conv1D, GlobalMaxPooling1D, Dense, Dropout, TimeDistributed, MaxPool1D, \
GlobalAveragePooling1D
def get_embedding(vocab_size, embedding_size, input_length,
@ -8,12 +9,13 @@ def get_embedding(vocab_size, embedding_size, input_length,
x = y = Input(shape=(input_length,))
y = Embedding(input_dim=vocab_size, output_dim=embedding_size)(y)
y = Conv1D(filter_size, kernel_size=5, activation='relu')(y)
y = MaxPool1D(pool_size=3, strides=1)(y)
# NOTE: max pooling destroys information flow for embedding
# y = MaxPool1D(pool_size=3, strides=1)(y)
y = Conv1D(filter_size, kernel_size=3, activation='relu')(y)
y = MaxPool1D(pool_size=3, strides=1)(y)
# y = MaxPool1D(pool_size=3, strides=1)(y)
y = Conv1D(filter_size, kernel_size=3, activation='relu')(y)
y = GlobalMaxPooling1D()(y)
y = Dropout(drop_out)(y)
y = GlobalAveragePooling1D()(y)
# y = Dropout(drop_out)(y)
y = Dense(hidden_dims, activation="relu")(y)
return Model(x, y)