Week 3, Course 5, Programming Assignment 1

This is my code and I think everything is OK:

    a = Bidirectional(LSTM(n_a, return_sequences=True))(X) 

# Step 2: Iterate for Ty steps
for t in range(Ty):

    # Step 2.A: Perform one step of the attention mechanism to get back the context vector at step t (≈ 1 line)
    context =  one_step_attention(a, s)
    
    # Step 2.B: Apply the post-attention LSTM cell to the "context" vector.
    # Don't forget to pass: initial_state = [hidden state, cell state] (≈ 1 line)
    s, _, c = post_activation_LSTM_cell(inputs=context, initial_state=[s,c])
    
    # Step 2.C: Apply Dense layer to the hidden state output of the post-attention LSTM (≈ 1 line)
    out = output_layer(inputs=s)
    
    # Step 2.D: Append "out" to the "outputs" list (≈ 1 line)
    outputs.append(out)

# Step 3: Create model instance taking three inputs and returning the list of outputs. (≈ 1 line)
model = Model(inputs=[X,s0,c0], outputs=outputs) 

but the unit test section gives me:

[‘InputLayer’, [(None, 30, 37)], 0]

does not match the input value:

[‘InputLayer’, [(None, 64)], 0]

if I change some items in ‘expected_summary’ list it gives me ‘All tests passed’ but yet my grade does not change!
can you help me please?

this is unit test:

# UNIT TEST
from test_utils import *

def modelf_test(target):
    m = 10
    Tx = 30
    n_a = 32
    n_s = 64
    len_human_vocab = 37
    len_machine_vocab = 11


model = target(Tx, Ty, n_a, n_s, len_human_vocab, len_machine_vocab)
print(summary(model))


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

comparator(summary(model), expected_summary)


modelf_test(modelf)
1 Like

Have you figured this one out? What was wrong with this code?

Since the error is with the first Input layer, check that the given code for X =, s0 =, and c0 = has not been modified.

I am having a similar issue.

I suspect there was some inconsistency with my code and the order of the input layers. I ask for help in controlling this part of the code.

Note - that in this section we build a Module with 3 inputs:

as stated in the code for ‘modelf’ (as taken from the assignment):

def modelf(Tx, Ty, n_a, n_s, human_vocab_size, machine_vocab_size):
...

   X = Input(shape=(Tx, human_vocab_size)) # the encoding of the input string
   s0 = Input(shape=(n_s,), name='s0') # initalization for the hidden state
   c0 = Input(shape=(n_s,), name='c0') # initalization for the cell state

It is reflected in my model: it has InputLayers on layers number: 0,1,9

My understanding is that layers 0 and 1 should switch places.

here is the summary:

[
   ['InputLayer', [(None, 64)], 0], 
   ['InputLayer', [(None, 30, 37)], 0], 
   ['RepeatVector', (None, 30, 64), 0, 30], 
   ['Bidirectional', (None, 30, 64), 17920], 
   ['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']
]

The unitTest claims I should have the following summary:
Again, InputLayer on layers numbers 0,1, 9

[
   ['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']
]

This, of course, affects the grading. Moreover, it makes it so I can’t load the trained weights properly, as the models have a different structure for the variables.

Thank you!

1 Like

Do not change the three lines of code that were provided for X=, s0=, and c0=. Those are correct.

But in addition to your InputLayers being out out of sequence, your Bidirectional and RepeatVector layers are also in the wrong order.

I suspect you have added some code that is incorrect, which is causing both of these problems.

1 Like

can you pls dm me the solution for the same …even I’m facing a similar error

Hi @aravinda_1402

What is your problem? In order to diagnose your problem, information is needed. We can guide you to locate your error and that is our limit.

[[‘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, 1), 129, ‘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’]]
Test failed at layer: 5
Expected value

[‘Dense’, (None, 30, 10), 1290, ‘tanh’]

does not match the input value:

[‘Dense’, (None, 30, 1), 129, ‘relu’]

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

in modelf_test(target)
29 [‘Dense’, (None, 11), 715, ‘softmax’]]
30
—> 31 comparator(summary(model), expected_summary)
32
33

~/work/W3A1/test_utils.py in comparator(learner, instructor)
25 “\n\n does not match the input value: \n\n”,
26 colored(f"{a}", “red”))
—> 27 raise AssertionError(“Error in test”)
28 layer += 1
29 print(colored(“All tests passed!”, “green”))

AssertionError: Error in test

Hi @aravinda_1402 ,

Check your code for step 2 c, ensure the correct parameter is passed to output_layer()

There was an error in the model function but yet all tests were passed…idk how…i just edited that now its working…thank you anyway!

Great to hear you have got it sorted. Thanks.

That’s because the unit tests do not identify every possible error in your code.

What did you edit exactly?

The answer is given in this thread.