Код: Выделить всё
input1_shape = (len(train_x[0]),)
input2_shape = (len(train_x2[0]),)
sent2vec_vectors1 = Input(shape=input1_shape)
sent2vec_vectors2 = Input(shape=input2_shape)
combined = concatenate([sent2vec_vectors1,sent2vec_vectors2])
dense1 = Dense(512, activation='relu')(combined)
dense1 = Dropout(0.3)(dense1)
output1 = Dense(1, activation='sigmoid',name='classification1')(dense1)
output2 = Dense(1, activation='sigmoid',name='classification2')(dense1)
model = Model(inputs=[sent2vec_vectors1,sent2vec_vectors2], outputs=[output1,output2])
Код: Выделить всё
model.compile(loss={'classification1': 'binary_crossentropy',
'classification2': 'binary_crossentropy'},
optimizer='adam', metrics=['accuracy'])
history = model.fit([train_x,train_x2],[train_y,train_y2],
validation_data=([test_x,test_x2],[test_y,test_y2]),
batch_size=32, nb_epoch=10, shuffle=True)
Я пытался запустить его на версии TensorFlow: 2.16. 1 и внес следующие изменения
Код: Выделить всё
input1_shape = (len(train_x[0]),)
input2_shape = (len(train_x2[0]),)
sent2vec_vectors1 = Input(shape=input1_shape, name="vector1")
sent2vec_vectors2 = Input(shape=input2_shape, name="vector2")
class ConcatenateLayer(Layer):
def call(self, inputs, axis=0):
return tf.concat(inputs, axis=axis)
combined = ConcatenateLayer()([sent2vec_vectors1,sent2vec_vectors2],axis=0)
dense1 = Dense(512, activation='relu')(combined)
dense1 = Dropout(0.3)(dense1)
output1 = Dense(1, activation='sigmoid',name='classification1')(dense1)
output2 = Dense(1, activation='sigmoid',name='classification2')(dense1)
model = Model(inputs=[sent2vec_vectors1,sent2vec_vectors2], outputs=[output1,output2])
model.compile(loss={'classification1': 'binary_crossentropy',
'classification2': 'binary_crossentropy'},
optimizer='adam', metrics=['accuracy', 'accuracy'])
history = model.fit([train_x, train_x2], [train_y, train_y2],
validation_data=([test_x, test_x2], [test_y, test_y2]),
epochs=10, shuffle=True
)
Код: Выделить всё
Incompatible shapes: [64,1] vs. [32,1]
[[{{node gradient_tape/compile_loss/binary_crossentropy_1/logistic_loss/mul/BroadcastGradientArgs}}]] [Op:__inference_one_step_on_iterator_8871]
форма данных следующая:
- Имя объекта: train_x Форма: Форма: (1400,600)
- Имя объекта: train_x2 Форма: Форма: (1400,600)
- Имя объекта: train_y Форма: Форма: (1400,)
- Имя объекта: train_y2 Форма: Форма: (1400,)
- Объект имя: test_x Форма: Форма: (600,600)
- Имя объекта: test_x2 Форма: Форма: (600,600)
- Имя объекта: test_y Форма: Форма : (600,)
- Имя объекта: test_y2 Форма: Форма: (600,)
И
И p>
Формы ввода:
- sent2vec_vectors1: (Нет, 600)
- sent2vec_vectors2: (Нет, 600)
- output1: (Нет, 1)
- output2: (Нет, 1)
Я пробовал изменить форму данных и пробовал различные размеры пакетов, но я очень новичок в тензорном потоке.
Подробнее здесь: https://stackoverflow.com/questions/783 ... and-tensor