# Understanding Tensorflow Recommenders embedding model

**URL:** <https://discuss.ai.google.dev/t/understanding-tensorflow-recommenders-embedding-model/23259>\
**Category:** General Discussion\
**Tags:** recommenders\
**Created:** [February 9, 2023, 2:30am UTC](https://discuss.ai.google.dev/t/understanding-tensorflow-recommenders-embedding-model/23259 "2023-02-09T02:30:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Yang](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/eric_yang/32/13966_2.png) [@Eric\_Yang](https://discuss.ai.google.dev/u/Eric_Yang)\
**Post date:** [February 9, 2023, 2:30am UTC](https://discuss.ai.google.dev/t/understanding-tensorflow-recommenders-embedding-model/23259/1 "2023-02-09T02:30:57Z")

</div>

I’m trying to understand how to alter some code from the [Tensorflow Recommenders](https://www.tensorflow.org/recommenders/examples/context_features) tutorial. Specifically wanted to understand how to change references to embedding variables in the call function of the Movie Model

Movie Model:

```auto
class MovieModel(tf.keras.Model):

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

    max_tokens = 10_000

    self.title_embedding = tf.keras.Sequential([
      tf.keras.layers.StringLookup(
          vocabulary=unique_movie_titles, mask_token=None),
      tf.keras.layers.Embedding(len(unique_movie_titles) + 1, 32)
    ])

    self.title_vectorizer = tf.keras.layers.TextVectorization(
        max_tokens=max_tokens)

    self.title_text_embedding = tf.keras.Sequential([
      self.title_vectorizer,
      tf.keras.layers.Embedding(max_tokens, 32, mask_zero=True),
      tf.keras.layers.GlobalAveragePooling1D(),
    ])

    self.title_vectorizer.adapt(movies)

  def call(self, titles):
    return tf.concat([
        self.title_embedding(titles),
        self.title_text_embedding(titles),
    ], axis=1)

```

If I change the call function to:

```auto
  def call(self, inputs):
    return tf.concat([
        self.title_embedding(inputs["movie_title"]),
        self.title_text_embedding(inputs["movie_title"]),
    ], axis=1)

```

I get the error:

```auto
TypeError: Only integers, slices (`:`), ellipsis (`...`), tf.newaxis (`None`) and scalar tf.int32/tf.int64 tensors are valid indices, got 'movie_title'

Call arguments received:
  • inputs=tf.Tensor(shape=(None,), dtype=string)

```

When I run:

```auto
class MovielensModel(tfrs.models.Model):

  def __init__ (self, use_timestamps):
    super(). __init__ ()
    self.query_model = tf.keras.Sequential([
      UserModel(use_timestamps),
      tf.keras.layers.Dense(32)
    ])
    self.candidate_model = tf.keras.Sequential([
      MovieModel(),
      tf.keras.layers.Dense(32)
    ])
    self.task = tfrs.tasks.Retrieval(
        metrics=tfrs.metrics.FactorizedTopK(
            candidates=movies.batch(128).map(self.candidate_model),
        ),
    )

  def compute_loss(self, features, training=False):
    # We only pass the user id and timestamp features into the query model. This
    # is to ensure that the training inputs would have the same keys as the
    # query inputs. Otherwise the discrepancy in input structure would cause an
    # error when loading the query model after saving it.
    query_embeddings = self.query_model({
        "user_id": features["user_id"],
        "timestamp": features["timestamp"],
    })
    movie_embeddings = self.candidate_model({"movie_title":features["movie_title"]})

```

I assumed that changing the input variable in the call function to something more specific wouldn’t change the output but for some reason this isn’t the case. I mirrored it to have similar structure to the UserModel and am not sure why it doesn’t work the same
