recommenders icon indicating copy to clipboard operation
recommenders copied to clipboard

adding more contexts

Open deeplearningnrs opened this issue 3 years ago • 0 comments

Please see if this is a correct way of adding a new feature/context in user model. Do I need to take unique values of additional feature (location in this case):

`#user encoder

class UserModel(tf.keras.Model):

def init(self): super().init()

self.user_embedding = tf.keras.Sequential([
    tf.keras.layers.StringLookup(
        vocabulary=unique_user_ids, mask_token=None),
    tf.keras.layers.Embedding(len(unique_user_ids) + 1, 32),
])
self.timestamp_embedding = tf.keras.Sequential([
    tf.keras.layers.Discretization(timestamp_buckets.tolist()),
    tf.keras.layers.Embedding(len(timestamp_buckets) + 1, 32),
])
self.normalized_timestamp = tf.keras.layers.Normalization(
    axis=None
)

self.normalized_timestamp.adapt(timestamps)

self.loc_embedding =  tf.keras.Sequential([
    tf.keras.layers.StringLookup(
        vocabulary=unique_loc, mask_token=None),
    tf.keras.layers.Embedding(len(unique_loc) + 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.loc_embedding(inputs["location"]), self.timestamp_embedding(inputs["comment_date"]), tf.reshape(self.normalized_timestamp(inputs["comment_date"]), (-1, 1)), ], axis=1)`

deeplearningnrs avatar Oct 09 '21 18:10 deeplearningnrs