C5W4A1 exercise 7 decoder

Below is the test error message. I am not sure why the pos_encoding dimension is (1, 50, 512). I looked at the embedding_dim in the test code it is 4.

pos_encoding (1, 50, 512)
x tf.Tensor(
[[[-0.04945436 -0.07790992 0.02245057 -0.0741863 ]
[ 0.01721156 0.01480629 -0.0819052 0.01511107]
[ 0.02541938 0.09872026 -0.09528103 -0.09266322]]

[[ 0.01721156 0.01480629 -0.0819052 0.01511107]
[ 0.02541938 0.09872026 -0.09528103 -0.09266322]
[ 0.02883019 0.06164945 0.07953096 0.02737803]]], shape=(2, 3, 4), dtype=float32)
pos_encoding (1, 50, 512)

InvalidArgumentError Traceback (most recent call last)
in
1 # UNIT TEST
----> 2 Decoder_test(Decoder, create_look_ahead_mask, create_padding_mask)

~/work/W4A1/public_tests.py in Decoder_test(target, create_look_ahead_mask, create_padding_mask)
218 target_vocab_size,
219 maximum_position_encoding)
→ 220 x, attention_weights = decoderk(x_array, encoderq_output, False, look_ahead_mask, None)
221 assert tf.is_tensor(x), “Wrong type for x. It must be a dict”
222 assert np.allclose(tf.shape(x), tf.shape(encoderq_output)), f"Wrong shape. We expected { tf.shape(encoderq_output)}"

/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, enc_output, training, look_ahead_mask, padding_mask)
58 print(“x”,x)
59 print(“pos_encoding”, pos_encoding.shape)
—> 60 x += pos_encoding[:, :seq_len, :]
61
62 # apply a dropout layer to x

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/math_ops.py in binary_op_wrapper(x, y)
1162 with ops.name_scope(None, op_name, [x, y]) as name:
1163 try:
→ 1164 return func(x, y, name=name)
1165 except (TypeError, ValueError) as e:
1166 # Even if dispatching the op failed, the RHS may be a tensor aware

/opt/conda/lib/python3.7/site-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
199 “”“Call target, and fall back on dispatchers if there is a TypeError.”“”
200 try:
→ 201 return target(*args, **kwargs)
202 except (TypeError, ValueError):
203 # Note: convert_to_eager_tensor currently raises a ValueError, not a

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/math_ops.py in _add_dispatch(x, y, name)
1484 return gen_math_ops.add(x, y, name=name)
1485 else:
→ 1486 return gen_math_ops.add_v2(x, y, name=name)
1487
1488

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/gen_math_ops.py in add_v2(x, y, name)
470 return _result
471 except _core._NotOkStatusException as e:
→ 472 _ops.raise_from_not_ok_status(e, name)
473 except _core._FallbackException:
474 pass

/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in raise_from_not_ok_status(e, name)
6860 message = e.message + (" name: " + name if name is not None else “”)
6861 # pylint: disable=protected-access
→ 6862 six.raise_from(core._status_to_exception(e.code, message), None)
6863 # pylint: enable=protected-access
6864

/opt/conda/lib/python3.7/site-packages/six.py in raise_from(value, from_value)

InvalidArgumentError: Incompatible shapes: [2,3,4] vs. [1,3,512] [Op:AddV2]

1 Like

Why are you using pos_encoding from the global scope? See the constructor function inside class Decoder for the correct variable to use.

3 Likes

I don’t know what to say… :sweat_smile: :sweat_smile: :sweat_smile:
Thank you! Thank you!

1 Like