remove max pooling from models for better infromation flow
This commit is contained in:
parent
18b60e1754
commit
c1535b941b
@ -1,6 +1,7 @@
|
|||||||
import keras
|
import keras
|
||||||
from keras.engine import Input, Model
|
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,
|
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,))
|
x = y = Input(shape=(input_length,))
|
||||||
y = Embedding(input_dim=vocab_size, output_dim=embedding_size)(y)
|
y = Embedding(input_dim=vocab_size, output_dim=embedding_size)(y)
|
||||||
y = Conv1D(filter_size, kernel_size=5, activation='relu')(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 = 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 = Conv1D(filter_size, kernel_size=3, activation='relu')(y)
|
||||||
y = GlobalMaxPooling1D()(y)
|
y = GlobalAveragePooling1D()(y)
|
||||||
y = Dropout(drop_out)(y)
|
# y = Dropout(drop_out)(y)
|
||||||
y = Dense(hidden_dims, activation="relu")(y)
|
y = Dense(hidden_dims, activation="relu")(y)
|
||||||
return Model(x, y)
|
return Model(x, y)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user