对于以下代码段,出现以下错误:
如果我添加辍学层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
最佳答案
尝试在模型之前导入K并设置学习阶段。
from keras import backend as K
K.set_learning_phase(1) #set learning phase
从this issue
关于tensorflow - Keras错误 “You must feed a value for placeholder tensor ' bidirectional_1/keras_learning_phase'与dtype bool”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42969779/