Я работаю над моделью встраивания слов, которая ломается, когда я пытаюсь добавить окончательный Reshape
.Ниже приведена модель с Reshape
, которая выдает:
ValueError: total size of new array must be unchanged
Я не могу понять, почему эти размеры не складываются.
embedding_size = 50
input_size = 46
# Both inputs are 1-dimensional
ingredients = Input(
name='ingredients',
shape=(input_size,)
)
documents = Input(
name='documents',
shape=(input_size,)
)
ingredients_embedding = Embedding(name='ingredients_embedding',
input_dim=training_size,
output_dim=embedding_size)(ingredients)
# Embedding the document (shape is (None, 46, 50))
document_embedding = Embedding(name='documents_embedding',
input_dim=training_size,
output_dim=embedding_size)(documents)
# Merge the layers with a dot product along the second axis (shape is (None, 46, 46))
merged = Dot(name='dot_product', normalize=True, axes=2)([ingredients_embedding, document_embedding])
# ~ This like breaks ~
# Reshape to be a single number (shape will be (None, 1))
merged = Reshape(target_shape=(1,))(merged) # <-- ValueError: total size of new array must be unchanged
m = Model(inputs=[ingredients, documents], outputs=merged)
m.compile(optimizer='Adam', loss='mse')
return m