Skip to content
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

Issues with StringLookUp layer and keras.ops.matmul #20734

Closed
Humbulani1234 opened this issue Jan 7, 2025 · 1 comment
Closed

Issues with StringLookUp layer and keras.ops.matmul #20734

Humbulani1234 opened this issue Jan 7, 2025 · 1 comment
Assignees

Comments

@Humbulani1234
Copy link

Humbulani1234 commented Jan 7, 2025

Here is my input to the keras preprocessing StringLookup layer: <tf.Tensor 'args_4:0' shape=(None,) dtype=string> and it returns: <tf.Tensor 'string_lookup_1/Squeeze:0' shape=() dtype=int64>. The code snippet is as follows:

            index = layers.StringLookup(
                vocabulary=vocabulary, mask_token=None, num_oov_indices=1, output_mode="int"
            )
            # Convert the string input values into integer indices.
            value_index = index(feature_name)

Question 1: Isn't the output shape supposed to maintain the same shape = (None,) instead of shape = (). None is a batch dimension for tf.data.Dataset elements.

Question 2: How do I perform matmul in Keras so it runs on tensorflow, jax and torch? The following only runs on tensorflow, but fails on others. Where x=<tf.Tensor 'stack:0' shape=(None, 40, 16) dtype=float32> and v=<tf.Tensor 'ExpandDims_7:0' shape=(None, 40, 1) dtype=float32>. The output shape should be shape = (None, 16) and this are Symbolic tensors.

result = keras.ops.dot(v, keras.ops.transpose(x))
result = keras.ops.reshape(result, (-1, 16))

jax error:

TypeError: dot_general requires contracting dimensions to have the same shape, got (1,) and (40,).

torch error:

RuntimeError: The size of tensor a (83) must match the size of tensor b (16) at non-singleton dimension 0
@Humbulani1234
Copy link
Author

Resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants