recommenders icon indicating copy to clipboard operation
recommenders copied to clipboard

Example on how to pass candidate_ids and candidate_sampling_probability in Retrieval

Open stefanogaiera opened this issue 2 years ago • 1 comments

Hi, I'm having problems trying to pass candidate_ids and candidate_sampling_probability

Can someone please share some code on how to create these two tensors?

stefanogaiera avatar Feb 15 '22 09:02 stefanogaiera

Hello u need to change 2 code

First one change your dataset object like this

train_tf = ds_train.map(lambda x:{'sku':x['sku'],
                                  'userid':x['userid'],
                                  "candidate_sampling_probabilities":x["candidate_sampling_probabilities"]})

Secondly you need to change your model like below I never use candidate_ids so i dont have idea about other parameter

def compute_loss(self, features: Dict[Text, tf.Tensor], training=False) -> tf.Tensor:
        # Define how the loss is computed.

        user_embeddings = self.user_model(features["userid"])
        sku_embeddings = self.sku_model(features["sku"])
        candidate_sampling_probability=features['candidate_sampling_probabilities']

        return self.task(user_embeddings,
                         sku_embeddings,
                         candidate_sampling_probability=candidate_sampling_probability)

mustfkeskin avatar Feb 26 '22 12:02 mustfkeskin