Week 4 assignment 1 UNQ_C4 The first argument to `Layer.call` must always be passed

I got the following erro: The first argument to Layer.call must always be passed.
What wrong with my parameters?


ValueError Traceback (most recent call last)
in
1 # UNIT TEST
----> 2 EncoderLayer_test(EncoderLayer)

~/work/W4A1/public_tests.py in EncoderLayer_test(target)
84 encoder_layer1 = target(4, 2, 8)
85 tf.random.set_seed(10)
—> 86 encoded = encoder_layer1(q, True, np.array([[1, 0, 1]]))
87
88 assert tf.is_tensor(encoded), “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)
41 attn_output = self.mha(batch_size=x.shape[0],
42 input_seq_len=x.shape[1],
—> 43 fully_connected_dim=x.shape[2]) # Self attention (batch_size, input_seq_len, fully_connected_dim)
44
45 # apply layer normalization on sum of the input and the attention output to get the

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in call(self, *args, **kwargs)
940 # not to any other argument.
941 # - setting the SavedModel saving spec.
→ 942 inputs, args, kwargs = self._split_out_first_arg(args, kwargs)
943 input_list = nest.flatten(inputs)
944

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in _split_out_first_arg(self, args, kwargs)
3046 else:
3047 raise ValueError(
→ 3048 ‘The first argument to Layer.call must always be passed.’)
3049 return inputs, args, kwargs
3050

ValueError: The first argument to Layer.call must always be passed.

You are not calling self.mha with the right parameters.
Please read the 1st point from the writeup of EncoderLayer().

Here’s the doc for MultiHeadAttention

1 Like