tensorflow / tensorflow/recommenders

Using contextual features of the current user's page.

Open
#336 7 comments 0 reactions 1 assignee View on GitHub

@maciejkula is already working on this.

Since Jul 21, 2021.

question
Dominant language
Python
Stars
2k
Forks
300
PR merge metrics
No merged PRs in 30d

Description

I 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.