tensorflow / tensorflow/recommenders
adding more contexts
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2k
- Forks
- 300
- PR merge metrics
- No merged PRs in 30d
Description
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)`
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the UserModel class and the StringLookup, Embedding, Discretization, and Normalization layers shown in the issue. Check the TensorFlow Recommenders and TensorFlow documentation for adding location as context; the work is done when the approach and vocabulary requirements are validated for this model.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, tensorflow
- Domain
- machine-learning
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100