# Course 5 week 3 assignment 1 exercise 2

**URL:** <https://community.deeplearning.ai/t/course-5-week-3-assignment-1-exercise-2/542791>\
**Category:** Sequence Models\
**Tags:** week-module-3, coursera-platform\
**Created:** [January 12, 2024, 5:49pm UTC](https://community.deeplearning.ai/t/course-5-week-3-assignment-1-exercise-2/542791 "2024-01-12T17:49:21Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![George\_Paslaski](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@George\_Paslaski](https://community.deeplearning.ai/u/George_Paslaski)\
**Post date:** [January 12, 2024, 5:49pm UTC](https://community.deeplearning.ai/t/course-5-week-3-assignment-1-exercise-2/542791/1 "2024-01-12T17:49:21Z")

</div>

## 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

---

<div class="post-metadata">

**Author:** ![balaji.ambresh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/balaji.ambresh/32/128697_2.png) [@balaji.ambresh](https://community.deeplearning.ai/u/balaji.ambresh)\
**Post date:** [January 12, 2024, 6:07pm UTC](https://community.deeplearning.ai/t/course-5-week-3-assignment-1-exercise-2/542791/2 "2024-01-12T18:07:01Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![George\_Paslaski](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@George\_Paslaski](https://community.deeplearning.ai/u/George_Paslaski)\
**Post date:** [January 12, 2024, 6:40pm UTC](https://community.deeplearning.ai/t/course-5-week-3-assignment-1-exercise-2/542791/3 "2024-01-12T18:40:29Z")

</div>

## 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

```auto

```

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [January 12, 2024, 7:12pm UTC](https://community.deeplearning.ai/t/course-5-week-3-assignment-1-exercise-2/542791/4 "2024-01-12T19:12:22Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![George\_Paslaski](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@George\_Paslaski](https://community.deeplearning.ai/u/George_Paslaski)\
**Post date:** [January 12, 2024, 7:23pm UTC](https://community.deeplearning.ai/t/course-5-week-3-assignment-1-exercise-2/542791/5 "2024-01-12T19:23:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![George\_Paslaski](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@George\_Paslaski](https://community.deeplearning.ai/u/George_Paslaski)\
**Post date:** [January 12, 2024, 7:35pm UTC](https://community.deeplearning.ai/t/course-5-week-3-assignment-1-exercise-2/542791/6 "2024-01-12T19:35:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [January 12, 2024, 7:40pm UTC](https://community.deeplearning.ai/t/course-5-week-3-assignment-1-exercise-2/542791/7 "2024-01-12T19:40:30Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![George\_Paslaski](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@George\_Paslaski](https://community.deeplearning.ai/u/George_Paslaski)\
**Post date:** [January 12, 2024, 7:48pm UTC](https://community.deeplearning.ai/t/course-5-week-3-assignment-1-exercise-2/542791/8 "2024-01-12T19:48:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [January 12, 2024, 7:53pm UTC](https://community.deeplearning.ai/t/course-5-week-3-assignment-1-exercise-2/542791/9 "2024-01-12T19:53:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![George\_Paslaski](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@George\_Paslaski](https://community.deeplearning.ai/u/George_Paslaski)\
**Post date:** [January 12, 2024, 8:00pm UTC](https://community.deeplearning.ai/t/course-5-week-3-assignment-1-exercise-2/542791/10 "2024-01-12T20:00:47Z")

</div>

Thanks. That worked. I appreciate your help.

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [January 12, 2024, 8:02pm UTC](https://community.deeplearning.ai/t/course-5-week-3-assignment-1-exercise-2/542791/11 "2024-01-12T20:02:07Z")

</div>

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.

 ![image](https://global.discourse-cdn.com/dlai/original/3X/2/1/21451ece7219e8d970216d06942e82df76c8a972.png)

---

<div class="post-metadata">

**Author:** ![lukestiles](https://avatars.discourse-cdn.com/v4/letter/l/d78d45/32.png) [@lukestiles](https://community.deeplearning.ai/u/lukestiles)\
**Post date:** [November 21, 2024, 7:43pm UTC](https://community.deeplearning.ai/t/course-5-week-3-assignment-1-exercise-2/542791/12 "2024-11-21T19:43:24Z")

</div>

I’m having the same problem, and updating to use output\_layer isn’t eliminating the AssertionError: Wrong output shape. Expected 10 != 1.

Would it be possible to share code in a DM?

---

<div class="post-metadata">

**Author:** ![lukestiles](https://avatars.discourse-cdn.com/v4/letter/l/d78d45/32.png) [@lukestiles](https://community.deeplearning.ai/u/lukestiles)\
**Post date:** [November 21, 2024, 8:01pm UTC](https://community.deeplearning.ai/t/course-5-week-3-assignment-1-exercise-2/542791/13 "2024-11-21T20:01:02Z")

</div>

Here’s the pprint output of my model

[[‘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’],  
[‘TensorFlowOpLayer’, [(10, None, 11)], 0]]  
[[‘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’], [‘TensorFlowOpLayer’, [(10, None, 11)], 0]]

---

<div class="post-metadata">

**Author:** ![lukestiles](https://avatars.discourse-cdn.com/v4/letter/l/d78d45/32.png) [@lukestiles](https://community.deeplearning.ai/u/lukestiles)\
**Post date:** [November 21, 2024, 8:03pm UTC](https://community.deeplearning.ai/t/course-5-week-3-assignment-1-exercise-2/542791/14 "2024-11-21T20:03:01Z")

</div>

Never mind, I had an attempted fix in my code from before I found this topic.

All set!
