DLS Course 5 Week 4 Exercise 5

i run my code but i keep getting the following error message:

TypeError Traceback (most recent call last)
in
28 print("\033[92mAll tests passed")
29
—> 30 Encoder_test(Encoder)

in Encoder_test(target)
14 x = np.array([[2, 1, 3], [1, 2, 0]])
15
—> 16 encoderq_output = encoderq(x, True, None)
17
18 assert tf.is_tensor(encoderq_output), “Wrong type. Output must be a tensor”

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in call(self, *args, **kwargs)
1010 with autocast_variable.enable_auto_cast_variables(
1011 self._compute_dtype_object):
→ 1012 outputs = call_fn(inputs, *args, **kwargs)
1013
1014 if self._activity_regularizer:

in call(self, x, training, mask)
56 # Pass the output through the stack of encoding layers
57 for i in range(self.num_layers):
—> 58 x = self.enc_layers(x) # code here x =None
59 # END CODE HERE
60

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in call(self, *args, **kwargs)
1010 with autocast_variable.enable_auto_cast_variables(
1011 self._compute_dtype_object):
→ 1012 outputs = call_fn(inputs, *args, **kwargs)
1013
1014 if self._activity_regularizer:

TypeError: call() missing 1 required positional argument: ‘mask’

Any help?

The stack trace and error message says that the "self.enc_layers() function in your Encoder() “call” method is missing the “mask” argument.

1 Like

To verify this, look at the call method in the EncoderLayer() class. That tells you the parameters that you need to pass from self.enc_layers().

1 Like

In the definition of the self.enc_layers below is the square brackets […] supposed to be there?

self.enc_layers = [EncoderLayer(embedding_dim=self.embedding_dim,
num_heads=num_heads,
fully_connected_dim=fully_connected_dim,
dropout_rate=dropout_rate,
layernorm_eps=layernorm_eps)
for _ in range(self.num_layers)]

whenever i call self.enc_layers it says it is uncallable due to the square brackets […]

typeerror: ‘listwrapper’ object is not callable

Hello @gillynatter, the problem you are having is that you are trying to call the complete list for each loop, as the error indicates.
You may have noticed that self.enc_layers is actually a list of Encoder layers, and you are calling it for each value of i. What you want is to call the layers one by one. As a hint you can use the i index from the for loop.
Hope that helps!

3 Likes

That helped. I solved this problem. Thanks!

Hey, I am facing the same error. How did you resolve it?

It’s solved in this thread:

3 Likes