Using contextual features of the current user's page.
See original GitHub issueI am a little confused by the two towers architecture on what features should I use in each model (query & candidate).
I’m trying to build a recommender for consumer products.
I want the model to recommend products for new visitors between the training operations and consider the existing visitors’ behaviour between these training operations. Thus I replaced the user_id with a sequence of the last X product visits per #119 .
I have at my disposal a lot of contextual information which I want to use. If I have got it right from Taking advantage of context features, I should use them only in the candidate model since they are product’s and not visitor’s attributes, right?
Based on the above, my current model is like:
class UserModel(tfrs.Model, ABC):
def __init__(
self, lookups: preprocessing.Lookups, hparams: preprocessing.RunParams
):
self.past_visits_embedding = tf.keras.Sequential(...)
def call(self, inputs: Dict[Text, tf.Tensor], training=None, mask=None):
return self.past_visits_embedding(inputs["past_visits"])
class ProductModel(tfrs.Model, ABC):
def __init__(
self, lookups: preprocessing.Lookups, hparams: preprocessing.RunParams
):
self.url_id_embedding = tf.keras.Sequential(...)
self.category_embedding = tf.keras.Sequential(...)
self.title_embedding = tf.keras.Sequential(...)
self.price_embedding = tf.keras.Sequential(...)
def call(self, inputs: Dict[Text, tf.Tensor], training=None, mask=None):
return tf.concat(...)
Where I’m really struggling is, can I use contextual features of the visitor’s current page to infer recommendations for that page? In other words, if a user is on product page A, can I use the title, category, price etc., of product A as embeddings in the user model to infer the next product? e.g
class UserModel(tfrs.Model, ABC):
def __init__(
self, lookups: preprocessing.Lookups, hparams: preprocessing.RunParams
):
self.past_visits_embedding = tf.keras.Sequential(...)
self.current_url_id_embedding = tf.keras.Sequential(...)
self.current_category_embedding = tf.keras.Sequential(...)
self.current_title_embedding = tf.keras.Sequential(...)
self.current_price_embedding = tf.keras.Sequential(...)
def call(self, inputs: Dict[Text, tf.Tensor], training=None, mask=None):
return tf.concat(...)
I really appreciate any help you can provide.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7

Top Related StackOverflow Question
Thanks! I was doing the same, but wanted to be sure! Thanks a lot!
This is absolutely the right approach - the product page the user is visiting right now is a very useful piece of contextual information.
Writing a tutorial might be tricky - do you have a dataset in mind where this could be demonstrated? Otherwise we could extend one of the existing tutorials with a new paragraph about this.