Open karndeepsingh opened 1 year ago
Have you solved this?
^
You can define a forward pass and use it in the compute_loss
function.
This should work, but there_ is a caveat. If your model architecture has layers that are shared between the query and candidate towers, (for example an item_id embedding in a sequential recommendation model), then I the checkpoint will save these as separate variables. This may cause an issue when restoring from the checkpoint.
class MovielensModel(tfrs.models.Model):
def __init__(self, layer_sizes):
super().__init__()
self.query_model = QueryModel(layer_sizes)
self.candidate_model = CandidateModel(layer_sizes)
self.task = tfrs.tasks.Retrieval(
metrics=tfrs.metrics.FactorizedTopK(
candidates=movies.batch(128).map(self.candidate_model),
),
)
def call(self, features, training=False):
query_embeddings = self.query_model({
"user_id": features["user_id"],
"timestamp": features["timestamp"],
})
movie_embeddings = self.candidate_model(features["movie_title"])
return (query_embeddings, movie_embeddings)
def compute_loss(self, features, training=False):
# We only pass the user id and timestamp features into the query model. This
# is to ensure that the training inputs would have the same keys as the
# query inputs. Otherwise the discrepancy in input structure would cause an
# error when loading the query model after saving it.
query_embeddings, movie_embeddings = self(features, training=training)
return self.task(
query_embeddings, movie_embeddings, compute_metrics=not training)
Hi, I have used Tensorflow Recommender's tutorial of Movielens to train the recommender model. But when I try to use callback mdel checkpoint in model.fit(). It raises following error:
Also, I am unable to model.summary() Please help me to resolve the issue. What are the changes I need to do in the subclass models to save best model checkpoint?
Here is the tutorial link that I am using for training: https://www.tensorflow.org/recommenders/examples/deep_recommenders