我在下面的代码段中收到以下错误:
您必须为占位符张量提供值 ' bidirectional_1 / keras_learning_phase'用dtype bool
如果我添加了dropout图层model.add(Dropout(dropout))
,它就可以了。谁知道为什么?后端是Tensorflow,Keras 2.0.1
def prep_model1(embedding_layer1, embedding_layer2, dropout=0.5):
model0 = Sequential()
model0.add(embedding_layer1)
model0.add(Bidirectional(LSTM(128, return_sequences=False, dropout=dropout)))
model1 = Sequential()
model1.add(embedding_layer2)
model1.add(Bidirectional(LSTM(128, return_sequences=False, dropout=dropout)))
model = Sequential()
model.add(Merge([model0, model1], mode='concat', concat_axis=1))
#model.add(Dropout(dropout))
model.add(Dense(1, activation='sigmoid'))
return model
答案 0 :(得分:27)
尝试导入K并在模型之前设置学习阶段。
from keras import backend as K
K.set_learning_phase(1) #set learning phase