Skip to content

Title: ValueError when initializing tfrs.metrics.FactorizedTopK with a candidates dataset. #748

Open

Description

@malinphy

I encountered a ValueError when attempting to initialize tfrs.metrics.FactorizedTopK with a dataset of candidate embeddings in the TensorFlow Recommenders library. It appears that the function is trying to convert a string into a shape, resulting in an error. I have been trying the sample code which was given at the following web page https://www.tensorflow.org/recommenders/examples/basic_retrieval
It is not working on the given colab link.

The following line

metrics = tfrs.metrics.FactorizedTopK(
  candidates=movies.batch(128).map(movie_model)
)

gives the following error.

ValueError                                Traceback (most recent call last)

[<ipython-input-14-e82bf640c968>](https://localhost:8080/#) in <cell line: 1>()
----> 1 metrics = tfrs.metrics.FactorizedTopK(
      2   candidates=movies.batch(128).map(movie_model)
      3 )

5 frames

[/usr/local/lib/python3.10/dist-packages/keras/src/backend/common/variables.py](https://localhost:8080/#) in standardize_shape(shape)
    533             continue
    534         if not is_int_dtype(type(e)):
--> 535             raise ValueError(
    536                 f"Cannot convert '{shape}' to a shape. "
    537                 f"Found invalid entry '{e}' of type '{type(e)}'. "

ValueError: Cannot convert '('c', 'o', 'u', 'n', 't', 'e', 'r')' to a shape. Found invalid entry 'c' of type '<class 'str'>'.

image
image

Activity

  1. malinphy commented on Dec 11, 2024

    @malinphy
    Author

    The following solution #712 (comment) works for the given example.

  2. added a commit that references this issue on Sep 26, 2025
    74c5fd8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions