adapting the script movielens_recommendations_transformers.py to be Backend-Agnostic#2039
Conversation
| encoded_other_features = [] | ||
|
|
||
| # Helper function to create embeddings | ||
| def embedding_helper(input): |
There was a problem hiding this comment.
Please move this to be a method on the class
|
|
||
| # This function merely groups similar logic for include_movie_features=True, | ||
| # or given as include_movie_features=False | ||
| def movie_sequence_helper(encoded_sequence_movies): |
| # or given as include_movie_features=False | ||
| def movie_sequence_helper(encoded_sequence_movies): | ||
| # Create positional embedding. | ||
| positions = keras.ops.arange(start=0, stop=sequence_length - 1, step=1) |
There was a problem hiding this comment.
Instead of using keras.ops.* everywhere, just do from keras import ops at the start -- it will shorten many lines
| output_dim=movie_embedding_dims, | ||
| name="position_embedding", | ||
| ) | ||
| positions = tf.range(start=0, limit=sequence_length - 1, delta=1) |
There was a problem hiding this comment.
Did the old really need extensive refactoring? Best I can tell only this line needed to change (to become ops.arange()
There was a problem hiding this comment.
Changing only the tf.range to ops.arange does not work and I believe it is because StringLookup is part of the model, not of tf.data.Dataset in the original script, and only Tensorflow can handle strings.
So, my approach was to split the function encode_input_features into two parts StringLookups and Embeddings. I placed the StringLookups functionality into tf.data.Dataset processing step, and created a class to handle each input embeddings. And also the issue that this script must run whether one chooses to include user_features or not also adds some refactoring.
However, if there is a less-refactoring approach/method, I'm wiling to learn and implement it. I must confess also that the refactoring felt a bit extensive, but required by my approach.
|
PR addressing code changes, and comments replies are also provided. |
|
Indeed, there was extensive refactoring. I've implemented the following new approach:
This PR implements the changes |
|
Thanks @Humbulani1234! LGTM, can you please generate the .ipynb and .md files? |
|
Generated |
This PR adapts the script
movielens_recommendations_transformers.pyto be Backend-Agnostic