多输入和共享层的概念

2018-11-19  本文已影响0人  光光小丸子

这里主要实现以下多输入和共享层的概念

'''
from keras.layers import Input, LSTM, Dense, merge,Concatenate
from keras.models import Model

tweet_a = Input(shape=(140, 256))
tweet_b = Input(shape=(140, 256))

shared_lstm = LSTM(64)

encoded_a = shared_lstm(tweet_a)
encoded_b = shared_lstm(tweet_b)

print('int0',shared_lstm.get_input_at(0))
print('int1',shared_lstm.get_input_at(1))

print('out0',shared_lstm.get_output_at(0))

print('out1',shared_lstm.get_output_at(1))
merged_vector = Concatenate(axis=-1)([encoded_a,encoded_b])

predictions = Dense(1, activation='sigmoid')(merged_vector)

model = Model(inputs=[tweet_a, tweet_b], outputs=predictions)

model.compile(optimizer='rmsprop',
loss='binary_crossentropy',
metrics=['accuracy'])

print(model.summary())
'''

上一篇下一篇

猜你喜欢

热点阅读