DLS course 5 week3

I am getting an error when I run the cell modef_tf. I have restarted the kernel a few times and tried this. I am still getting the same error in Concatenate (). Could you please help? Thanks. I have pasted the error message.

in modelf_test(target)
11
12
—> 13 model = target(Tx, Ty, n_a, n_s, len_human_vocab, len_machine_vocab)
14
15 print(summary(model))

in modelf(Tx, Ty, n_a, n_s, human_vocab_size, machine_vocab_size)
38
39 # Step 2.A: Perform one step of the attention mechanism to get back the context vector at step t (≈ 1 line)
—> 40 context = one_step_attention(a, s)
41
42 # Step 2.B: Apply the post-attention LSTM cell to the “context” vector.

in one_step_attention(a, s_prev)
20 # Use concatenator to concatenate a and s_prev on the last axis (≈ 1 line)
21 # For grading purposes, please list ‘a’ first and ‘s_prev’ second, in this order.
—> 22 concat = concatenator ( [a, s_prev])
23 # Use densor1 to propagate concat through a small fully-connected neural network to compute the “intermediate energies” variable e. (≈1 lines)
24 e = densor1 ( concat)

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in call(self, *args, **kwargs)
924 if _in_functional_construction_mode(self, inputs, args, kwargs, input_list):
925 return self._functional_construction_call(inputs, args, kwargs,
→ 926 input_list)
927
928 # Maintains info about the Layer.call stack.

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in _functional_construction_call(self, inputs, args, kwargs, input_list)
1115 try:
1116 with ops.enable_auto_cast_variables(self._compute_dtype_object):
→ 1117 outputs = call_fn(cast_inputs, *args, **kwargs)
1118
1119 except errors.OperatorNotAllowedInGraphError as e:

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/layers/merge.py in call(self, inputs)
181 return y
182 else:
→ 183 return self._merge_function(inputs)
184
185 @tf_utils.shape_type_conversion

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/layers/merge.py in _merge_function(self, inputs)
520
521 def _merge_function(self, inputs):
→ 522 return K.concatenate(inputs, axis=self.axis)
523
524 @tf_utils.shape_type_conversion

/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/keras/backend.py in concatenate(tensors, axis)
2879 return ragged_concat_ops.concat(tensors, axis)
2880 else:
→ 2881 return array_ops.concat([to_dense(x) for x in tensors], axis)
2882
2883

/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/array_ops.py in concat(values, axis, name)
1652 dtype=dtypes.int32).get_shape().assert_has_rank(0)
1653 return identity(values[0], name=name)
→ 1654 return gen_array_ops.concat_v2(values=values, axis=axis, name=name)
1655
1656

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/gen_array_ops.py in concat_v2(values, axis, name)
1220 _attr_N = len(values)
1221 _, _, _op, _outputs = _op_def_library._apply_op_helper(
→ 1222 “ConcatV2”, values=values, axis=axis, name=name)
1223 _result = _outputs[:]
1224 if _execute.must_record_gradient():

/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/op_def_library.py in _apply_op_helper(op_type_name, name, **keywords)
742 op = g._create_op_internal(op_type_name, inputs, dtypes=None,
743 name=scope, input_types=input_types,
→ 744 attrs=attr_protos, op_def=op_def)
745
746 # outputs is returned as a separate return value so that the output

/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/func_graph.py in _create_op_internal(self, op_type, inputs, dtypes, input_types, name, attrs, op_def, compute_device)
591 return super(FuncGraph, self)._create_op_internal( # pylint: disable=protected-access
592 op_type, inputs, dtypes, input_types, name, attrs, op_def,
→ 593 compute_device)
594
595 def capture(self, tensor, name=None, shape=None):

/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in _create_op_internal(self, op_type, inputs, dtypes, input_types, name, attrs, op_def, compute_device)
3483 input_types=input_types,
3484 original_op=self._default_original_op,
→ 3485 op_def=op_def)
3486 self._create_op_helper(ret, compute_device=compute_device)
3487 return ret

/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in init(self, node_def, g, inputs, output_types, control_inputs, input_types, original_op, op_def)
1973 op_def = self._graph._get_op_def(node_def.op)
1974 self._c_op = _create_c_op(self._graph, node_def, inputs,
→ 1975 control_input_ops, op_def)
1976 name = compat.as_str(node_def.name)
1977 # pylint: enable=protected-access

/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in _create_c_op(graph, node_def, inputs, control_inputs, op_def)
1813 except errors.InvalidArgumentError as e:
1814 # Convert to ValueError for backwards compatibility.
→ 1815 raise ValueError(str(e))
1816
1817 return c_op

ValueError: Shape must be rank 2 but is rank 3 for ‘{{node concatenate/concat_3}} = ConcatV2[N=2, T=DT_FLOAT, Tidx=DT_INT32](bidirectional_3/concat, repeat_vector/Tile_3, concatenate/concat_3/axis)’ with input shapes: [?,64], [?,30,64], .

Please ignore my earlier post. There was an error in calling bidirectional LSTM. I did not set return_sequences = True. Now the test is passing. Thank you.