# Course 5 week 3 assignment 1 exercise 2

## Hi. I’m getting this error. Can you point me in the right direction? [[‘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, 64), 4160, ‘softmax’], [‘Dense’, (None, 64), 4160, ‘softmax’], [‘Dense’, (None, 64), 4160, ‘softmax’], [‘Dense’, (None, 64), 4160, ‘softmax’], [‘Dense’, (None, 64), 4160, ‘softmax’], [‘Dense’, (None, 64), 4160, ‘softmax’], [‘Dense’, (None, 64), 4160, ‘softmax’], [‘Dense’, (None, 64), 4160, ‘softmax’], [‘Dense’, (None, 64), 4160, ‘softmax’], [‘Dense’, (None, 64), 4160, ‘softmax’]]

AssertionError Traceback (most recent call last)
in
33
34
—> 35 modelf_test(modelf)

in modelf_test(target)
30 assert len(model.outputs) == 10, f"Wrong output shape. Expected 10 != {len(model.outputs)}"
31
—> 32 comparator(summary(model), expected_summary)
33
34

~/work/W3A1/test_utils.py in comparator(learner, instructor)
16 def comparator(learner, instructor):
17 if len(learner) != len(instructor):
—> 18 raise AssertionError(“Error in test. The lists contain a different number of elements”)
19 for index, a in enumerate(instructor):
20 b = learner[index]

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

1 Like

Please use the following snippet to compare your model architecture against the expected result:

``````from pprint import pprint
pprint(summary(model))
``````

## Thanks! Here you go. [[‘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, 64), 4160, ‘softmax’], [‘Dense’, (None, 64), 4160, ‘softmax’], [‘Dense’, (None, 64), 4160, ‘softmax’], [‘Dense’, (None, 64), 4160, ‘softmax’], [‘Dense’, (None, 64), 4160, ‘softmax’], [‘Dense’, (None, 64), 4160, ‘softmax’], [‘Dense’, (None, 64), 4160, ‘softmax’], [‘Dense’, (None, 64), 4160, ‘softmax’], [‘Dense’, (None, 64), 4160, ‘softmax’], [‘Dense’, (None, 64), 4160, ‘softmax’]] [[‘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, 64), 4160, ‘softmax’], [‘Dense’, (None, 64), 4160, ‘softmax’], [‘Dense’, (None, 64), 4160, ‘softmax’], [‘Dense’, (None, 64), 4160, ‘softmax’], [‘Dense’, (None, 64), 4160, ‘softmax’], [‘Dense’, (None, 64), 4160, ‘softmax’], [‘Dense’, (None, 64), 4160, ‘softmax’], [‘Dense’, (None, 64), 4160, ‘softmax’], [‘Dense’, (None, 64), 4160, ‘softmax’], [‘Dense’, (None, 64), 4160, ‘softmax’]]

AssertionError Traceback (most recent call last)
in
33
34
—> 35 modelf_test(modelf)

in modelf_test(target)
30 assert len(model.outputs) == 10, f"Wrong output shape. Expected 10 != {len(model.outputs)}"
31
—> 32 comparator(summary(model), expected_summary)
33
34

~/work/W3A1/test_utils.py in comparator(learner, instructor)
16 def comparator(learner, instructor):
17 if len(learner) != len(instructor):
—> 18 raise AssertionError(“Error in test. The lists contain a different number of elements”)
19 for index, a in enumerate(instructor):
20 b = learner[index]

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

1 Like

Ok, now you can do the same “pretty print” on the instructor version of the model and compare the two. What do you have that is extra or what are you missing compared to the correct value that they have in the test case?

Or maybe the easier first step is to print the two “len()” values so you know whether you’ve added something extra or missed a step(s).

1 Like

From the instructors code the expected summary is below. The difference is that my model has this at the end [‘Dense’, (None, 64), 4160, ‘softmax’] ten times where the expected model output is [‘Dense’, (None, 11), 715, ‘softmax’]] once. In my version the 64 comes from ‘n_s – hidden state size of the post-attention LSTM’. I’m using it as the first parameter of the last Dense layer. That seems right? I have no idea where the number 11 in the expected summary would come from.

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’]]

1 Like

Changing the units in the dense layer to human_vocab_size – size of the python dictionary “human_vocab” does not fix the issue. I get what below which is also wrong.
[[‘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, 37), 2405, ‘softmax’],
[‘Dense’, (None, 37), 2405, ‘softmax’],
[‘Dense’, (None, 37), 2405, ‘softmax’],
[‘Dense’, (None, 37), 2405, ‘softmax’],
[‘Dense’, (None, 37), 2405, ‘softmax’],
[‘Dense’, (None, 37), 2405, ‘softmax’],
[‘Dense’, (None, 37), 2405, ‘softmax’],
[‘Dense’, (None, 37), 2405, ‘softmax’],
[‘Dense’, (None, 37), 2405, ‘softmax’],
[‘Dense’, (None, 37), 2405, ‘softmax’]]

1 Like

The key think to investigate is how you’re getting ten Dense() layers.

Do you have Dense() inside some sort of loop?

1 Like

I figured out how to get the dense summary to be right. But as you point out I have ten copies of it.
The only loop in the code is the one that came in the exercise. # Step 2: Iterate for Ty steps. All I did to that code is fill in Ty in the code. I think the ten copies of the dense layer are coming from this step # Step 2.D: Append “out” to the “outputs” list (≈ 1 line). Where each iteration I append ‘out’, which is the variable that the dense layer is assigned to to the list of outputs. So In my mind it seems correct that outputs should be a list with a number of dense layers equal to Ty. At least according to my understanding of the instructions, which is clearly wrong.

1 Like

In the code for model() at Step 2.C, you’re supposed to use the “output_layer()” function, not a new “Dense()” layer.

The output_layer() function is actually a pointer to a single Dense() layer.

Using output_layer() passes the data through that layer. It doesn’t create a new one each time it is called.

Thanks. That worked. I appreciate your help.

1 Like

Just for clarification, the output_layer() function was defined here in the notebook, with a note that you should use it in the model code.

1 Like