C5 W3 A1 NMT 'modelf' function : AssertionError

Hi everyone,

I’m encountering an issue in my Neural Machine Translation model and need some guidance.

The error I’m seeing is:

‘AssertionError: Error in test. The lists contain a different number of elements’

This seems to be due to a mismatch between the expected and actual number of elements in the output. I suspect the issue lies with how I’m handling the output sequence in the loop or some problem with the LSTM states during each iteration.

Could someone help me with:

  • Ensuring that the correct number of outputs are generated and matched.
  • Debugging why there is a mismatch in the output sequence size.
  • Identifying any potential issues with states of the units or the attention mechanism in the setup.

Let me know if you need any specific parts of the code to help debug the issue.

Looking forward to your help!

Best regards,
Joseph Emerald.

That error message is printed by the comparator function. That means your model does not have the correct number of layers. The best way to understand where you went wrong is to compare the summary of your actual model with the “expected” value that is shown in that cell. Try adding this cell after the test cell to see your model:

print(model.summary())

Where is it different from the “expected” model shown above? Please show us what you get from the above.


this is how the summary of my model looks like:
“”"
[[‘InputLayer’, [(None, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(3,)], 0],
[‘TensorFlowOpLayer’, [()], 0],
[‘TensorFlowOpLayer’, [()], 0],
[‘TensorFlowOpLayer’, [(None, 1, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘InputLayer’, [(None, 30, 37)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 30, 64)], 0],
[‘TensorFlowOpLayer’, [(3,)], 0],
[‘Bidirectional’, (None, 30, 64), 17920],
[‘TensorFlowOpLayer’, [(None, None, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 30, 128)], 0],
[‘Dense’, (None, 30, 10), 1290, ‘tanh’],
[‘Dense’, (None, 30, 1), 11, ‘relu’],
[‘Activation’, (None, 30, 1), 0],
[‘TensorFlowOpLayer’, [(None, 30, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 64)], 0],
[‘InputLayer’, [(None, 64)], 0],
[‘LSTM’,
[(None, 64), (None, 64), (None, 64)],
33024,
[(None, 1, 64), (None, 64), (None, 64)],
‘tanh’],
[‘TensorFlowOpLayer’, [(None, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(3,)], 0],
[‘TensorFlowOpLayer’, [()], 0],
[‘TensorFlowOpLayer’, [()], 0],
[‘TensorFlowOpLayer’, [(None, 1, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 30, 64)], 0],
[‘TensorFlowOpLayer’, [(3,)], 0],
[‘TensorFlowOpLayer’, [(None, None, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 30, 128)], 0],
[‘TensorFlowOpLayer’, [(None, 30, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(3,)], 0],
[‘TensorFlowOpLayer’, [()], 0],
[‘TensorFlowOpLayer’, [()], 0],
[‘TensorFlowOpLayer’, [(None, 1, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 30, 64)], 0],
[‘TensorFlowOpLayer’, [(3,)], 0],
[‘TensorFlowOpLayer’, [(None, None, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 30, 128)], 0],
[‘TensorFlowOpLayer’, [(None, 30, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(3,)], 0],
[‘TensorFlowOpLayer’, [()], 0],
[‘TensorFlowOpLayer’, [()], 0],
[‘TensorFlowOpLayer’, [(None, 1, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 30, 64)], 0],
[‘TensorFlowOpLayer’, [(3,)], 0],
[‘TensorFlowOpLayer’, [(None, None, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 30, 128)], 0],
[‘TensorFlowOpLayer’, [(None, 30, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(3,)], 0],
[‘TensorFlowOpLayer’, [()], 0],
[‘TensorFlowOpLayer’, [()], 0],
[‘TensorFlowOpLayer’, [(None, 1, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 30, 64)], 0],
[‘TensorFlowOpLayer’, [(3,)], 0],
[‘TensorFlowOpLayer’, [(None, None, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 30, 128)], 0],
[‘TensorFlowOpLayer’, [(None, 30, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(3,)], 0],
[‘TensorFlowOpLayer’, [()], 0],
[‘TensorFlowOpLayer’, [()], 0],
[‘TensorFlowOpLayer’, [(None, 1, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 30, 64)], 0],
[‘TensorFlowOpLayer’, [(3,)], 0],
[‘TensorFlowOpLayer’, [(None, None, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 30, 128)], 0],
[‘TensorFlowOpLayer’, [(None, 30, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(3,)], 0],
[‘TensorFlowOpLayer’, [()], 0],
[‘TensorFlowOpLayer’, [()], 0],
[‘TensorFlowOpLayer’, [(None, 1, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 30, 64)], 0],
[‘TensorFlowOpLayer’, [(3,)], 0],
[‘TensorFlowOpLayer’, [(None, None, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 30, 128)], 0],
[‘TensorFlowOpLayer’, [(None, 30, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(3,)], 0],
[‘TensorFlowOpLayer’, [()], 0],
[‘TensorFlowOpLayer’, [()], 0],
[‘TensorFlowOpLayer’, [(None, 1, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 30, 64)], 0],
[‘TensorFlowOpLayer’, [(3,)], 0],
[‘TensorFlowOpLayer’, [(None, None, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 30, 128)], 0],
[‘TensorFlowOpLayer’, [(None, 30, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(3,)], 0],
[‘TensorFlowOpLayer’, [()], 0],
[‘TensorFlowOpLayer’, [()], 0],
[‘TensorFlowOpLayer’, [(None, 1, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 30, 64)], 0],
[‘TensorFlowOpLayer’, [(3,)], 0],
[‘TensorFlowOpLayer’, [(None, None, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 30, 128)], 0],
[‘TensorFlowOpLayer’, [(None, 30, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(3,)], 0],
[‘TensorFlowOpLayer’, [()], 0],
[‘TensorFlowOpLayer’, [()], 0],
[‘TensorFlowOpLayer’, [(None, 1, 1, 64)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(1,)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 30, 64)], 0],
[‘TensorFlowOpLayer’, [(3,)], 0],
[‘TensorFlowOpLayer’, [(None, None, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 30, 128)], 0],
[‘TensorFlowOpLayer’, [(None, 30, 64)], 0],
[‘TensorFlowOpLayer’, [(None, 1, 64)], 0],
[‘Dense’, (None, 11), 715, ‘softmax’]]
“”"

And for comparison, here is the “expected” value that they show:

expected_summary = [['InputLayer', [(None, 30, 37)], 0],
                         ['InputLayer', [(None, 64)], 0],
                         ['Bidirectional', (None, 30, 64), 17920],
                         ['RepeatVector', (None, 30, 64), 0, 30],
                         ['Concatenate', (None, 30, 128), 0],
                         ['Dense', (None, 30, 10), 1290, 'tanh'],
                         ['Dense', (None, 30, 1), 11, 'relu'],
                         ['Activation', (None, 30, 1), 0],
                         ['Dot', (None, 1, 64), 0],
                         ['InputLayer', [(None, 64)], 0],
                         ['LSTM',[(None, 64), (None, 64), (None, 64)], 33024,[(None, 1, 64), (None, 64), (None, 64)],'tanh'],
                         ['Dense', (None, 11), 715, 'softmax']]

Notice that the first two instances of “InputLayer” occur in the wrong order in your version. And there are lots of TensorFlowOpLayer values that should not be there.

In terms of the order in which the summary lists the layers, it is determined by the order in which arguments appear in the compute graph. Perhaps your arguments to the BiDirectional API are not correct. Please have another look at the instructions that they gave in that section and compare that to what your code actually does.