model.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:nmt 作者: westrik 项目源码 文件源码
def __init__(self, cp):
    print("Building network ...")

    # First, we build the network, starting with an input layer
    # Recurrent layers expect input of shape
    # (batch size, SEQ_LENGTH, num_features)

    # this is the placeholder tensor for the input sequences
    sequence = Input(shape=(maxlen,), dtype='int32')
    # this embedding layer will transform the sequences of integers
    # into vectors of size 128
    embedded = Embedding(max_features, 128, input_length=maxlen)(sequence)

    # apply forwards LSTM
    forwards = LSTM(64)(embedded)
    # apply backwards LSTM
    backwards = LSTM(64, go_backwards=True)(embedded)

    # concatenate the outputs of the 2 LSTMs
    merged = merge([forwards, backwards], mode='concat', concat_axis=-1)
    after_dp = Dropout(0.5)(merged)
    output = Dense(1, activation='sigmoid')(after_dp)

    self.model = Model(input=sequence, output=output)

    # try using different optimizers and different optimizer configs
    self.model.compile('adam', 'binary_crossentropy', metrics=['accuracy'])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号