Modelf error: Week 3, Assignment 1 , Exercise 2

I’m not sure what is wrong with my code. Any suggestions.


ValueError Traceback (most recent call last)
in
34
35
—> 36 modelf_test(modelf)

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)
42 # Step 2.B: Apply the post-attention LSTM cell to the “context” vector.
43 # Don’t forget to pass: initial_state = [hidden state, cell state] (≈ 1 line)
—> 44 s, _, c = post_activation_LSTM_cell(inputs= context, initial_state=[s, c])
45
46

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/layers/recurrent.py in call(self, inputs, initial_state, constants, **kwargs)
707 # Perform the call with temporarily replaced input_spec
708 self.input_spec = full_input_spec
→ 709 output = super(RNN, self).call(full_input, **kwargs)
710 # Remove the additional_specs from input spec and keep the rest. It is
711 # important to keep since the input spec was populated by build(), and

/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)
1090 # TODO(reedwm): We should assert input compatibility after the inputs
1091 # are casted, not before.
→ 1092 input_spec.assert_input_compatibility(self.input_spec, inputs, self.name)
1093 graph = backend.get_graph()
1094 # Use self._name_scope() to avoid auto-incrementing the name.

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/input_spec.py in assert_input_compatibility(input_spec, inputs, layer_name)
156 str(len(input_spec)) + ’ inputs, ’
157 'but it received ’ + str(len(inputs)) +
→ 158 ’ input tensors. Inputs received: ’ + str(inputs))
159 for input_index, (x, spec) in enumerate(zip(inputs, input_spec)):
160 if spec is None:

ValueError: Layer lstm expects 33 inputs, but it received 3 input tensors. Inputs received: [<tf.Tensor ‘dot/MatMul_21:0’ shape=(None, 1, 64) dtype=float32>, <tf.Tensor ‘s0_21:0’ shape=(None, 64) dtype=float32>, <tf.Tensor ‘c0_21:0’ shape=(None, 64) dtype=float32>]

I don’t see any “modelf” function in the Course 5 Week 4 programming assignment.

1 Like

It’s week 3. Sorry, my mistake.

There may be a problem with your code for “a = …”, or “context = …”, or maybe your one_step_attention() function has a problem.

Or, maybe you should not use “inputs=” in this line of code:

s, _, c = post_activation_LSTM_cell(inputs= context, initial_state=[s, c])

2 Likes

That was it. Thank you

1 Like

I had the same problem. “inputs= …” defined was not the problem. Restarting Kernel fixed it in my case.