tensorflow / tensorflow/recommenders

Question | Would it be a good idea to share an embedding layer between inputs and labels?

Open
#169 6 comments 3 reactions 1 assignee View on GitHub

@maciejkula is already working on this.

Since Nov 20, 2020.

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

Description

Let's say in the movielens dataset I have another column where each row is the list of the last 100 movies clicked by that user.

user_id movie_watched_id last_100_movies_clicked_ids
'123' '67865' '4543534 345435435 657657'

Would it make sense to encode the movie_watched_id in the candidate tower using the embedding layer used in the query tower to embed last_100_movies_clicked_ids?

Like, having this user model:

class UserModel(tf.keras.Model):

  def __init__(self):
    super().__init__()

    self.user_embedding = tf.keras.Sequential([
        tf.keras.layers.experimental.preprocessing.StringLookup(
            vocabulary=unique_user_ids, mask_token=None),
        tf.keras.layers.Embedding(len(unique_user_ids) + 1, 32),
    ])

    self.last_100_movies_clicked_ids_embedding = tf.keras.Sequential([
        tf.keras.layers.experimental.preprocessing.TextVectorizer(
            vocabulary=unique_last_100_movies_clicked_ids, mask_token=None),
        tf.keras.layers.Embedding(len(unique_last_100_movies_clicked_ids) + 1, 32),
    ])

  def call(self, inputs):
    # Take the input dictionary, pass it through each input layer,
    # and concatenate the result.
    return tf.concat([self.user_embedding(inputs["user_id"]), 
   					  self.last_100_movies_clicked_ids_embedding(inputs["last_100_movies_clicked_ids"])
        			])

We define the movie model as:

class MovieModel(tf.keras.Model):

  def __init__(self, user_model):
    super().__init__()

    max_tokens = 10_000

    self.movie_watched_id_embedding = user_model.last_100_movies_clicked_ids_embedding

  def call(self):
    return self.movie_watched_id_embedding(inputs['movie_watched_id'])

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.