def create_model(options):
post = Input(shape=(options['MAX_LEN'],))
if options['USE_EMBEDDING']:
embedding = Embedding(output_dim=options['EMBEDDING_DIM'], weights = [options['EMBEDDING_MATRIX']] ,input_dim = len(options['VOCAB']) + 2, mask_zero=True )
else:
embedding = Embedding(output_dim=options['EMBEDDING_DIM'] ,input_dim = len(options['VOCAB']) + 2, mask_zero=True )
embed_post = embedding(post)
processed_post = Bidirectional(GRU(options['HIDDEN_DIM'], return_sequences = True))(embed_post)
output = Dense(len(options['CLASSES_2_IX']), activation='softmax')(processed_post)
model = Model(inputs = [post], outputs = output)
adam = Adam(clipnorm=1.)
model.compile(optimizer=adam, loss='categorical_crossentropy',metrics=['accuracy'])
model.summary()
return model
评论列表
文章目录