gpt4 book ai didi

python - 属性错误: 'Tensor' object has no attribute 'compile'

转载 作者:行者123 更新时间:2023-11-30 09:05:13 25 4
gpt4 key购买 nike

当我尝试运行这个时:

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'])

它给了我这个错误:

AttributeError             
---> model.compile(loss='categorical_crossentropy',optimizer='rmsprop', metrics=['accuracy'])

最佳答案

正如评论中提到的,您需要使用 Keras Functional API创建具有分支、多个输入/输出的模型。但是,无需对所有代码执行此操作,只需对最后一部分执行此操作即可:

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'])

关于python - 属性错误: 'Tensor' object has no attribute 'compile' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53796872/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com