C4W2 - Ex3 Decoder - EagerTensor not callable

Hi!

The following error is thrown by line x += self.pos_encoding(maximum_position_encoding, self.embedding_dim) in the Decoder#call method:

TypeError: Exception encountered when calling layer 'decoder' (type Decoder).

'tensorflow.python.framework.ops.EagerTensor' object is not callable

Call arguments received by layer 'decoder' (type Decoder):
  • x=tf.Tensor(shape=(3, 4), dtype=int64)
  • enc_output=tf.Tensor(shape=(3, 7, 9), dtype=float64)
  • training=False
  • look_ahead_mask=tf.Tensor(shape=(1, 4, 4), dtype=float32)
  • padding_mask=None

When I remove self.embedding_dim from the arguments passed into the self.pos_encoding method, I get a similar error:

TypeError: Exception encountered when calling layer 'decoder_1' (type Decoder).

'tensorflow.python.framework.ops.EagerTensor' object is not callable

Call arguments received by layer 'decoder_1' (type Decoder):
  • x=tf.Tensor(shape=(3, 4), dtype=int64)
  • enc_output=tf.Tensor(shape=(3, 7, 9), dtype=float64)
  • training=False
  • look_ahead_mask=tf.Tensor(shape=(1, 4, 4), dtype=float32)
  • padding_mask=None

And here is what I am passing the self.dec_layers: x, block1, block2 = self.dec_layers(x, enc_output, training, look_ahead_mask, padding_mask).

When I add return_attention_scores=True to the arguments just above I get a third similar error that seems to indicate I’m making progress but I can’t quite figure out what the issue is:

TypeError: Exception encountered when calling layer 'decoder_2' (type Decoder).

'tensorflow.python.framework.ops.EagerTensor' object is not callable

Call arguments received by layer 'decoder_2' (type Decoder):
  • x=tf.Tensor(shape=(3, 4), dtype=int64)
  • enc_output=tf.Tensor(shape=(3, 7, 9), dtype=float64)
  • training=False
  • look_ahead_mask=tf.Tensor(shape=(1, 4, 4), dtype=float32)
  • padding_mask=None

Do you know where this might come from?

Thanks!

1 Like

My interpretation of that error message is that what is wrong is that your code is treating self.pos_encoding as a function and calling it with arguments. But the error is telling you that it’s not a function: it’s a tensor. So I would start by looking at how you defined self.pos_encoding. Either you defined it incorrectly or you are using it incorrectly.

2 Likes

You’re right, using it as a tensor worked as expected. I also needed to change how I use self.dec_layers as it’s not a function either. Thanks for your help!

2 Likes

Glad to hear that my hints were useful. The “meta” lesson here is that the First Law of Debugging is “Believe the Error Message”. If you don’t understand what it’s telling you, that’s the first problem you need to solve. :nerd_face: