加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
model.py 840 Bytes
一键复制 编辑 原始数据 按行查看 历史
Administrator 提交于 2020-02-12 19:50 . add detail
#!/user/bin/env python3
# -*- coding: utf-8 -*-
from keras import Input, Model, losses, Sequential
from keras.activations import relu, sigmoid
from keras.layers import Dense, Bidirectional, LSTM, Dropout, Flatten
from keras.optimizers import Adam
from keras.preprocessing import sequence
from keras_bert import Tokenizer, load_trained_model_from_checkpoint
def build_model(maxlen):
model = Sequential()
# BiRNN train
model.add(Bidirectional(LSTM(64), input_shape=(maxlen, 768)))
# model.add(Flatten())
# model.add(Dense(32, activation=relu, input_dim=maxlen))
# model.add(Dropout(0.5))
model.add(Dense(1, activation=sigmoid))
model.compile(loss=losses.binary_crossentropy, optimizer=Adam(1e-5), metrics=['accuracy'])
return model
if __name__ == '__main__':
print(build_model(maxlen=100).summary())
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化