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

Error while running the latest English_Spanish_Transformer.ipynb #18

Open
AsH1605 opened this issue Sep 13, 2024 · 0 comments
Open

Error while running the latest English_Spanish_Transformer.ipynb #18

AsH1605 opened this issue Sep 13, 2024 · 0 comments

Comments

@AsH1605
Copy link

AsH1605 commented Sep 13, 2024

Error thrown at

    def compute_mask(self, inputs, mask=None):
        return tf.math.not_equal(inputs, 0)

Stacktrace

ValueError                                Traceback (most recent call last)
[<ipython-input-10-cf8901b39907>](https://localhost:8080/#) in <cell line: 6>()
      4 
      5 encoder_inputs = keras.Input(shape=(None,), dtype="int64", name="encoder_inputs")
----> 6 x = PositionalEmbedding(sequence_length, vocab_size, embed_dim)(encoder_inputs)
      7 encoder_outputs = TransformerEncoder(embed_dim, latent_dim, num_heads)(x)
      8 encoder = keras.Model(encoder_inputs, encoder_outputs)

1 frames
[<ipython-input-9-23371d180913>](https://localhost:8080/#) in compute_mask(self, inputs, mask)
     57 
     58     def compute_mask(self, inputs, mask=None):
---> 59         return tf.math.not_equal(inputs, 0)
     60 
     61     def get_config(self):

ValueError: A KerasTensor cannot be used as input to a TensorFlow function. A KerasTensor is a symbolic placeholder for a shape and dtype, used when constructing Keras Functional models or Keras Functions. You can only use it as input to a Keras layer or a Keras operation (from the namespaces `keras.layers` and `keras.operations`). You are likely doing something like:


x = Input(...)
...
tf_fn(x)  # Invalid.

What you should do instead is wrap `tf_fn` in a layer:


class MyLayer(Layer):
    def call(self, x):
        return tf_fn(x)

x = MyLayer()(x)
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

1 participant