Good day, everyone.
I want to have two separate TensorFlow models (f and g) and train both of them on the loss of f(g(x)). However, I want to use them separately, like g(x) or f(e), where e is an embedded vector but received not from g.
For example, the classical way to create the model with embedding looks like this:
# First block
model = Sequential([
vectorize_layer,
Embedding(vocab_size, embedding_dim, name="embedding"),
GlobalAveragePooling1D(),
Dense(16, activation='relu'),
Dense(1)
])
I want to have an option to pass data through embedding layer and all other layers separately, but still train the model as a whole unit, like:
# Second block
g = Sequential([
vectorize_layer,
Embedding(vocab_size, embedding_dim, name="embedding")
])
f = Sequential([
GlobalAveragePooling1D(),
Dense(16, activation='relu'),
Dense(1)
])
Can I do that without going to low-level TensorFlow? The first block of code is exactly what I want to train and I can leave it like that, but I need to pass data through the specific layers somehow.