Skip to content

StringLookup does not work on torch.Tensor #21255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
DLumi opened this issue May 6, 2025 · 3 comments
Open

StringLookup does not work on torch.Tensor #21255

DLumi opened this issue May 6, 2025 · 3 comments
Assignees
Labels
stat:contributions welcome A pull request to fix this issue would be welcome. type:Bug

Comments

@DLumi
Copy link

DLumi commented May 6, 2025

keras.layers.StringLookup throws an error when calling on a torch.Tensor or a numpy array (although, both are supposed to be valid backends?)

Colab example:
https://colab.research.google.com/drive/1MYcIsJJuiPcvykC8ifOyE4vQk6aAo2UQ

Am I missing something here, or torch support didn't reach here yet?

@dhantule
Copy link
Contributor

dhantule commented May 9, 2025

Hi @DLumi, thanks for reporting this.

The StringLookup layer uses tensorflow internally, it relies on tensorflow operations and expects tf.tensors. Using tf.tensor or a np.array works fine with tensorflow backend but using torch.tensor or np.array raises a Value Error with torch backend in this gist. We'll look into this and update you.

@dhantule dhantule added the keras-team-review-pending Pending review by a Keras team member. label May 19, 2025
@VarunS1997
Copy link
Collaborator

One could convert the torch tensor into a TF tensor as part of the StringLookup, and then convert back as output. If you'd like, we're open to contributions on this, @DLumi

@VarunS1997 VarunS1997 added the stat:contributions welcome A pull request to fix this issue would be welcome. label May 22, 2025
@sachinprasadhs sachinprasadhs removed the keras-team-review-pending Pending review by a Keras team member. label May 22, 2025
@DLumi
Copy link
Author

DLumi commented May 23, 2025

@VarunS1997 correct me if I'm wrong, but if the package is multi-backend, it means it should be able to run itself on just one backend completely fine. So the way I see it, the function should have equivalents for torch and jax without relying on tensorflow at all. Or it needs to be axed entirely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stat:contributions welcome A pull request to fix this issue would be welcome. type:Bug
Projects
None yet
Development

No branches or pull requests

5 participants