When I tried to run this:
p0 = Sequential()
p0.add(Embedding(vocabulary_size1, 50, weights=[embedding_matrix_passage],
input_length=50, trainable=False))
p0.add(LSTM(64))
p0.add(Dense(256,name='FC1'))
p0.add(Activation('relu'))
p0.add(Dropout(0.5))
p0.add(Dense(50,name='out_layer'))
p0.add(Activation('sigmoid'))
q0 = Sequential()
q0.add(Embedding(vocabulary_size2,50,weights=embedding_matrix_query],
input_length=50, trainable=False))
q0.add(LSTM(64))
q0.add(Dense(256,name='FC1'))
q0.add(Activation('relu'))
q0.add(Dropout(0.5))
q0.add(Dense(50,name='out_layer'))
q0.add(Activation('sigmoid'))
model = concatenate([p0.output, q0.output])
model = Dense(10)(model)
model = Activation('softmax')(model)
model.compile(loss='categorical_crossentropy',optimizer='rmsprop', metrics=
['accuracy'])
it's giving me this error:
AttributeError
---> model.compile(loss='categorical_crossentropy',optimizer='rmsprop', metrics=['accuracy'])
As mentioned in the comments you need to use Keras Functional API to create models with branches, multiple inputs/outputs. However, there is no need to do this for all of your code, just for the last part:
concat = concatenate([p0.output, q0.output])
x = Dense(10)(concat)
out = Activation('softmax')(x)
model = Model([p0.input, q0.input], out)
model.compile(loss='categorical_crossentropy',optimizer='rmsprop', metrics=['accuracy'])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.