question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using contextual features of the current user's page.

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
Ullar-Kaskcommented, Aug 2, 2021

Thanks! I was doing the same, but wanted to be sure! Thanks a lot!

2reactions
maciejkulacommented, Jul 21, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Enable viewing of search results for the current and another ...
Enable viewing of search results for the current and another selected user · Navigate to All > Contextual Search > Table Configuration. ·...
Read more >
What is Contextual Help, and how it can lead to happier users
Benefits: Reassures the user that their action is correct and builds confidence in the application. Drawbacks: May be distracting for more ...
Read more >
Contextual Inquiry: Inspire Design by Observing and ...
Contextual inquiry is a type of ethnographic field study that involves in-depth observation and interviews of a small sample of users to ...
Read more >
IndieUI: User Context 1.0 - W3C
IndieUI: User Context defines a set of preferences that users can choose to expose to web applications, and an API for user agents...
Read more >
Work with contextual identities - Mozilla - MDN Web Docs
This extension provides users with enhanced functionality for contextual identities, such as the ability to long-click the new tab button and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found