Error in exercise 2 of the Neural Machine translation problem

I am getting an error in the second LSTM function - “list assignment index out of range” . Can’t identify where the error could be.

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-14-1492e4d59c1c> in <module>
     34 
     35 
---> 36 modelf_test(modelf)

<ipython-input-14-1492e4d59c1c> in modelf_test(target)
     11 
     12 
---> 13     model = target(Tx, Ty, n_a, n_s, len_human_vocab)
     14 
     15     print(summary(model))

<ipython-input-13-f92568c63de4> in modelf(Tx, Ty, n_a, n_s, human_vocab_size, machine_vocab_size)
     48         # Don't forget to pass: initial_state = [hidden state, cell state]
     49         # Remember: s = hidden state, c = cell state
---> 50         _, s, c = post_activation_LSTM_cell(inputs=n_s, initial_state=[s, c])(context)
     51 
     52         # Step 2.C: Apply Dense layer to the hidden state output of the post-attention LSTM (≈ 1 line)

/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)
    980       with ops.name_scope_v2(name_scope):
    981         if not self.built:
--> 982           self._maybe_build(inputs)
    983 
    984         with ops.enable_auto_cast_variables(self._compute_dtype_object):

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in _maybe_build(self, inputs)
   2641         # operations.
   2642         with tf_utils.maybe_init_scope(self):
-> 2643           self.build(input_shapes)  # pylint:disable=not-callable
   2644       # We must set also ensure that the layer is marked as built, and the build
   2645       # shape is stored since user defined build functions may not be calling

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/layers/recurrent.py in build(self, input_shape)
    564       # This indicates the there is only one input.
    565       if self.input_spec is not None:
--> 566         self.input_spec[0] = get_input_spec(input_shape)
    567       else:
    568         self.input_spec = [get_input_spec(input_shape)]

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/layers/recurrent.py in get_input_spec(shape)
    542       batch_index, time_step_index = (1, 0) if self.time_major else (0, 1)
    543       if not self.stateful:
--> 544         input_spec_shape[batch_index] = None
    545       input_spec_shape[time_step_index] = None
    546       return InputSpec(shape=tuple(input_spec_shape))

IndexError: list assignment index out of range

This isn’t correct.
image

“context” isn’t a separate parameter list.
And “inputs=n_s” should not be there.

1 Like

Thank you! Got it. On to the next lab.

1 Like