1

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'])
2
  • As you define it, model is indeed a tensor, and not a model; you should switch all of your pipeline to the functional API - see How to “Merge” Sequential models in Keras 2.0? Commented Dec 15, 2018 at 21:11
  • Yes, your whole code makes little sense, you should use the functional API. Commented Dec 15, 2018 at 21:34

1 Answer 1

1

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'])
Sign up to request clarification or add additional context in comments.

3 Comments

Interesting... So, we can use p0.input and q0.input in such a manner even if p0 and q0 are sequential models?
@desertnaut Sure, they are valid attributes because the corresponding models have been defined and also they are (placeholder) tensors after all.
A well-deserved upvote - seems you got both myself & Matias off-guard ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.