tensorflow / tensorflow/recommenders
TypeError: Cannot convert 1 to EagerTensor of dtype string
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2k
- Forks
- 300
- PR merge metrics
- No merged PRs in 30d
Description
Getting below error when trying Quickstart example.
File "/Users/terry/Documents/project/recommender/recommenders/collab_filtering_movie.py", line 245, in
index.index_from_dataset(
File "/Users/terry/Documents/project/recommender/recommenders/tensorflow_recommenders/layers/factorized_top_k.py", line 215, in index_from_dataset
return self.index(candidates, identifiers)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/terry/Documents/project/recommender/recommenders/tensorflow_recommenders/layers/factorized_top_k.py", line 550, in index
self._identifiers = self.add_weight(
^^^^^^^^^^^^^^^^
File "/Users/terry/Documents/project/recommender/recommenders/.venv/lib/python3.12/site-packages/keras/src/layers/layer.py", line 522, in add_weight
variable = backend.Variable(
^^^^^^^^^^^^^^^^^
File "/Users/terry/Documents/project/recommender/recommenders/.venv/lib/python3.12/site-packages/keras/src/backend/common/variables.py", line 162, in init
value = initializer(shape, dtype=dtype)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/terry/Documents/project/recommender/recommenders/.venv/lib/python3.12/site-packages/keras/src/initializers/constant_initializers.py", line 35, in call
return ops.cast(self.value, dtype=dtype) * ops.ones(
^^^^^^^^^
File "/Users/terry/Documents/project/recommender/recommenders/.venv/lib/python3.12/site-packages/keras/src/ops/numpy.py", line 5948, in ones
return backend.numpy.ones(shape, dtype=dtype)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/terry/Documents/project/recommender/recommenders/.venv/lib/python3.12/site-packages/keras/src/backend/tensorflow/numpy.py", line 611, in ones
return tf.ones(shape, dtype=dtype)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/terry/Documents/project/recommender/recommenders/.venv/lib/python3.12/site-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/Users/terry/Documents/project/recommender/recommenders/.venv/lib/python3.12/site-packages/tensorflow/python/framework/constant_op.py", line 108, in convert_to_eager_tensor
return ops.EagerTensor(value, ctx.device_name, dtype)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Cannot convert 1 to EagerTensor of dtype string
OSX 14.2.1
python 3.12
tensorflow 2.16.2
tensorflow-recommenders 0.7.3
tensorflow-datasets 4.9.6
keras 3.4.1
I've overcome this by changing the keras code like below - "site-packages/keras/src/initializers/constant_initializers.py", line 35
def __call__(self, shape, dtype=None):
dtype = standardize_dtype(dtype)
return ops.cast(self.value, dtype=dtype) if dtype == "string" else ops.cast(self.value, dtype=dtype) * ops.ones(
shape=shape, dtype=dtype
)
Not sure how this code has been this way and worked but the Quickstart example is not working with this code for sure.
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 Quickstart entry point in collab_filtering_movie.py around line 245, then trace index_from_dataset and index in tensorflow_recommenders/layers/factorized_top_k.py around lines 215 and 550. Reproduce the failure with the listed TensorFlow and Keras versions and verify that the Quickstart completes without the string EagerTensor TypeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- keras, python, tensorflow
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100