I have two datasets, one numeric and one semantic information of the numeric ones. I want to train an autoencoder to give latent embeddings that should match the semantic dataset. That is: ae_model = Model(input = X_tr, target = [X_tr, S_tr]) where S_tr is the semantic embedding that should match with the encoder outputs or the latent embeddings.
# Load the data
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()
# Load the target embeddings
target_embeddings = tf.keras.datasets.mnist.load_data()[1]
# Define the autoencoder
encoder = tf.keras.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dense(64, activation='relu'),
])
decoder = tf.keras.Sequential([
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dense(28 * 28, activation='sigmoid'),
tf.keras.layers.Reshape((28, 28)),
])
ae_model = tf.keras.Model(encoder, decoder)
# Compile the autoencoder
ae_model.compile(optimizer='adam', loss='mse')
# Train the autoencoder
ae_model.fit(x_train, target_embeddings, epochs=10)
I have tried this, but this passes Target_embeddings as the target, I want the latent embeddings match the target_embeddings, how can I do that.
Try this one: