def build_model():
main_input = Input(shape=(maxlen, ), dtype='int32', name='main_input')
embedding = Embedding(max_features, embedding_dims,
weights=[np.matrix(W)], input_length=maxlen,
name='embedding')(main_input)
embedding = Dropout(0.50)(embedding)
conv4 = Convolution1D(nb_filter=nb_filter,
filter_length=4,
border_mode='valid',
activation='relu',
subsample_length=1,
name='conv4')(embedding)
maxConv4 = MaxPooling1D(pool_length=2,
name='maxConv4')(conv4)
conv5 = Convolution1D(nb_filter=nb_filter,
filter_length=5,
border_mode='valid',
activation='relu',
subsample_length=1,
name='conv5')(embedding)
maxConv5 = MaxPooling1D(pool_length=2,
name='maxConv5')(conv5)
x = merge([maxConv4, maxConv5], mode='concat')
x = Dropout(0.15)(x)
x = RNN(rnn_output_size)(x)
x = Dense(hidden_dims, activation='relu', init='he_normal',
W_constraint = maxnorm(3), b_constraint=maxnorm(3),
name='mlp')(x)
x = Dropout(0.10, name='drop')(x)
output = Dense(nb_classes, init='he_normal',
activation='softmax', name='output')(x)
model = Model(input=main_input, output=output)
model.compile(loss={'output':'categorical_crossentropy'},
optimizer=Adadelta(lr=0.95, epsilon=1e-06),
metrics=["accuracy"])
return model
评论列表
文章目录